![在 zsh 的 vi 模式中处于插入模式时发出一个正常模式命令](https://linux22.com/image/186190/%E5%9C%A8%20zsh%20%E7%9A%84%20vi%20%E6%A8%A1%E5%BC%8F%E4%B8%AD%E5%A4%84%E4%BA%8E%E6%8F%92%E5%85%A5%E6%A8%A1%E5%BC%8F%E6%97%B6%E5%8F%91%E5%87%BA%E4%B8%80%E4%B8%AA%E6%AD%A3%E5%B8%B8%E6%A8%A1%E5%BC%8F%E5%91%BD%E4%BB%A4.png)
默认情况下,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