Execute a command in zsh vim mode

vimzsh

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.

Best Answer

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.

Related Question