问题
I noticed a strange behavior in vim regarding the relative numbers:
:set nu
1
2
3 _
4
5
6
~
:set relativenumber
2
1
3 _
1
2
3
~
:set nonu
2
1
0 _
1
2
3
~
I was asking myself why sometime I see the absolute current line number and sometime I see 0 which is pretty useless.
Is this behavior normal and how to correctly number and relativenumber?
回答1:
It's the expected behavior. From :help number_relativenumber
The 'relativenumber' option changes the displayed number to be
relative to the cursor. Together with 'number' there are these
four combinations (cursor in line 3):
'nonu' 'nu' 'nonu' 'nu'
'nornu' 'nornu' 'rnu' 'rnu'
|apple | 1 apple | 2 apple | 2 apple
|pear | 2 pear | 1 pear | 1 pear
|nobody | 3 nobody | 0 nobody |3 nobody
|there | 4 there | 1 there | 1 there
回答2:
That behavior depends on how number and relativenumber are combined.
Everything is explained in :help number_relativenumber, a subsection of :help 'number' that you would have found if you had tried a little harder.
来源:https://stackoverflow.com/questions/27151491/relative-number-in-vim