How can I set "vi" as my default editor in UNIX?

I believe I can do something like export EDITOR=vi, but I’m not sure what exactly to enter, and where.

How can I set “vi” as my default editor?

Asked By: Donny P

||

If bash is your shell, then insert it into .bash_profile in your home directory; if zsh is your shell, then insert it into .zprofile; for other shells see the according documentation.

Answered By: lotsofcode

You should add it to your shell’s configuration file. For Bash, this is ~/.bashrc or ~/.bash_profile (see detailed comparison). You should also set $VISUAL, as some programs (correctly) use that instead of $EDITOR (see VISUAL vs. EDITOR). Additionally, unless you know why, you should set it to vim instead of vi.

TL;DR, add the following to your shell configuration (probably ~/.bashrc):

export VISUAL=vim
export EDITOR="$VISUAL"
Answered By: Andrew Marshall

On Ubuntu and other Ubuntu/Debian-based Linux systems, you can explicitly set the default text editor at the system level by providing its path to update-alternatives:

Automatic, Scripted

sudo update-alternatives --set editor /usr/bin/vim.basic
sudo update-alternatives --set vi /usr/bin/vim.basic

Note

If your distro doesn’t call it /usr/bin/vim.basic, you can find out which path to use with the --list argument:

sudo update-alternatives --list editor
/bin/ed
/bin/nano
/usr/bin/vim.basic
/usr/bin/vim.tiny

Manual, Interactive

Or, to see all options and choose interactively:

sudo update-alternatives --config editor
Answered By: Rick

In recent versions of Ubuntu you use the alternatives system to manage the default, editor, e.g.:

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

To see which editors are available for use:

update-alternatives --list editor

Some UNIX distributions might provide a select-editor command:

select-editor

And it will ask you which editor to use.

Make sure you actually have vim installed before trying to set it as your default editor.

Answered By: Dobes Vandermeer
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.