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?

  • 6
    just export EDITOR=vim in your bashrc or zshrc or ..rc – Kent Apr 23 '13 at 23:31
  • often must be set up for programs in addition to this such as git – timpone Apr 24 '13 at 0:39
  • 4
    In Ubuntu (as said), try run: select-editor. – Pablo A Feb 21 '17 at 17:50

You should add it to your shell’s configuration file. For Bash, this is ~/.bashrc or ~/.bash_profile. 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
  • Not working for me! I still see a number after: "sudo crontab -e" instead of editing crontab! – Mohsen Abasi Jun 26 '18 at 9:34
  • @MohsenAbasi What do you mean “I still see a number?”. Check that 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
  • I mean that I still see just a number (not opening 'vim' editor) after executing: 'sudo crontab -e'. Since there is no default editor for editing cron jobs in my Ubuntu. To have a default editor, your solution does nothing for me. Only solution of 'DobesVandermeer' works. – Mohsen Abasi Jun 27 '18 at 6:08

You could also set your default text editor by using the following command.

sudo update-alternatives --config editor
  • 3
    This set the default for git too, which was exactly what I needed. – Kzqai Mar 9 '16 at 18:26
  • This set the default for ranger too, which was exactly what I needed. PS: just for helping index for people who is trying to do the same. – wviana Dec 6 '16 at 16:42
  • 1
    Only this worked for me on Ubuntu server 18.04 – user3751385 Sep 17 '18 at 17:55

As mentioned by Pablo Bianchi in a comment, you can run


And it will ask you which editor to use. If you don't see vim as an option, run

apt install vim

And try again.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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