Vim’s gutter—the space on the left side of the editor—is often used to display line numbers. While some developers prefer a clean, numberless interface, most rely on line numbers for quick navigation, debugging, and coordinating with error messages.
Whether you’re new to Vim or looking to refine your configuration, here is how you control absolute line numbers.
:::note[TL;DR]
:set number— Show absolute line numbers:set nonumber— Hide absolute line numbers:set number!— Toggle line numbers- Add
set numberto your~/.vimrcto make it permanent :::
How do I enable line numbers in the current session?
To show line numbers in your current Vim session, enter command mode by pressing Esc and type:
:set number
You can also use the shorthand version:
:set nu
Immediately, you will see a column of numbers on the left side of your buffer.
How do I hide line numbers?
If you need more screen real estate or find the numbers distracting, you can hide them with:
:set nonumber
Or the shorthand:
:set nonu
How do I toggle line numbers?
If you frequently switch between showing and hiding numbers, use the toggle command:
:set number!
This will reverse the current state—if numbers are on, they turn off; if they are off, they turn on.
How do I make line numbers permanent?
To ensure Vim always starts with line numbers enabled, you need to add the command to your Vim configuration file.
- Open your
.vimrcfile (located in your home directory):vim ~/.vimrc - Add the following line to the file:
set number - Save and exit (
:wq).
The next time you open any file in Vim, absolute line numbers will be there by default.
What are the alternatives to absolute numbering?
In modern Vim (and Neovim), absolute numbers aren’t your only option. Many power users prefer Relative Line Numbers, which show the distance from your current line.
- Relative Numbers:
:set relativenumber - Hybrid Mode (Recommended):
:set number relativenumber
Hybrid mode shows the absolute number for the current line and relative numbers for all others, giving you the best of both worlds.
Summary
| Command | Action |
|---|---|
:set number | Show absolute numbers |
:set nonumber | Hide absolute numbers |
:set number! | Toggle numbers |
:set relativenumber | Show relative numbers |
FAQ
Why should I use line numbers in Vim?
Line numbers make it significantly easier to jump to specific parts of a file (e.g., 42G to jump to line 42) and help you match compiler errors to your source code.
How do I change the color of the line numbers?
You can customize the LineNr highlight group in your .vimrc:
highlight LineNr ctermfg=grey
Can I show line numbers only in certain file types?
Yes, using autocommands in your .vimrc:
autocmd FileType python set number
What to Read Next
- Search and Replace in Vim — Take your Vim skills further with powerful editing commands.
- Top 10 Claude Code Routines — Automate your coding tasks with AI agents.
- Install and Configure PHP on Ubuntu 26.04 — Prepare your Linux environment for web development.
Related Articles
Deepen your understanding with these curated continuations.
Zsh + Oh My Zsh: The Ultimate Terminal Setup Guide
Transform your terminal with Zsh and Oh My Zsh — themes, plugins, aliases, and productivity hacks. From boring bash to powerful command line.
How to Exit Vim, Vi, and Nano (Step by Step)
Stuck in Vim? Here is exactly how to save and exit, quit without saving, and force-quit Vim, Vi, and Nano — with every command you need and why they work.
SSH Config & Aliases: The Developer's Connection Kit
Master SSH configuration — host aliases, jump hosts, key management, port forwarding, and secure connections. Save time with ~/.ssh/config automation.