How to show line numbers in the vi/vim editor

vim FAQ: How do I show line numbers in the vi/vim editor?

I’m frequently asked if there’s a way to show line numbers in vi (or vim). That is, can you take a normal vim display like this:

aaa
bbb
ccc

and then get vim to show line numbers before each line in the editor, like this:

1 aaa
2 bbb
3 ccc

The answer is a resounding yes.

How to show vim line numbers (vim set number)

You show vim line numbers by issuing this vim “set number” command:

:set number

That command tells vim to display a line number before each line it displays on screen.

Then, if you want to turn off this line number display you can just issue this vi command:

:set nonumber

Remember that you have to issue these vim commands while you’re in the “command mode” of the vi/vim editor. That sounds complicated, but usually all you have to do to make sure you're in command mode is to hit the [Esc] key. Then, when you type the : character at the beginning of these commands, you will be taken to vim’s “last line mode”, where you can issue these line number commands.

Add new comment

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.