In zsh in vim mode, I write something

foo foo bar bar

Then I hit Esc to go in normal mode and type :

foo foo bar bar
execute: _

Then, I assume I can do that, I want to search and replace bar with baz

foo foo bar bar
execute: s/bar/baz/g_

Then I try to hit Enter, but that doesn't work. I can only go back from the execute using Ctrl+c.

How can I execute the command?

I tried this with my normal .zshrc and without any .zshrc at all.

  • The accepted answer doesn't seem to answer your question of how you do a substitute command in zsh vim mode. @pfneusel, did you ever find a way to do exactly what you have above?
    – jspencer
    Commented Jan 13, 2021 at 23:31
  • @jspencer No, I would type v and enter vim, if I want to use the substitute command.
    – pfnuesel
    Commented Jan 14, 2021 at 12:02

1 Answer 1


The vicmd mode, despite the name, is for Vi's normal-mode commands. The prompt started by : isn't for Vi's ex-mode commands, but for running ZLE (Zsh's line editor) commands:

$ echo foo
execute: e_
edit-command-line          emacs-forward-word         end-of-history             end-of-line-hist           exchange-point-and-mark    execute-named-cmd          expand-history             expand-or-complete-prefix
emacs-backward-word        end-of-buffer-or-history   end-of-line                end-of-list                execute-last-named-cmd     expand-cmd-path            expand-or-complete         expand-word

Pressing Enter will work when a unique prefix has been entered (i.e, say you type ed, which matches edit-command-line, then Enter will work). You can press Tab to see matching commands.

  • Thanks. A reason for using bash then instead of zsh.
    – pfnuesel
    Commented Apr 5, 2016 at 12:01
  • @pfnuesel it is? Does Bash support using Vi's ex commands?
    – muru
    Commented Apr 5, 2016 at 12:02
  • 2
    Typing v, you can enter vim and do whatever you can do in vim.
    – pfnuesel
    Commented Apr 5, 2016 at 12:19
  • 4
    @pfnuesel Oh, that. Zsh has that. It's not enabled by default. See unix.stackexchange.com/a/6622/70524
    – muru
    Commented Apr 5, 2016 at 12:21
  • 1
    @muru Your answer is a bit misleading. What you’re referring to as the “vicmd mode” is in fact the command keymap — that’s the “ex-like” one that gives you the execute: prompt for entering ZLE commands. The vicmd keymap is for working vi(m)-style command mode. When using zsh in vi mode, you’ll likely be swapping back and forth between vicmd and viins in much the same way that you move back an forth between command and insert mode in vi(m).
    – wjv
    Commented Apr 11, 2016 at 7:17

You must log in to answer this question.

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