Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

Change Your Vim Cursor from a Block to Line in Normal and Insert Mode

blog/cards/change-your-vim-cursor-from-a-block-to-line-in-normal-and-insert-mode.jpg

Here's how you can change your Vim cursor depending on which mode you're in. It should work with most terminal emulators.

Quick Jump: Demo Video

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

Does this work with your terminal? Let me know below.

Never Miss a Tip, Trick or Tutorial

Like you, I'm super protective of my inbox, so don't worry about getting spammed. You can expect a few emails per month (at most), and you can 1-click unsubscribe at any time. See what else you'll get too.



Comments