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?
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.
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.
:se nu to turn on line numbers and :se nu! to toggle - on if it is off, off if it is on
– jmarina
Oct 09 '23 at 07:57
set number!will turn on line numbering if it's off, and turn it on if it's off.set relativenumbercan be shortened asset rnu. – orjan Feb 03 '15 at 21:48:se nuto turn on line numbers and:se nu!to toggle - on if it is off, off if it is on – jmarina Oct 09 '23 at 07:57