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?
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"
EDITOR is in both your environment (env | grep EDITOR) and is passed to sudo (sudo env | grep EDITOR), as your system’s sudo security policy may prohibit it (see man sudo for more details).
– Andrew Marshall
Jun 26 '18 at 17:18
/usr/bin/vi rather than vim otherwise crontab -e failed with the error crontab /bin/sh: 1: vim: not found.
– SharpC
Jan 28 '23 at 13:24
bash or source ~/.bashrc, whatever, is required to update the environment after you've edited the file. As Jona points out.
– NeilG
Jun 21 '23 at 19:45
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:
sudo update-alternatives --set editor /usr/bin/vim.basic
sudo update-alternatives --set vi /usr/bin/vim.basic
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
Or, to see all options and choose interactively:
sudo update-alternatives --config editor
ranger too, which was exactly what I needed.
PS: just for helping index for people who is trying to do the same.
– wviana
Dec 06 '16 at 16:42
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.
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.
.zprofile file will be read for each and every shell invocation. It seems odd to want to set the editor for shell sessions that aren't even interactive.
– Kusalananda
Dec 28 '20 at 19:02
su into your account, .zshenv will be sourced.
– pepoluan
Dec 29 '20 at 04:55
export EDITOR=vimin your bashrc or zshrc or ..rc – Kent Apr 23 '13 at 23:31select-editor. – Pablo A Feb 21 '17 at 17:50