Have you ever found yourself stuck in a code maze, urgently trying to find that elusive line causing all the trouble? There's a solution: "Vim go to line number." If you've ever wondered how to display line numbers in Vim, you've come to the perfect place. Whether you prefer traditional line numbers, relative counterparts, or hybrid mode, Vim gives you the freedom to improve your coding experience — finding, referencing, and troubleshooting code becomes second nature.
⚡ Quick Answer
Vim hides line numbers by default. To show them, press Esc to get into normal mode, type :set number, and press Enter. Numbers appear in the gutter, the column on the left side of the window.
Show line numbers for the current session
:set numberThis lasts until you close Vim. The next file you open won't have numbers.
Make line numbers permanent in .vimrc
Add this line to ~/.vimrc to get numbers in every file. You don't need the colon inside the config file:
set number
🔢 How to Enable Absolute Line Numbers in Vim
The number option prints each line's absolute number, wherever the cursor is. It's the mode you want when a compiler error, a log entry, or a teammate says "check line 214." For more on Vim's command-line tools, see Linux VIM commands.
Use :set number
:set numberIt's an Ex command, so run it from normal mode. If you're in insert mode, press Esc first.
Use the shorthand :set nu
:set nu is the short name for the same thing. Most Vim options have one, and you'll see both forms in other people's config files.

📏 How to Enable Relative Line Numbers in Vim
With relativenumber, each line shows its distance from the cursor. The current line is 0, and the count goes up as you move away from it in either direction. This pays off when you move with counts — if the line you want shows a 7 below the cursor, 7j takes you straight there. 12k moves up 12 lines, and 5dd deletes the current line plus the four below it. You read the count off the gutter instead of subtracting line numbers in your head. If you delete a lot of lines this way, the guide to Vim delete line commands covers ranges and patterns too.
Use :set relativenumber
:set relativenumberUse the shorthand :set rnu
:set rnu is the short form, and :set rnu! toggles the setting on and off.
People also like to read VI/VIM select all.

🎯 How to Show Both Absolute and Relative Line Numbers
Turn on both options and you get what people call hybrid mode.
Use :set number relativenumber
:set number relativenumberSince Vim 7.4, this shows relative numbers on every line except the current one, which keeps its absolute number. With only relativenumber on, the current line just shows 0 — which tells you nothing about where you are in the file.
When this mode is most useful
Make hybrid mode the default for anyone who edits code all day. You keep track of your place in the file and can still read off counts for j, k, d, and y motions.
💾 How to Make Line Numbers Permanent in Vim
A :set command only affects the session you type it in. Settings you want every time Vim starts go in your config file.
Edit ~/.vimrc
Open the file (Vim creates it if it doesn't exist):
vim ~/.vimrcAdd one or both of these lines:
set number
set relativenumberSave with :w. The Vim save and exit guide covers :w, :wq, and :q! if those are new to you, and the undo and redo guide shows how to recover if you break something while editing.

Reload with :source ~/.vimrc
Load the new settings into the current session without restarting:
:source ~/.vimrc
Neovim note: init.vim
Neovim uses the same option names but reads its config from ~/.config/nvim/init.vim, or from ~/.config/nvim/init.lua if you configure it in Lua. In init.vim you write set number as you would in Vim. In Lua it's vim.opt.number = true and vim.opt.relativenumber = true.
🚫 How to Turn Off Line Numbers in Vim
To turn off a boolean option, put no in front of its name.
Use :set nonumber
:set nonumberThe short form is :set nonu. It's handy when you want to copy text out of a terminal without the numbers coming along.
Use :set norelativenumber
:set norelativenumberThe short form is :set nornu. If both options are on, turn off both or you'll still have a gutter.
These commands only last for the current session. To stop numbers from appearing every time, delete or comment out the set number line in ~/.vimrc (comment lines in Vim config start with ").
🎯 How to Jump to a Specific Line Number in Vim
Jump with :42
In normal mode, type :42 and press Enter to put the cursor on line 42. The command line takes an absolute line number as an address, so this works whether or not the gutter is visible.
Jump with 42G
Typing 42G in normal mode does the same thing without Enter. It also adds an entry to the jump list, so Ctrl+O takes you back to where you started.
Related navigation commands: gg and G
gg goes to the first line of the file and G goes to the last. For more motions like these, see the Vim shortcuts list. For searching patterns instead of specific lines, see how to search in Vim editor.
📐 Line Numbers vs Ruler in Vim
:set ruler does not add line numbers to the gutter.
What :set ruler does
The ruler option shows the cursor's line and column number in the bottom right corner of the screen. When there's room, it also shows how far through the file you are, such as Top, Bot, or 45%. Neovim turns ruler on by default. Classic Vim leaves it off unless your defaults.vim or .vimrc enables it.
Why ruler is not the same as gutter numbering
The ruler reports only the cursor's position, while number labels every visible line. Plenty of people use both.
📏 Adjusting the Number Column
Use numberwidth
numberwidth sets the minimum width of the number column in characters, including the space between the number and the text. The default is 4. The column widens on its own for files with more lines, so you only need this if you want a wider gutter on short files:
:set numberwidth=6Wrapped lines, wrap, linebreak, and showbreak
With wrap on, a long line runs onto several screen rows but still gets one line number, and the continuation rows have a blank gutter. linebreak breaks those rows at word boundaries, and showbreak puts a marker at the start of each continuation row so you can tell it apart from a new line:
set wrap linebreak
set showbreak=↪\ The marker normally appears after the number column. Adding the n flag to cpoptions moves the marker and the wrapped text into the number column. Once you've made the adjustments, save the file and restart Vim to apply the modifications. If you're still deciding which editor fits your workflow, see Vim vs Nano editor for a comparison.
🚨 Common Problems and Fixes
The command is being typed into the file
If :set number shows up as text in your file, you were in insert mode. Press Esc, then u to undo the stray text, and run the command again.
.vimrc changes are not applying
Run :source ~/.vimrc or restart Vim, and make sure the file is in your home directory and named exactly .vimrc. :version lists the config files Vim found. A plugin or filetype setting can also overwrite your option. Start Vim with vim -u NONE and run :set number. If it works there, add your config back in pieces until you find the line that breaks it. Neovim users should check init.vim or init.lua, not .vimrc.
Relative numbers show but absolute numbers do not
Only relativenumber is on, so the current line shows 0. Add set number to get hybrid mode. :set number? tells you whether the option is currently on.
📋 Vim Line Number Command Cheat Sheet
| Task | Command |
| Show line numbers | :set number or :set nu |
| Hide line numbers | :set nonumber or :set nonu |
| Show relative numbers | :set relativenumber or :set rnu |
| Hide relative numbers | :set norelativenumber or :set nornu |
| Show both (hybrid) | :set number relativenumber |
| Jump to line 42 | :42 or 42G |
| First or last line | gg / G |
| Make permanent | set number in ~/.vimrc |
For the rest of the editor's commands, keep the Vim cheat sheet open in another tab, and read the Vim copy and paste guide once you're comfortable moving by line number.
🧩 Conclusion
To summarize, understanding how to display line numbers in Vim is a game-changer for any coder navigating the code maze. Whether you prefer absolute numbers, relative counterparts, or hybrid mode, Vim gives you the freedom to improve your coding experience. You now know how to turn numbers on and off, make them permanent in ~/.vimrc, jump to a specific line with :42 or 42G, adjust the gutter width, and troubleshoot when changes don't apply. Finding, referencing, and troubleshooting code becomes second nature — improving your process and increasing productivity. To put these Vim skills to work on a reliable Linux environment, explore Linux VPS hosting from MonoVM — full root access and dedicated resources.
Hello, everyone, my name is Lisa. I'm a passionate electrical engineering student with a keen interest in technology. I'm fascinated by the intersection of engineering principles and technological advancements, and I'm eager to contribute to the field by applying my knowledge and skills to solve real-world problems.