On Linux machines the current bash shell command can be edited in VI (or whatever the EDITOR is set to) by pressing Ctrl+XCtrl+E.
This doesn't seem to work on OS X 10.8. Any ideas on how to edit the current bash command in the default editor?
On Linux machines the current bash shell command can be edited in VI (or whatever the EDITOR is set to) by pressing Ctrl+XCtrl+E.
This doesn't seem to work on OS X 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 :
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)
This worked for me:
If you’re using zsh (as you should), you could add the following to your .zshrc (or .zprofile):
export EDITOR=nvim
# Enable Ctrl-x-e to edit command line
autoload -U edit-command-line
# Emacs style
zle -N edit-command-line
bindkey '^xe' edit-command-line
bindkey '^x^e' edit-command-line
# Vi style:
# zle -N edit-command-line
# bindkey -M vicmd v edit-command-line
Then, reload your .zshrc.
Now all you need to do is hit Ctrl-x Ctrl-e (Ctrl-x e also works) or, if you use vi style, ESC v, and zsh will launch $VISUAL or $EDITOR, allowing you to edit the current command to your hearts content, and once you save & close your editor’s window, ZSH will execute your command.
VISUALvariable? – glenn jackman Apr 11 '13 at 21:29