I have seen in blogs on Linux machines you can edit the current bash shell command in VI (or whatever the EDITOR is set to) by pressing ctrl-x,ctrl-e.

This doesn't seem to work on 10.8. Any ideas on how to edit the current bash command in the default editor?


You want set -o vi (add it to your ~/.bashrc). Then, to edit the current line, just hit Esc to enter command mode.

See http://www.gnu.org/software/bash/manual/bashref.html#Readline-vi-Mode

To edit the current command in a full-screen editor, set your VISUAL environment variable to vim (I assume you want vim), then in command mode in the current comment, hit v.

To show the mode in the prompt:

$ cat ~/.inputrc
set editing-mode vi
set show-mode-in-prompt on
set vi-ins-mode-string +
set vi-cmd-mode-string :
  • 5
    pressing the "v" was the secret sauce I was missing. thanks. – Scott Walter Apr 27 '13 at 0:32
  • 2
    Is it possible to get this v command while in emacs (non-vi) mode? – Alex Kahn Oct 28 '15 at 14:15
  • 12
    Just do Ctrl-X then Ctrl-E. – albapa Jun 7 '16 at 10:18
  • There is no visual indication that I have entered vim editing mode. Is there some setting to turn this on ? – gprasant Jan 31 '20 at 23:02
  • Yes. See my edit. – glenn jackman Feb 1 '20 at 1:57

Your edit-and-execute-command may not be bound for vi mode. Try:

bind -m vi-insert '"\C-x\C-e": edit-and-execute-command'

To make it permanent, add that line to your ~/.inputrc file.

(via this answer; credit to @unforgettableid for the link)

You must log in to answer this question.

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