Change Cursor Shape for Zsh Vi-mode
I’ve been using zsh and its wonderful vi-mode line editing keybindings for a long time, but one thing that has always troubled me is the lack of visual clues to the current mode.
With oh-my-zsh you can optionally have an indicator to the right of the prompt telling you this, but I feel it’s not native enough - we need something simpler and more direct, just as in vim I’ve set my cursor to be an underscore in the insert mode and a solid block in the command mode.
Luckily you can do just that with the powerful zsh shell.
First off the relevant escape sequences for changing the cursor shape are:
"\e[4 q": solid underscore
"\e[2 q": solid block
The hook called when your vi mode changes is
zle-keymap-select. If you want comprehensiveness, also include
Now just append this to the end of your
1 2 3 4 5 6 7 8 9 10 11
Boom, you’ve just configured your cursor to change shape on the fly according to your editing mode!