DPH.AM

I like to draw, code, and build stuff.

Vim Editing Mode in Your Zshell

Note: I got the huge chunk of the code from this blog post.

If you’re a VIM lover like me and using zsh for your shell, there’s a simple command to enable vim mode on your command prompt.

1
set -o vi

It works fine other than the fact that I usually had no idea if I’m in normal or command mode. If you want to read about the hows, following the link above. Below is the zsh script I use to indicate my editing mode on my prompt.

1
2
3
4
5
6
7
VIMODE=">> "
function zle-keymap-select {
    VIMODE="${${KEYMAP/(main|viins)/>> }/(vicmd)/}${${KEYMAP/vicmd/<< }/(main|viins)/}"
    zle reset-prompt
}
zle -N zle-keymap-select
set -o vi

Now you can place $VIMODE in your zsh prompt declaration. >> will display for normal mode and << will appear for command mode. Of course you can easily change that to whatever you prefer.

Comments