4

The situation is the following. This is an Ubuntu box:

Linux ns3mx3 2.6.32-41-server #89-Ubuntu SMP Fri Apr 27 22:33:31 UTC 2012 x86_64 GNU/Linux

Which means that when I first issue \e in psql, I'm asked to choose an editor. Then there is the .selected_editor file, which contains

# Generated by /usr/bin/select-editor
SELECTED_EDITOR="/usr/bin/mcedit-debian"

So far this is OK (it's my problem that I consider this completely useless, but never mind).

Then I set up a .psqlrc file:

\set PSQL_EDITOR /usr/bin/vim
\set EDITOR /usr/bin/vim
\set VISUAL /usr/bin/vim

As you can see, I wanted to be sure not to miss a candidate variable for editor setting. The file is used as expected:

test=# \echo :EDITOR
/usr/bin/vim

But when I issue the \e command, none of these is used - I fall back to SELECTED_EDITOR. The situation remains just the same if I append an \unset SELECTED_EDITOR to the .psqlrc file.

Now how can I make .psqlrc setting win over the default editor?

(PostgreSQL version id 9.1.4)

HopelessN00b
  • 53,385
  • 32
  • 133
  • 208
dezso
  • 149
  • 9

1 Answers1

4

From what I can understand by reading the psql documentation, PSQL_EDITOR, EDITOR or VISUAL are supposed to be shell environment variables. Therefore you should set them, for example, in your .bashrc, by adding the following line:

export PSQL_EDITOR=/usr/bin/vim

I have tested this by executing the following command line (which sets the given environment variable just for the executed command):

PSQL_EDITOR=/usr/bin/nano psql

and when I executed the \e command in psql, nano was correctly executed as the editor, even though my default selected editor is vim.

Pedro Romano
  • 343
  • 2
  • 10