3

Zsh vi mode doesn't have ctrl-o behavior set by default how do I get to work like in vim ?

1
  • 1
    Zsh has a vi mode, not a vim mode. This is a vim-specific feature so it's unsurprising that zsh doesn't have it. It's probably doable with a custom widget though. Commented Jan 10, 2021 at 22:15

1 Answer 1

3

It's as simple as this:

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
2
  • It works but still wouldn't do some key shortcuts like "d" to delete Commented Jan 19, 2021 at 7:11
  • 1
    @Hazemgamal I updated my answer with a fix. Please try again. Commented Jan 19, 2021 at 13:07

You must log in to answer this question.

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