Vim doesn’t show line numbers by default, but they can be turned on in your configuration. Besides regular absolute line numbers, Vim has relative and “hybrid” modes to help navigate around files. With the vim-numbertoggle plugin, it can even toggle between line number modes automatically when you switch files or enter insert mode.

Absolute line numbers Using the number option, Vim sets up absolute line numbers to show the line number for each line in the file you’re working on. " turn absolute line numbers on :set number :set nu " turn absolute line numbers off :set nonumber :set nonu " toggle absolute line numbers :set number! :set nu! Besides being useful for finding a line from a stack trace or a test result, you can use line numbers to help you jump around the file. For example, if you want to go to the tenth line in your file, you’d type esc while in insert mode and then :10 to move to the correct line.

Relative line numbers With the relativenumber option, each line in your file is numbered relative to the cursor’s current position to show the distance to that line. The current line is marked 0, the ones above and below it are marked 1, and so on. " turn relative line numbers on :set relativenumber :set rnu " turn relative line numbers off :set norelativenumber :set nornu " toggle relative line numbers :set relativenumber! :set rnu! Like most commands in Vim, the j and k (or ↑ and ↓ ) keys can be prefixed with a number. Typing 5 j will move the cursor five lines down, for example. If you want to remove seven lines, you can use d 7 d without having to switch to visual mode to select the lines first. It can be difficult to see how far you need to jump to get to where you want to be, rendering this method useless for any jumps over ten lines. Also, absolute line numbers become less useful when working in lengthy files. With relative line numbers, you can glance at the number of the line you want to jump to. If it’s thirteen lines up, you press 1 3 k to get there. To get back to where you came from, you use 1 3 j .

“Hybrid” line numbers Since Vim 7.4, enabling number and relativenumber at the same time produces hybrid line number mode. All lines will show their relative number, except for current line, which will show its absolute line number. " turn hybrid line numbers on :set number relativenumber :set nu rnu " turn hybrid line numbers off :set nonumber norelativenumber :set nonu nornu " toggle hybrid line numbers :set number! relativenumber! :set nu! rnu! Hybrid line numbers are what relative line numbers should have been. Instead of having a useless zero on the current line, it uses that space to give you an idea of where you are in the file.