Relative line numbering
Many operations in Vim can be executed over a given number of lines. For example, d3j
will delete the current line, plus the 3 below it. Having line numbers displayed will make it easier to know how many lines you want to edit. You can enable and disable line numbering easily in Vim:
:set number
– Shows line numbers:set nonumber
– Hides line numbers
You may find yourself often reading the line numbers and then subtracting two numbers in your head to decide over how many lines to execute a command. But there is a better way!
Vim allows showing relative line numbers instead of absolute line numbers:
:set relativenumber
– Shows relative line numbers:set norelativenumber
– Hides relative line numbers
The numbers are now relative to the current cursor position. If you’re on Vim 7.4 or newer, and you have both absolute line numbering enabled and relative numbering, then you’ll get hybrid line numbering. That is, the number on your current line will be its absolute line number, instead of 0.