Vim’s relativenumber

Dev tip 0/99

paydro
paydro
Aug 24, 2017 · 2 min read

My editor of choice is vim — specifically MacVim. One of my favorite settings that enables faster movement in files is the relativenumber setting:

...'relativenumber' 'rnu' boolean (default off)Show the line number relative to the line with the cursor in front of each line. Relative line numbers help you use the |count| you can precede some vertical motion commands (e.g. j k + -) with, without having to calculate it yourself. Especially useful in combination with other commands (e.g. y d c < > gq gw =).When the 'n' option is excluded from 'cpoptions' a wrapped line will not use the column of line numbers (this is the default when
'compatible' isn't set).
The 'numberwidth' option can be used to set the room used for the line number.When a long, wrapped line doesn't start with the first character, '-' characters are put before the number.See |hl-LineNr| for the highlighting used for the number.
When setting this option, 'number' is reset.
...

Instead of guessing how many lines above or below my cursor the next line I want to edit is, I can look to the number column and see exactly lines I need to jump. Here’s what realtivenumber (and number) look like in my editor.

This works wonderfully for yanking and deleting! Say I want to delete everything from my current line (line 30 in the image) to the line with set laststatus=2. I look to the line number column and see it’s 7 lines down. So I type 7dj and the lines are nixed.

100 Days Of Development Tips

I take the 100 Day challenge and write down the developments tips I’ve accumulated over the years as a professional software developer.

)

paydro

Written by

paydro

I jump on boxes.

100 Days Of Development Tips

I take the 100 Day challenge and write down the developments tips I’ve accumulated over the years as a professional software developer.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade