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?

2 Answers 2


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. 
  • 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? Jul 9, 2019 at 20:03
  • 1
    Why would it be listed in either of those places? These are not shortcuts provided by Terminal.app, they are shortcuts provided by the application running inside the terminal, in this case, bash. I suppose you also believe that if a copy of vim is launched inside that running Terminal.app, that all vim's various keys and shortcuts should be listed on Terminal.app menus? Jul 17, 2020 at 22:01

This question gets to the root of how you want to work - so there's some "preference" that may be in play. If you come from the school of vi you might prefer a command as opposed to the emacs key bindings.

I prefer using fc since my big chunk of time post-emacs was spent in Korn shell (ksh) and I used fc built in to summon the editor. On all macOS systems, by default vim is chosen over 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. So if I were to head back to “emacs land”, fc is how I'd get there initially.

You must log in to answer this question.

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