Unable to change the default editor in the terminal

Viewed 49534

My default editor is Pico at my server. I use Bash and Linux.

I tried to change Vim to be my default editor unsuccessfully by:

echo vim > $EDITOR

How can I change Vim to be my default editor?

The following code does not work in file .bashrc:

export EDITOR='vim'
9 Answers

Adding

export EDITOR=vim

to your .bashrc file should really do the trick. (Quotes aren't necessary there and, depending on what quotes you used, they may be the cause for your problem.)

You must open a new shell (or enter source ~/.bashrc at the prompt) after modifying file .bashrc for the modification to take effect.

What is the program from which you want Vim to be started?

I haven't used Git, but the documentation reads:

The editor used to edit the commit log message will be chosen from the GIT_EDITOR environment variable, the core.editor configuration variable, the VISUAL environment variable, or the EDITOR environment variable (in that order).

So check whether one of these variables is set:

echo $GIT_EDITOR $VISUAL $EDITOR
git config --get-all core.editor

For me,

export VISUAL=vim

solved the problem.

vim=/usr/bin/vim # Or wherever the Vim binary is
export EDITOR=vim

should do the job.

I don't have an EDITOR environmental variable. My .bashrc file does define this:

alias vi='vim'

And supposedly, if Vim can't find a file called .vimrc in your home directory, it runs in "compatibility mode" and you only get vi features until you say type :nocp.

If it is based on your EDITOR environmental variable, you would set it like this in Bash:

export EDITOR='vim'

I had this same challenge when setting up my new MacBook Pro.

Here's how I solved it

To switch to your editor of choice (say nano) on a MacBook you will need to add the following lines to your ~/.zshrc file if your default shell is zsh or ~/.bash_profile if your default shell is bash:

export EDITOR=nano
export VISUAL="$EDITOR"

However, a simpler approach to do this will be to use the echo command to insert them into your ~/.zshrc file if your default shell is zsh:

echo 'export EDITOR=nano' >> ~/.zshrc
echo 'export VISUAL="$EDITOR"' >> ~/.zshrc

OR ~/.bashrc if your default shell is bash:

echo 'export EDITOR=nano' >> ~/.bash_profile
echo 'export VISUAL="$EDITOR"' >> ~/.bash_profile

Run the command below to activate the new configuration:

source ~/.zshrc

Or

source ~/.bash_profile

If you need to switch to other editors of choice you can replace nano with your preferred editor:

  • Vim - vim
  • Vi - vi

That's all.

Related