zshのviモードで挿入モードの間に通常モードコマンドを実行します。

zshのviモードで挿入モードの間に通常モードコマンドを実行します。

デフォルトでは、Zsh vi モードでは ctrl-o 動作が設定されていません。 vimのように動作させるにはどうすればよいですか?

ベストアンサー1

それは簡単です:

vi-cmd () {
  local REPLY

  # Read the next keystroke, look it up in the `vicmd` keymap and, if successful,
  # evalute the widget bound to it in the context of the `vicmd` keymap.
  zle .read-command -K vicmd && 
      zle $REPLY -K vicmd
}

# Make a keyboard widget that calls the function above.
zle -N vi-cmd

# Bind the widget to Ctrl-O in the `viins` keymap.
bindkey -v '^O' vi-cmd

おすすめ記事