Vim Tips Wiki

Quick and dirty Postgres query

1,624pages on
this wiki
Add New Page
Talk0 Share
Tip 446 Printable Monobook Previous Next

created March 23, 2003 · complexity basic · author Shawn Deleurme · version 5.7

Here is a simple and useful mapping for anyone who can't stand developing queries on the psql prompt or messing around with the single \e psql edit buffer.

map <F9> :!psql -d yourdb < % <BAR> less


You could also consider use the database extension plugin for Vim, which provides a lot of features for Postgress. script#356 db_ext.vim

One other way of using vim with the \e command in psql is to set the PSQL_EDITOR environment variable. On a redhat system you'd do the following:

export PSQL_EDITOR=vim

When using old versions of psql the buffer does not have the .sql extension. If you want syntax highlighting use:

export PSQL_EDITOR='vim +"set syntax=sql" '

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki