When typing a complicated command that started on the command line in Bash, how do I switch to editing it with ViM?


2 Answers 2


There is a readline command, called edit-and-execute-command tied to the sequence C-x C-e, that invokes your editor with the current content of the command line for editing.

When you exit the editor the command is executed.

  • 1
    Should also add that the editor that is used can be set in the EDITOR environment variable. I added this to my bashrc: "export EDITOR="$(which vim )" Aug 6, 2013 at 18:44
  • Whoa... that's just cool. I learned something today!
    – John
    Aug 6, 2013 at 18:47
  • 4
    For those that use set -o vi, you want to hit Esc v Aug 6, 2013 at 19:26

I'm not sure you can do so in the middle of typing in the command, but you (at least in my experience) can switch to an 'emacs' or a 'vi' line-editing mode via set -o emacs or set -o vi respectively. Those commands will set keybindings for things like last-command, erase-word, erase-to-end-of-line, erase-to-start-of-line, etc.

  • emacs is the default in readline.
    – jordanm
    Aug 6, 2013 at 18:50

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