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?


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


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. 
| improve this answer | |
  • Thanks for the marvelous answer. Could you clear just one thing - why this keyboard shortcut fails to appear on both the Terminal's rather extensive help window (special one for keyboard shortcuts) or in the Keyboard shortcuts tab in the Keyboard System Preferences panel? How can bash introduce keyboard shortcuts such that the OS is not aware of? and how to enlist ALL of bash's keyboard shortcuts? – Motti Shneor Jul 9 '19 at 20:03

I prefer using fc since that's my Korn shell (ksh) to get to my editor and that should choose vim by default since they go together more naturally than the emacs command.

For changing the editor, I usually set FCEDIT so that it catches both the bash / emacs invocation for the fc built in commands. I rarely change things, though since it's nice to know I can get directly to emacs when needed (on occasion it's better for me) and let fc do the heavy lifting for me. Great question!

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .