How To Show Line Numbers In Vim

March 29, 2011 by
Filed under: HowTo, linux, Ubuntu, windows 

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.

:set number

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

Affiliate Link
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.

:set nonumber

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.

vim ~/.vimrc

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:

set number

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


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 Response to “How To Show Line Numbers In Vim”

  1. Adjie says:

    Hey, this is good, works for me. Thanks!

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>