This question already has an answer here:

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

marked as duplicate by slm, jasonwryan, Anthon, Mat, manatwork Aug 7 '13 at 10:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


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 )" – Freedom_Ben Aug 6 '13 at 18:44
  • Whoa... that's just cool. I learned something today! – John Aug 6 '13 at 18:47
  • 4
    For those that use set -o vi, you want to hit Esc v – glenn jackman Aug 6 '13 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 '13 at 18:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.