Vim Show Line Numbers

How To Show Line Numbers In Vim

There are times when editing or viewing text files that it can be handy to display line numbers for the file on which you’re working. In this tutorial I’ll demonstrate how to show line numbers in Vim/vi/gVim.

Show line numbers in Vim

To turn on the line numbers, you first need to be in Command Mode. If you’re not sure which mode you’re in, just hit the [ESC] key once to make sure. Then enter the following command.

[term]:set number[/term]

That’s it. The line numbers should now be displayed.

Vim Show Line Numbers

Vim Show Line Numbers

Hide line numbers in Vim

Turning the line numbers off is just as easy. Again, make sure you’re in command mode first. Then enter the following.

[term]:set nonumber[/term]

The line numbers should now be hidden.

Vim Don't Show Line Numbers

Vim Don’t Show Line Numbers

Make Vim show line numbers by default

On Linux, the Vim defaults for your user ID are stored in $HOME/.vimrc. (That’s /home/yourID/.vimrc). You can edit this file with Vim by using the following command from the terminal.

[term]vim ~/.vimrc[/term]

If this file doesn’t already exist, Vim will create it. Navigate to the end of the file (it might be a blank file already), then hit [a] to go into Append Mode. Then just enter a new  line:

[term]set number[/term]

Then hit [ESC] to enter Command Mode. Enter the following command to save and quit Vim.

[term]:wq[/term]

On Windows the Vim defaults are stored in C:\Program Files\Vim\_vimrc. Edit the file like I showed above and save it.

Vim will now display line numbers when you start it.

One thought on “How To Show Line Numbers In Vim

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.