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?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityI'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.
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.