Vim tip - showing line numbers

  • November 26, 2007
  • Avatar for peter
    Peter
    Upfold

I covered an ultra quick start on how to get into Vim recently, and now it's time for a related Vim tip.

Being a bit of a geeky text editor, Vim is often used for programming. And in programming, having line numbers easily visible can mean the difference between hunting for a bug for half an hour or finding and correcting it within a few seconds.

Now, it is possible to jump straight to a line of your choice in Vim, but sometimes it can certainly be beneficial to see the line numbers at the side for quick and easy reference. Thankfully, that is very easy to do.

In command mode, simply run the command:

:set number

To turn it back off, run its opposite number:

:set nonumber

You can also set either of these settings as your default by adding the same command to the bottom of the file .vimrc in your home directory (if it doesn't exist, simply create it).

$ cd
$ vim .vimrc

And there you go - line numbers!

Avatar for peter Peter Upfold

Home » Articles »