I have vim as default editor on my Mac and every time I run commands on Mac terminal, it automatically opens "vim".

How can I set up "nano" instead and make sure the terminal will open "nano" every time is needed?


Set the EDITOR and VISUAL environment variables to nano.

If you use bash on macOS, this is easiest done by editing your ~/.bash_profile file and adding the two lines

export EDITOR=nano

to the bottom of the file. If the file does not exist, you may create it.

You should set both variables as some tools use one and others may use the other.

You will need to restart your terminal to have the changes take effect.

  • This is a great solution! How can we get the name of other editors for this purpose? – Ben Racicot Feb 19 '20 at 15:48
  • @BenRacicot The editors installed by default on macOS are nano, vi/vim, and ed (a very basic line-editor). If you install other editors for used in the shell, e.g. through Homebrew, then you would know what they are (since you installed them). – Kusalananda Feb 19 '20 at 15:52
  • Yes, only the common issue online is swapping text edit as default for Sublime Text 3. However, export EDITOR=Sublime Text does nothing. – Ben Racicot Feb 19 '20 at 15:57
  • 1
    @BenRacicot Any command that uses e.g. $EDITOR will use it as a command. You would set it to the command that you use to launch Sublime from the command line. If the command contains spaces, then it has to be quoted. – Kusalananda Feb 19 '20 at 16:04
  • 1
    @BenRacicot this answer may help if you're trying to use a GUI application like Sublime Text stackoverflow.com/a/3539630/370407 – Mike Eng Oct 7 '20 at 14:16

The answer suggested by @Kusalananda doesnt work with a default install of Catalina.

Apple has changed the shell from bash to zsh as default in Catalina.

You need to rename your .bash_profile as .zprofile.

Then it works.

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.