The Art of Vim: Relative Number


This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/relative-number-with-ben-orenstein

Before ā€œset relativenumberā€ put ā€œset numberā€ and instead zero you will have current line number.

set number
set relativenumber

1
2
42 cursor here
2
1

2 Likes

@rbilych, this is a great tip. This is one of my favorite (relatively recent) Vim features, as it gets you the best of both worlds.

I use something slightly different. With configuration like:

set relativenumber 
set number
autocmd InsertEnter * :set number norelativenumber
autocmd InsertLeave * :set relativenumber

The relative number is used in visual mode, but once entering the insert mode, it becomes the absolute number.

Hope that helps someone!

1 Like

Wow, that is really cool. Do you notice any sluggishness when you enter and leave normal mode? I am going to give this a try in my dotfiles.

That is super cool. Extremely useful. Awesome solution to combine number and relative number together.

sluggishness? No, I havenā€™t noticed anything particularly different than before using this set of configā€¦ But Iā€™ll keep an eye on it! Thanks!

Love this episode! I have a question, plus and minus donā€™t work for me. why is that?

Love it! Thanksā€¦

Iā€™ve found that relativenumber is very slow in large ruby files. I profiled my entire zshrc without any plugins and thatā€™s what was causing it. Iā€™ve since switched to using easy-motion