Relative number in vim

为君一笑 提交于 2020-01-01 19:17:38

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!