Zsh

在 zsh 的 vi 模式下在插入模式下執行一個普通模式命令

  • May 21, 2021

Zsh vi 模式預設沒有設置 ctrl-o 行為我如何像在 vim 中一樣工作?

就這麼簡單:

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 out of the function above.
zle -N vi-cmd

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

引用自:https://unix.stackexchange.com/questions/628423