Quick! How many lines from the current one, 143, is the beginning of the paragraph, 116? Trying to see these numbers in the first place? Find out here how to see and use line numbering (both absolute and relative to the current line) in Vim and Neovim ⤓.
On This Page
How to See Line Numbering in Vim and Neovim
Enable Line Numbering in Vim for the Current Session
Time needed: 2 minutes
To turn on line numbering in Vim or Neovim:
- Press Esc to enter normal mode in Vim.
Here’s why: Esc exists insert mode and makes sure Vim is ready to take commands instead of text input.
- Now press : (colon) for command mode.
- Type
set numberto turn on line number in Vim.Relative numbering: For numbers relative to the current line, type
set relativenumberinstead. - Press Enter.
Their word: Vimhelp.org include information on the number option in Vim help.
Numbers lining up already?
Tips help fuel these email and tech how-tos.
Enable Vim Line Numbering Permanently
To set up Vim for line numbering by default, add the following to your .vimrc file
set number " turn on line numbering
"set nonumber " turn off line numbering
"set relativenumber " turn on relative line numbers
set norelativenumber " turn off relative line numbersEnable the desired options; the configuration above turns on absolute line numbers and disables relative line numbering, for example.
How to Use Line Numbering in Vim and Neovim
You can make use of line numbers in Vim and Neovim in a number of ways:
- Going to a line
Type:<line number>and press Enter in normal mode to go to a line.
Example: :8 will go to line number 8 or the last line if there are fewer than 8 lines. - Specifying a range
Use:<starting line number>,<ending line number>to act on the specified lines (inclusively) in command mode.
Example::1,5dwill delete the first five lines. - Giving a relative line or range
You can use+and-to make a range’s line number relative to the current line.
Examples:+2,+2dwill delete the line after the next counting from the current line.:1,-1dwill delete from the top until the current line, but leave the latter in place. - Repeating commands that act on lines
Use relative line numbering to know how often to repeat a command that acts on lines. (Pattern matching might be easier to achieve the same result and faster to boot in some cases.)
Example: 3 J moves the cursor down 3 lines.
Special Line Numbers
| Special Line Number | Function |
|---|---|
0 | Equal to 1, refers to the first line |
$ | The last line, equal to the absolute number of the last line |
% | All lines, equal to the range 1,$ |
. (period) | The current line, equal to the line’s absolute number (You can also use +0 or -0 to achieve the same in most cases) |
How to See and Use Line Numbering in Vim and Neovim: FAQ
Can I see both absolute and relative line numbers?
Yes.
You can turn on both number and relativenumber. Vim will then show the absolute number for the line hat holds the cursor and all other lines with numbers relative to it.
(Tested with Vim 9.1 and Neovim 0.9.5–0.11.5; first published April 2024, last updated March 2026)