Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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)

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.