Reputation: 281
I am working on a file which divided into several sections. I knew in vim there are set nu and set rnu for setting line numbering or relative line numbering on all lines. I wonder vim can setup line numbering so that each section has its own line number, such as
1 Section A
2 jhkj
3 gfsg
...
1 Section B
2 gfsdg
3 gsdfg
4 gsf
....
1 Section C
2 gs
3 kjgk
...
I online searched and can't find help.
Upvotes: 0
Views: 133
Reputation: 172590
No, you cannot influence the built-in :set nu
line numbering.
To get something like this, you could use the signs feature (its column is right next to the number column), but updating all the signs would be a hassle, especially during line insertion / deletion.
I would suggest looking into the NrrwRgn - A Narrow Region Plugin similar to Emacs plugin. With this, you can split each section into a separate buffer (and :set nu
there), and any edits there will be automatically synced back to the original by the plugin.
Upvotes: 1
Reputation: 5112
I do not think that vim gives you that much control over line numbering. You could open a new, narrow window, paste in the correct line numbers, and use 'scrollbind'
. This should work fine if you are just navigating, but it will not update automatically. If you start on Line 1, then this works pretty well:
let ln = 0
let lines = []
g/^/let ln = getline('.') =~ '^Section ' ? 1 : ln + 1 | call add(lines, ln)
5vnew
call append(0, lines)
windo setl scb
Upvotes: 1