I'd like to see line numbers, starting with 1 at the top, on the left side of Vim. Ideally it would look like this:

1 | foo = Foo.new
2 | bar = Bar.new
3 | baz = foo.baz(bar)
10| test = AwesomeSauce.test

How can I do this in Vim?


You have two options: set number for regular line numbers

And also set relativenumber which will show relative line numbers. i.e. current line is always 0. This is useful for moving up/down N number of lines using 5j for example.

What is cool is that you can combine them. I have the following in my .vimrc

set number                     " Show current line number
set relativenumber             " Show relative line numbers

This will make it use relative numbers for all lines except the current line, which will show you the actual number.

  • Now I tried this, and it's a schyzo! I mean, confusing. :D
    – yo'
    Feb 3 '15 at 19:02
  • 6
    You can also toggle the commands by appending a "!" to them. E.g. set number! will turn on line numbering if it's off, and turn it on if it's off. set relativenumber can be shortened as set rnu.
    – orjan
    Feb 3 '15 at 21:48

You can use the command:

:set number  

to turn on line numbering. To turn it off again you can use:

:set nonumber   

If you want vim to always default to showing line numbers you can add the command to your vimrc file.

nu and nonu can be used as aliases for number and nonumber respectively.

  • 3
    Here's a small abbreviation: :set nu " to enable :set nonu " to disable
    – stdcall
    Feb 13 '15 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.