I was at the fantastic CSSconf.eu on Friday, and one of the presentations include code in Vim with a line numbering setup that blew my mind. It showed the current line number as an absolute number, but showed all other lines as relative numbers, making it super-duper easy to go up or down N lines in normal mode.
I asked the presenter how it was done, and was told it was “part of the SPF13 bundle.” So today I looked it up, but no luck. There was no plugin included to change the line numbers. Time to do a little more digging! In fact, there was a change made to Vim itself in version 7.3.1115 to allow more customization of line numbers. Here’s how it works now:
patch 7.3.1115 changes the ‘number’ and ‘relativenumber’ options so that instead of resetting each other, they interact with each other, so that 4 different displays can be achieved:
both set: relative numbers + absolute number in current line
relativenumber only: only relative numbers, 0 in current line
number only: only absolute numbers
neither set: no line numbering
—vim_dev Google Group thread, message on 25 June 2013 sent by Ben Fritz
Result: for totally sweet line numbers, just update your Vim and put
set relativenumber in your
Edit: To clarify a bit, the old behavior for
relativenumber was to show
0 for the current line number, and that wasn’t modifiable. Setting
number just switched you back to absolute line numbers.