PostgreSQL <--> Vim integration: Finally …

Last time I had come up with the idea of writing some Vim script for PostgreSQL so that people can edit data fast and easily directly in Vim. The goal is to export a table directly to Vim, modify it and load it back in. This can come in handy when you want to edit a configuration table or some other small data set. Using INSERT / UPDATE / DELETE can be quite a lot of work.

Importing into Vim is basically not too much of an issue – but, exporting data back to PostgreSQL has kept me and my fellow here in office (Attila Max Ruf) pretty occupied mentally.

The weekend has finally left us with the following procedures:

:call PSQLInit({'host': <host>, 'port': …, 'db': …, 'usr': …, 'passwd': …, })

:call PSQLCopyTable( 't_test', [ 'db', [, truncfile: 0 ]]

:call PSQLCopySave('t_test' [, 'db'])

The PSQLInit call will initialize the editor and provide information about where to find what and so on. Then there is PSQLCopyTable to load the data from PostgreSQL to Vim (in COPY format). Once you have edited the data you can call PSQLCopySave to pump the data back in.

Note that this will simply replace the content of the entire table.

Btw, you can test those modules. Just go to and follow the instructions in the README file.

Visit us on facebook:

Hans-Juergen Schoenig
Hans-Jürgen Schönig has 15 years of experience with PostgreSQL. He is consultant and CEO of the company „Cybertec Schönig & Schönig GmbH“ (, which has served countless customers around the globe.