How to Change the Default Text Editor in Terminal on macOS

bashdefaultsterminal

I just discovered that Control + X + E opens a text editor in the Terminal that allows me to edit the most recent command before executing it again (I think it is actually a bash thing).

However, the editor that gets opened is always Emacs. How can I change it to vim?

Best Answer

Simply set the EDITOR variable to vim in your bash startup file.

EDITOR=vim

From the bash manual

   edit-and-execute-command (C-xC-e)
      Invoke an editor on the current command line, and execute the result as shell commands.  Bash
      attempts to invoke $FCEDIT, $EDITOR, and emacs as the editor, in that order.