In bash, using vi mode, if I hit Esc,v, my current command line is opened in the editor specified by $EDITOR and I am able to edit it in full screen before ‘saving’ the command to be returned to the shell and executed.
How can I achieve similar behaviour in zsh? Hitting v in command mode results in a bell an has no apparent effect, despite the EDITOR environment variable being set.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
See edit-command-line in zshcontrib.
bindkey -M vicmd v edit-command-line
Method 2
In case you prefer Emacs keybindings:
autoload -z edit-command-line zle -N edit-command-line bindkey "^X^E" edit-command-line
Method 3
You can use fc to edit the last command in history. It’s not the same as editing the same command, but a quick hit on the Enter key makes your current command the last command in history.
Method 4
This is the complete configuration that I added to my ~/.zshrc to get the same behavior from bash:
export VISUAL=vim autoload edit-command-line; zle -N edit-command-line bindkey -M vicmd v edit-command-line
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0