vim line numbers - how to show line numbers in the vi/vim editor

vim FAQ: How do I show line numbers in vim (or vi)?

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

aaa
bbb
ccc

and 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 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 vi's "last line mode", where you can issue these vim line number commands.

Post new comment

The content of this field is kept private and will not be shown publicly.