Change Your Vim Cursor from a Block to Line in Normal and Insert Mode
Here's how you can change your Vim cursor depending on which mode you're in. It should work with most terminal emulators.
This is a huge quality of life enhancement if you’re using terminal Vim. Without this it’s tricky to tell if you’re within insert mode or normal mode. With this config option your cursor will change to a bar / line within insert mode and a block cursor everywhere else.
After adding this I’ve made substantially less mistakes around thinking I’m in one mode but not the other.
# Demo Video
Vim Configuration
" Use a line cursor within insert mode and a block cursor everywhere else.
"
" Reference chart of values:
" Ps = 0 -> blinking block.
" Ps = 1 -> blinking block (default).
" Ps = 2 -> steady block.
" Ps = 3 -> blinking underline.
" Ps = 4 -> steady underline.
" Ps = 5 -> blinking bar (xterm).
" Ps = 6 -> steady bar (xterm).
let &t_SI = "\e[6 q"
let &t_EI = "\e[2 q"
Timestamps
- 0:10 – Checking out the difference between the block and line cursor types
- 1:01 – Going over 2 lines of Vim config options to do this
- 2:30 – I also changed my Microsoft Terminal to use filledBox which is its block cursor
- 2:45 – One potential downside with character visibility depending on your terminal
- 3:48 – The benefit of easily seeing if you’re within insert mode is worth it
Reference Links
- https://github.com/nickjj/dotfiles
- https://stackoverflow.com/a/42118416
- The commit that added this to my dotfiles
- https://github.com/microsoft/terminal/issues/9610
Does this work with your terminal? Let me know below.