nowox
nowox

Reputation: 29178

Relative number in vim

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?

Upvotes: 2

Views: 2443

Answers (2)

romainl
romainl

Reputation: 196906

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.

Upvotes: 2

Stefan
Stefan

Reputation: 114258

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

Upvotes: 11

Related Questions