For Vim—and vi—line numbers are even more significant. The editor has several commands that make use of line numbers for navigation. You can instantly move the cursor to a specific line, but you’ll need to know its number to do so.

Read on to learn how to show line numbers in Vi and Vim and how to change your settings to do so by default.

Why Vim Doesn’t Show Line Numbers by Default

Vim is such a power-user-oriented text editor that basic features can be difficult to locate. Even quitting the application can be a challenge for new users!

Out of the box, vim aims to be a minimalist editor, offering just enough functionality to perform the most basic editing tasks. But you can install various extensions and change a large number of settings. This allows you to set up the editor exactly how you want it.

Note that, even in its most basic form, vim does show you your current line number near the bottom-right of your window.

See also: How to Use Vim: A Guide to the Basics

How to Show and Hide Line Numbers in Vim

Follow these steps to toggle line numbers on and off, whenever you need to:

Make sure you’re in command mode: press Esc if you’re not sure you are. Press colon (:). Type set number, then press Enter.

You should now see line numbers in the left-hand column. You will still be in command mode. To turn line numbers off, repeat the process but use the command set nonumber instead.

You can also use abbreviated versions of each command: set nu and set nonu respectively.

How to Use Relative Line Numbering

Relative line numbers work well with vim’s concept of navigating by command. This allows you to instantly move the cursor four lines up, for example. To turn on relative line numbers:

Press Esc to enter command mode. Press colon (:). Type set relativenumber (or set rnu), then press Enter.

On its own, this setting will show 0 alongside your current line. Vim will prefix the lines above and below your current line with 1. Remaining lines will continue to show their distance from the current line in the same fashion.

You can combine this setting with the standard number setting. With both enabled, your current line will show its actual line number instead of 0.

Change Settings to Show Line Numbers by Default

The location of your vim settings file may vary depending on your system. It’s often a file named .vimrc in your home directory. You can place any set commands in this file and they will take effect by default. So include a line that reads:

In ~/.vimrc and you’ll see line numbers by default, the next time you open the editor. You can still hide them interactively, using the set nonu process above.

Vim’s Powerful Line Numbering Is the Tip of the Iceberg

Vim looks like a basic editor, but it has a very powerful command set. Few text editors have this much flexibility, even when dealing with something as straightforward as line numbers!

Of course, line numbering is just the beginning. You can configure almost any aspect of vim, interactively or via your configuration file.