How do I change the default text editor in the Debian (squeeze) distro

To change the default editor at the system level:

sudo update-alternatives --config editor

and then follow the onscreen prompts.


The way to change the default editor for your account is to set the EDITOR environment variable. If that doesn't work for you, you've done something unusual. Check that you haven't also defined VISUAL, or if you have, give the two variables the same value (see VISUAL vs. EDITOR – what’s the difference?). Add these lines to your ~/.profile (note: not to ~/.bashrc):

EDITOR=nano
VISUAL=$EDITOR
export EDITOR VISUAL

Under the Debian policy, all programs are supposed to support EDITOR and VISUAL to set the default editor.

Under Debian and derivatives, you can use the alternatives mechanism to set the system-wide default editor, as mentioned by Steve Robillard: run update-alternatives --config editor as root.


The solution mentioned above works, but it isn't scriptable. If you want to do this in a scriptable (non-interactive) fashion, you should use --set:

# update-alternatives --set editor /usr/bin/vim.basic

You can get a list of the choices with:

$ update-alternatives --list editor