Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 26 down vote accepted

See edit-command-line in zshcontrib.

bindkey -M vicmd v edit-command-line
share|improve this answer
(Just to clarify): To enabled the edit-command-line “widget” you will need something like autoload edit-command-line; zle -N edit-command-line in one of your zsh init files (see the ZLE Functions section of the zshcontrib documentation). – Chris Johnsen Jan 29 '11 at 3:14
How do you activate this once it's in place? The bindkey in the emacs-style answer makes sense to me. But I can't find reference on what bindkey -M vicmd v sets up. – Mat Schaffer May 25 '12 at 18:50
@MatSchaffer Same as Bash: if you are in vi mode, then hit <ESC> to enter command mode from insert mode and and then v to visual mode (Meta-v is the same), or just v if you're already in command mode. If you're using Emacs mode, the typical binding is C-x C-e. – ephemient May 25 '12 at 20:03

In case you prefer Emacs keybindings:

autoload -z edit-command-line
zle -N edit-command-line
bindkey "^X^E" edit-command-line
share|improve this answer
The ^x^e binding seems to be a default with current .oh-my-zsh, which is extremely nice. – quodlibetor Aug 8 '14 at 15:44
^x^e is exactly what I was looking for. – jmreicha Nov 17 '14 at 16:30
Similar setup for Prezto as long as the editor module is loaded. – AL the X Jun 9 '15 at 12:08

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.

share|improve this answer
+1 This is the answer I needed, moreso than the accepted one. – BenjaminGolder Aug 4 '15 at 22:14

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
share|improve this answer
Per the earlier comments, this is configured by default if you're using Oh my ZSH or Prezto. The latter requires the editor module to be loaded and vi or vim selected for command mode. – AL the X Jun 9 '15 at 12:10
I'd vote to make this the accepted answer, it solved my question with all configuration described. Thanks. – Laurent Jul 17 at 20:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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