Search code examples
vimzsh

How to set VIM key binding in ZSH/terminal


In my normal use of Vim I have a key binding ("jj") to enter NORMAL mode. I accomplish this by setting a mapping configuration in ~/.vimrc -> :imap jk <Esc>. However this binding does not take effect in ZSH on Mac OS Terminal. Is there a way to enable this?

Edit/Update: I came across this question which appears to sort of indirectly answer my question within its question to something else (not its answer). Leaving this open as that original thread does not directly answer the question


Solution

  • ZSH and Vim are configured separately, in ~/.zshrc and ~/.vimrc respectively. You can add the jj key binding to your zsh terminal by adding the following line to you ~/.zshrc file.

    # Add "jj" shortcut to enter NORMAL mode
    bindkey -M viins 'jj' vi-cmd-mode