Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Fresh Ubuntu installation. I have no personal dot-files active.

I run unsuccessfully \e file.sql in Psql, when I have the following in my .bashrc, since Nano opens instead of Vim

export VISUAL=/usr/bin/vim
export EDITOR=/usr/bin/vim
export PSQL_EDITOR=/usr/bin/vim

I run the same command when I have vim in place of PATH/vim in .bashrc for the above three commands.

I get vim when I cat $EDITOR, for instance.

The problem is in environmental variables likely. However, I am not sure where.

How can you have Vim as Psql's editor?

share|improve this question
up vote 3 down vote accepted

I'm not sure about psql, but if something is goofed up with $EDITOR it will probably fall back on the system default as defined through the /usr/bin/editor symlink, which is nano by default. If you have admin access, try

sudo update-alternatives --config editor

and select vim there. I think programs should still respect $EDITOR if it's defined but that will define the fallback. It's the only setting I use and it works just fine.

share|improve this answer

Edit the file ~/.selected_editor or run select-editor. Select /usr/bin/vim-basic in either case, /usr/bin/vim on Ubuntu is a symlink to /etc/alternatives/vim, which is a symlink to /usr/bin/vim.basic.

Here's the contents of the file for an Ubuntu system's postgres user:

postgres@ubuntu904test:~$ cat .selected_editor
# Generated by /usr/bin/select-editor
SELECTED_EDITOR="/usr/bin/vim.basic"
share|improve this answer
1  
Ah, well if postgres is running as a different user then that would explain the problem with ~/.bashrc too. Looks like SELECTED_EDITOR is yet another way of choosing an editor per-user, with priority between EDITOR and the /etc/alternatives links (though my old Ubuntu 8.04 install doesn't honor it). If you want to set the editor system-wide then use the alternatives command I gave below. – jtb Aug 3 '09 at 5:16
1  
I suppose Debian has real good reasons for things like "selected editor", "update-alternatives", and all those symlinks chasing themselves around the filesystem, but I remember when Unix meant a simple system you could rap your head around... Now if you'll excuse me, I have to go chase some kids off my lawn. :) – Richard Hoskins Aug 3 '09 at 6:19
    
I run your command select-editor. However, Emacs is now my default editor for some unknown reason, although I selected Vim. If I run the command again, the list shows that my default editor is Nano. I run the command with sudo unsuccessfully. This suggests me that there is also some file manipulating the editor settings in Ubuntu. – Masi Aug 7 '09 at 12:29

I tried all the suggestions here and the editor did not change to VIM. Although the selections were made correctly and the files were updated correctly, the editor continued to be Nano.

sudo update-alternatives --config editor

Edit the file ~/.selected_editor

Finally I deleted the file ~/.selected_editor and executed \ef once again. Because the .selected_editor file did not exist it allowed this to execute as if this was the first time creating the file. And then I could select "2" for "vim.basic". The new file was created and VIM became my editor.

postgres=# \ef

Select an editor. To change later, run 'select-editor'. 1. /bin/nano <---- easiest 2. /usr/bin/vim.basic 3. /usr/bin/vim.tiny

share|improve this answer
    
Welcome to Superuser! Please, consider your thing next time as an comment because it is not answer. Please, see jtb's answer which is the accepted answer here. Please, consider also sending a new thread with a link here. – Masi Jul 8 at 20:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .