feature request: help users count lines - display relative line numbers

19 views
Skip to first unread message

Nick Gravgaard

unread,
Feb 13, 2008, 1:53:34 AM2/13/08
to vim...@vim.org
Hi everyone,

I have an idea which I think will make Vim much faster and easier to
use. I find that over 4 lines or so, it becomes difficult to quickly
count the number of lines I want to delete/yank/shift or whatever, and
so I usually revert to using linewise Visual mode to select the lines I
want to perform the operation on. Obviously it's much faster to (for
example) press 23d than to press V followed by down 23 times and finally
d to delete, but the problem is knowing how many lines I want to perform
the operation on. I believe this could be easily rectified if Vim could
display relative line numbers in the left hand margin (with the current
line being 1, the next being 2, and so on). Then the user could just
look down to the last line they want to operate on, see how many lines
it is from the cursor, and type the command.

Cheers,
Nick

PS. Similar visual hints could help users count words, but I can't see
how it could be done without making the editor look cluttered.

Richard Hartmann

unread,
Feb 13, 2008, 5:54:35 AM2/13/08
to vim...@googlegroups.com
On Feb 13, 2008 7:53 AM, Nick Gravgaard <m...@nickgravgaard.com> wrote:


> I believe this could be easily rectified if Vim could
> display relative line numbers in the left hand margin (with the current
> line being 1, the next being 2, and so on).

I can see this being useful when refactoring code. I would probably map
that to a toggle and use it every once in a while. As a daily-use
feature, it would prolly drive me wild. ;)


Richard

Tony Mechelynck

unread,
Feb 13, 2008, 11:48:52 AM2/13/08
to vim...@googlegroups.com, vim...@vim.org

I guess relative line numbers would have the current line be 0, the next one
1, etc., the line before the current line -1, the one before that -2, etc. --
Vim cannot easily do that, but what it can do is almost as good: Vim can show
absolute line numbers, the first line in the file being 1, the next one 2,
etc. Then instead of visually selecting the lines upon which you want to
operate, you can use an ex-command with a range, such as

:2435,2457d


To quickly select a visual range, you can also use the mouse: start linewise
visual mode using V then use either shift-mouse (if 'mousemodel' is "popup" or
"popup_setpos") or right-click (if 'mousemodel' is "extend") at the other end
of the range.

See
:help 'number'
:help 10.3
:help [range]
:help 'mousemodel'


Best regards,
Tony.
--
In case of atomic attack, the federal ruling against prayer in schools
will be temporarily canceled.

Nico Weber

unread,
Feb 13, 2008, 12:01:36 PM2/13/08
to vim...@googlegroups.com
>> I have an idea which I think will make Vim much faster and easier to
>> use. I find that over 4 lines or so, it becomes difficult to quickly
>> count the number of lines I want to delete/yank/shift or whatever,
>> and
>> so I usually revert to using linewise Visual mode to select the
>> lines I
>> want to perform the operation on. Obviously it's much faster to (for
>> example) press 23d than to press V followed by down 23 times and
>> finally
>> d to delete,

> etc. Then instead of visually selecting the lines upon which you

> want to
> operate, you can use an ex-command with a range, such as
>
> :2435,2457d

Most of the time it's even faster to use v/ (and perhaps 'n' a few
times) to jump to the line where you want to go in my experience.

Nico

Nick Gravgaard

unread,
Feb 13, 2008, 12:22:53 PM2/13/08
to vim...@googlegroups.com, vim...@vim.org

On Wed, 13 Feb 2008 17:48:52 +0100, "Tony Mechelynck"
<antoine.m...@gmail.com> said:
>
> Nick Gravgaard wrote:
> > Hi everyone,
> >
> > I have an idea which I think will make Vim much faster and easier to
> > use. I find that over 4 lines or so, it becomes difficult to quickly
> > count the number of lines I want to delete/yank/shift or whatever, and
> > so I usually revert to using linewise Visual mode to select the lines I
> > want to perform the operation on. Obviously it's much faster to (for
> > example) press 23d than to press V followed by down 23 times and finally
> > d to delete, but the problem is knowing how many lines I want to perform
> > the operation on. I believe this could be easily rectified if Vim could
> > display relative line numbers in the left hand margin (with the current
> > line being 1, the next being 2, and so on). Then the user could just
> > look down to the last line they want to operate on, see how many lines
> > it is from the cursor, and type the command.
> >
> > Cheers,
> > Nick
> >
> > PS. Similar visual hints could help users count words, but I can't see
> > how it could be done without making the editor look cluttered.
>
> I guess relative line numbers would have the current line be 0, the next
> one
> 1, etc.,

At first I thought it should start at 0 too, but then I realised that
it's a count, not an index. 2dd deletes 2 lines, the current line and
the line below it, so it makes sense that the current line should have
"1" next to it and the next line "2".

> the line before the current line -1, the one before that -2,
> etc. --

Can Vim use negative counts?

> Vim cannot easily do that, but what it can do is almost as good: Vim can
> show
> absolute line numbers, the first line in the file being 1, the next one
> 2,
> etc. Then instead of visually selecting the lines upon which you want to
> operate, you can use an ex-command with a range, such as
>
> :2435,2457d

Sure, but it's not as easy or as fast as 23dd though :(

Erik Falor

unread,
Feb 13, 2008, 12:26:00 PM2/13/08
to vim...@googlegroups.com
:.,+23d

Nick Gravgaard

unread,
Feb 13, 2008, 12:33:40 PM2/13/08
to vim...@googlegroups.com
On Wed, 13 Feb 2008 10:26:00 -0700, "Erik Falor" <ewf...@gmail.com>
said:
> :.,+23d

How does that help you count the number of lines you want to delete?

> --
> Erik Falor
> Registered Linux User #445632 http://counter.li.org
>
> >

Erik Falor

unread,
Feb 13, 2008, 1:27:48 PM2/13/08
to vim...@googlegroups.com
On 2/13/08, Nick Gravgaard <m...@nickgravgaard.com> wrote:

On Wed, 13 Feb 2008 10:26:00 -0700, "Erik Falor" <ewf...@gmail.com>
said:
> :.,+23d

How does that help you count the number of lines you want to delete?


Oh, it doesn't.  Its just less to type than :2435,2457d  :)

I think your idea has a lot of potential.  Given the fact that most Vim commands can take a count, I can't believe no one thought of this sooner.
I had never tried to use a negative count before I read this thread.  -2d doesn't delete the current line plus the two above it, but 2d- does.

sc

unread,
Feb 13, 2008, 1:47:29 PM2/13/08
to vim...@googlegroups.com

nick--

it occurs to me, if it were possible to display
relative line numbers as you suggest, right away you
wouldn't like them -- every time you scroll they'd move
as the current line moved -- you'd never see more than
one screen of relative numbers -- so for example if you
wanted to act on several hundred lines, as you scrolled
to see how many there are the numbers would keep
changing

here's a thought: open a 2nd window, put sequence
numbers in it, line it up so line 1 is across from
current in your main window, then turn on scrollbind
for both windows -- it would take some doing but you
could automate it with a script

you do know about marks, right?

sc


Nick Gravgaard

unread,
Feb 13, 2008, 4:04:22 PM2/13/08
to vim...@googlegroups.com

I thought of this too. One way to fix this would be to have an option
which allowed the cursor to exist outside the visible part of the
textbuffer. That way you could scroll down a couple of pages and the
cursor would stay where it was.

> here's a thought: open a 2nd window, put sequence
> numbers in it, line it up so line 1 is across from
> current in your main window, then turn on scrollbind
> for both windows -- it would take some doing but you
> could automate it with a script
>
> you do know about marks, right?

I do now that I've just looked them up. Your scrollbind idea sounds
interesting, but it's a bit of a hack to use 2 windows isn't it?

sc

unread,
Feb 13, 2008, 6:04:00 PM2/13/08
to vim...@googlegroups.com

no, it's a shameless bald-faced blatent hack

but it would work, and you could tie it to a
<Leader>command to line up the other window with
current line at one, scrollbind on, so all you'd have
to do is (for example) type ',r' and you'd get your 2nd
window, sized skinny, all scrollbound and ready to go

i'm just thinking out loud here, you should probably
ignore me

sc

Andy Wokula

unread,
Feb 13, 2008, 4:02:30 PM2/13/08
to vim...@googlegroups.com
Nick Gravgaard schrieb:

>
> On Wed, 13 Feb 2008 17:48:52 +0100, "Tony Mechelynck"
> <antoine.m...@gmail.com> said:
>> Nick Gravgaard wrote:
>>> Hi everyone,
>>>
>>> I have an idea which I think will make Vim much faster and easier to
>>> use. I find that over 4 lines or so, it becomes difficult to quickly
>>> count the number of lines I want to delete/yank/shift or whatever, and
>>> so I usually revert to using linewise Visual mode to select the lines I
>>> want to perform the operation on. Obviously it's much faster to (for
>>> example) press 23d than to press V followed by down 23 times and finally
>>> d to delete, but the problem is knowing how many lines I want to perform
>>> the operation on. I believe this could be easily rectified if Vim could
>>> display relative line numbers in the left hand margin (with the current
>>> line being 1, the next being 2, and so on). Then the user could just
>>> look down to the last line they want to operate on, see how many lines
>>> it is from the cursor, and type the command.
>>>
>>> Cheers,
>>> Nick

Is it ok for you to type
23Vd

Doesn't work out of the box, the builtin "V" handles the count
differently, but with a little work ...

:nn <silent>V :<c-u>exec"norm!V".(v:count>1?v:count-1."j":"")<cr>
" or maybe better:
:nnoremap <silent> V :<c-u>execute "normal! V". v:count1. "_"<cr>

Without your requested Visual hint, it's good to have Visual mode enabled
after 23V, for fine tuning the range.

--
Andy

Yakov Lerner

unread,
Feb 14, 2008, 2:23:59 AM2/14/08
to vim...@googlegroups.com, m...@nickgravgaard.com
Nick Gravgaard <m...@nickgravgaard.com> escrit:

> if Vim could display relative line numbers
> in the left hand margin (with the current
> line being 1, the next being 2, and so on)


Yes, this is easy, vim can.


This is easy implementable in vimscript
using the *SIGNS* (:help signs).
Plus, use the CursorMoved autocommand.

Learn vim scripting yourself, or ask someone
who has vimscript experience to write such script.
Couple of hours if you already have experience with
vimscript, or several days if it's your first nontrivial vim script.

Good luck
Yakov

--
[1] Not related to http://imdb.com/title/tt0286106/ :-)

Nick Gravgaard

unread,
Feb 14, 2008, 2:27:32 AM2/14/08
to vim...@googlegroups.com

On Wed, 13 Feb 2008 22:02:30 +0100, "Andy Wokula" <anw...@yahoo.de>
said:

This is better, but it still involves a bit of trial and error. Your
solution is about guessing and then fine tuning, rather than getting the
number correct instantly (which relative line numbers would allow)...

Nick Gravgaard

unread,
Feb 14, 2008, 2:31:38 AM2/14/08
to Yakov Lerner, vim...@googlegroups.com
On Thu, 14 Feb 2008 09:23:59 +0200, "Yakov Lerner" <ile...@gmail.com>
said:

> Nick Gravgaard <m...@nickgravgaard.com> escrit:
>
> > if Vim could display relative line numbers
> > in the left hand margin (with the current
> > line being 1, the next being 2, and so on)
>
> Yes, this is easy, vim can.
>
> This is easy implementable in vimscript
> using the *SIGNS* (:help signs).
> Plus, use the CursorMoved autocommand.

Thanks Yakov. When I get the time I might have a go at this...

Milan Vancura

unread,
Feb 14, 2008, 9:31:46 AM2/14/08
to vim...@googlegroups.com
>
> Nick Gravgaard <m...@nickgravgaard.com> escrit:
>
> > if Vim could display relative line numbers
> > in the left hand margin (with the current
> > line being 1, the next being 2, and so on)
>
>
> Yes, this is easy, vim can.
>
>
> This is easy implementable in vimscript
> using the *SIGNS* (:help signs).
> Plus, use the CursorMoved autocommand.
>
> Learn vim scripting yourself, or ask someone
> who has vimscript experience to write such script.
> Couple of hours if you already have experience with
> vimscript, or several days if it's your first nontrivial vim script.

I've tried it. It's my first attempt to write vim script but it seems it works.
I hope it helps you, Nick. Feel free to modify it etc.

BTW: Does some experienced vim scripter know how to define a sign with
text=' 1' (starting with a space)? I wanted to align numbers to the right but I
failed. None of "escaping" syntaxes worked.

Milan
--
Milan Vancura, Prague, Czech Republic, Europe

RelLines.vim

Nick Gravgaard

unread,
Feb 14, 2008, 10:16:44 AM2/14/08
to vim...@googlegroups.com

Thanks Milan, that's great. It would be perfect if it updated itself
every time the cursor moved up or down a line, and if it counted as if
the current line's number was 1 (so that to delete the current and next
lines using "2dd" the last line I wanted to delete would have "2" next
to it).

Milan Vancura

unread,
Feb 14, 2008, 11:03:47 AM2/14/08
to vim...@googlegroups.com
> Thanks Milan, that's great. It would be perfect if it updated itself
> every time the cursor moved up or down a line, and if it counted as if
> the current line's number was 1 (so that to delete the current and next
> lines using "2dd" the last line I wanted to delete would have "2" next
> to it).

Super that it works for you. Now it's your turn :-) Modification of minimal
line number is trivial, but events in vim is a system I still don't know -
remember this was my first vim script at all so you probably know more about
vim scripting than me :-)

So modification with events is up to you. BTW, I don't think it's a good idea
because you don't need this feature so often, it may be easier to press one key
to get it when you need it than to slow down vim by recalculating signs every
time the cursor moves. But you will see - try it and tell me.

Milan Vancura

unread,
Feb 14, 2008, 11:15:54 AM2/14/08
to vim...@googlegroups.com
Hi all,

while I was trying to play with signs in vim, I found several issues:

1. there is no way to clear all signs in one file - strange

2. there are no internal functions to work with signs - get a list of them etc.

for example as far as I understand it, ':sign list' is completely unusable in
scripts

3. mksession does not stores signs (probably the result of point 2)

4. minor one: re-definition of some sign has no immediate effect, one must
redraw screen

I know I have little older vim build (7.1 without patches), but I checked all
patches up to today and didn't find anything related.


Did I miss anything?

Milan Vancura

Charles E Campbell Jr

unread,
Feb 14, 2008, 11:43:10 AM2/14/08
to vim...@googlegroups.com
Milan Vancura wrote:

>Hi all,
>
>while I was trying to play with signs in vim, I found several issues:
>
>1. there is no way to clear all signs in one file - strange
>
>

sign unplace *

will remove all signs from all files. It'd seem that

sign unplace * file=somefilenamehere

should work, but it doesn't seem to (I get "E474: Invalid argument")

>2. there are no internal functions to work with signs - get a list of them etc.
>
> for example as far as I understand it, ':sign list' is completely unusable in
>scripts
>
>

Look up :help redir

>3. mksession does not stores signs (probably the result of point 2)
>
>

True (AFAIK)

>4. minor one: re-definition of some sign has no immediate effect, one must
> redraw screen
>
>I know I have little older vim build (7.1 without patches), but I checked all
>patches up to today and didn't find anything related.
>
>
>Did I miss anything?
>
>

Regards,
Chip Campbell

Erik Falor

unread,
Feb 14, 2008, 12:08:37 PM2/14/08
to vim...@googlegroups.com
On 2/14/08, Milan Vancura <mi...@ucw.cz> wrote:
1. there is no way to clear all signs in one file - strange

I'll get to this in a second... 

2. there are no internal functions to work with signs - get a list of them etc.

  for example as far as I understand it, ':sign list' is completely unusable in
scripts

Not exactly;
:redir => s:signs
:silent sign place
:redir END

Now the output of the ':sign place' command is redirected into the variable s:signs, which you can parse through with the built-in regex functions.
It is perhaps not as clean as it would be with internal functions, but certainly do-able.  
After setting up the redirection, you'll want to execute the command with :silent, so that the output isn't also copied to the screen, forcing the user
to tap through several "Press ENTER" prompts.

Knowing this, you may now programatically remove all signs found in a single file.


3. mksession does not stores signs (probably the result of point 2)

This is unfortunate.  
Although, if you see a need for such functionality, you could write a plugin that wraps the :mksession command, and uses the redirection mentioned above to add code to the session file which would replace
all signs upon loading of the session.

4. minor one: re-definition of some sign has no immediate effect, one must
redraw screen

This is the case with many operations that change things on the display; it is common in Vim scripts to finish a function with a :redraw
to make sure everything is ready for the user to see.  This way, you can efficiently do many screen-updating commands and delay
expensive redraws until the end.

Read all about it:
:help lazyredraw

Hope this helps

Milan Vancura

unread,
Feb 15, 2008, 4:41:09 AM2/15/08
to vim...@googlegroups.com
Thank you both you, Chip and Erik, for your answers. I didn't know about
:redir. (it was really my first vim script :-) ) However it still seems to be a
hack instead of a clean solution, probably quite slow for interactive usage.
For example I can't imagine using this workaround in a code called from
cursormove event, like nick wanted to have.

I'm not sure how frequent is the usage of signs today, but if they are to be
used more frequently, new functions for handling them (and using that functions
in mksession) would be a good idea (including a possibility to clear signs in
one file/buffer). Do you agree?

BTW: open folds after vertical diffsplit looks (visually) very similar to signs
but :sign list shows nothing. Interesting... Why two so similar mechanisms were
developped?

John Beckett

unread,
Feb 15, 2008, 9:24:58 PM2/15/08
to vim...@googlegroups.com
Milan Vancura wrote:
> I'm not sure how frequent is the usage of signs today, but if
> they are to be used more frequently, new functions for
> handling them (and using that functions in mksession) would
> be a good idea (including a possibility to clear signs in one
> file/buffer). Do you agree?

I don't use signs, but I took a quick look at the docs from interest. It
does seem that more help from Vim would be good, like maintaining a
script-accessible list of what signs are in use, and perhaps where
(per-file).

But then I wondered whether the system using the signs should maintain that
intelligence itself. If I had some complex script adding signs, I should
probably change signs with a single function, and that function should
maintain its own list or dictionary with whatever information it wants.

John

Erik Falor

unread,
Feb 16, 2008, 9:57:34 AM2/16/08
to vim...@googlegroups.com
On 2/15/08, Milan Vancura <mi...@ucw.cz> wrote:

Thank you both you, Chip and Erik, for your answers. I didn't know about
:redir. (it was really my first vim script :-) ) However it still seems to be a
hack instead of a clean solution, probably quite slow for interactive usage.
For example I can't imagine using this workaround in a code called from
cursormove event, like nick wanted to have.

I'm not sure how frequent is the usage of signs today, but if they are to be
used more frequently, new functions for handling them (and using that functions
in mksession) would be a good idea (including a possibility to clear signs in
one file/buffer). Do you agree?

I think that allowing the user to interact with signs in a more granular way (similar to what we have with regards to the quickfix/location lists) would be a good thing. 

BTW: open folds after vertical diffsplit looks (visually) very similar to signs
but :sign list shows nothing. Interesting... Why two so similar mechanisms were
developped?

I can think of one reason they would be implemented as two separate features: you wouldn't want your signs to go away if you turned on folding.

Markus Heidelberg

unread,
Feb 21, 2008, 4:36:40 AM2/21/08
to vim...@googlegroups.com
Am Wednesday, 13. February 2008 schrieb Nick Gravgaard:
>
> Hi everyone,
>
> I have an idea which I think will make Vim much faster and easier to
> use. I find that over 4 lines or so, it becomes difficult to quickly
> count the number of lines I want to delete/yank/shift or whatever, and
> so I usually revert to using linewise Visual mode to select the lines I
> want to perform the operation on. Obviously it's much faster to (for
> example) press 23d than to press V followed by down 23 times and finally
> d to delete, but the problem is knowing how many lines I want to perform
> the operation on. I believe this could be easily rectified if Vim could
> display relative line numbers in the left hand margin (with the current
> line being 1, the next being 2, and so on). Then the user could just
> look down to the last line they want to operate on, see how many lines
> it is from the cursor, and type the command.

I also thought it could be useful in some cases, so I've just tried it the last
days. Here's the patch (based on svn revision 908, latest patch 258).

To use it set the new option 'relativenumber' or 'rnu'.

I have implemented 'relativenumber' and 'number' exclusive-or, i.e. setting
either resets the other. That was more uncomplicated and I don't think many
people want to display absolute and relative line numbers side by side. It
would be just too confusing.

:print :list and :number don't use 'relativenumber'.

Index: runtime/doc/quickref.txt
===================================================================
*** runtime/doc/quickref.txt (revision 908)
--- runtime/doc/quickref.txt (working copy)
***************
*** 806,811 ****
--- 806,812 ----
'pumheight' 'ph' maximum height of the popup menu
'quoteescape' 'qe' escape characters used in a string
'readonly' 'ro' disallow writing the buffer
+ 'relativenumber' 'rnu' print relative line number in front of each line
'remap' allow mappings to work recursively
'report' threshold for reporting nr. of lines changed
'restorescreen' 'rs' Win32: restore screen when exiting
Index: runtime/doc/version7.txt
===================================================================
*** runtime/doc/version7.txt (revision 908)
--- runtime/doc/version7.txt (working copy)
***************
*** 633,640 ****
'maxmempattern' maximum amount of memory to use for pattern matching
'mkspellmem' parameters for |:mkspell| memory use
'mzquantum' Time in msec to schedule MzScheme threads.
! 'numberwidth' Minimal width of the space used for the 'number'
! option. (Emmanuel Renieris)
'omnifunc' The name of the function used for omni completion.
'operatorfunc' function to be called for |g@| operator
'printmbcharset' CJK character set to be used for :hardcopy
--- 633,640 ----
'maxmempattern' maximum amount of memory to use for pattern matching
'mkspellmem' parameters for |:mkspell| memory use
'mzquantum' Time in msec to schedule MzScheme threads.
! 'numberwidth' Minimal width of the space used for the 'number' and
! 'relativenumber' option. (Emmanuel Renieris)
'omnifunc' The name of the function used for omni completion.
'operatorfunc' function to be called for |g@| operator
'printmbcharset' CJK character set to be used for :hardcopy
Index: runtime/doc/options.txt
===================================================================
*** runtime/doc/options.txt (revision 908)
--- runtime/doc/options.txt (working copy)
***************
*** 1855,1862 ****
parenthesis match. When included "%" ignores
backslashes, which is Vi compatible.
*cpo-n*
! n When included, the column used for 'number' will also
! be used for text of wrapped lines.
*cpo-o*
o Line offset to search command is not remembered for
next search.
--- 1855,1863 ----
parenthesis match. When included "%" ignores
backslashes, which is Vi compatible.
*cpo-n*
! n When included, the column used for 'number' and
! 'relativenumber' will also be used for text of wrapped
! lines.
*cpo-o*
o Line offset to search command is not remembered for
next search.
***************
*** 4807,4812 ****
--- 4808,4814 ----
When a long, wrapped line doesn't start with the first character, '-'
characters are put before the number.
See |hl-LineNr| for the highlighting used for the number.
+ When setting this option, 'relativenumber' is being reset.

*'numberwidth'* *'nuw'*
'numberwidth' 'nuw' number (Vim default: 4 Vi default: 8)
***************
*** 4815,4827 ****
{only available when compiled with the |+linebreak|
feature}
Minimal number of columns to use for the line number. Only relevant
! when the 'number' option is set or printing lines with a line number.
! Since one space is always between the number and the text, there is
! one less character for the number itself.
The value is the minimum width. A bigger width is used when needed to
! fit the highest line number in the buffer. Thus with the Vim default
! of 4 there is room for a line number up to 999. When the buffer has
! 1000 lines five columns will be used.
The minimum value is 1, the maximum value is 10.
NOTE: 'numberwidth' is reset to 8 when 'compatible' is set.

--- 4817,4831 ----
{only available when compiled with the |+linebreak|
feature}
Minimal number of columns to use for the line number. Only relevant
! when the 'number' or 'relativenumber' option is set or printing lines
! with a line number. Since one space is always between the number and
! the text, there is one less character for the number itself.
The value is the minimum width. A bigger width is used when needed to
! fit the highest line number in the buffer respectively the number of
! rows in the window, depending on whether 'number' or 'relativenumber'
! is set. Thus with the Vim default of 4 there is room for a line
! number up to 999. When the buffer has 1000 lines five columns will be
! used.
The minimum value is 1, the maximum value is 10.
NOTE: 'numberwidth' is reset to 8 when 'compatible' is set.

***************
*** 5202,5207 ****
--- 5206,5226 ----
matches will be highlighted. This is used to avoid that Vim hangs
when using a very complicated pattern.

+ *'relativenumber'* *'rnu'* *'norelativenumber'* *'nornu'*
+ 'relativenumber' 'rnu' boolean (default off)
+ local to window
+ {not in Vi}
+ Print the line number relative to the line with the cursor in front of
+ each line. When the 'n' option is excluded from 'cpoptions' a wrapped
+ line will not use the column of line numbers (this is the default when
+ 'compatible' isn't set).
+ The 'numberwidth' option can be used to set the room used for the line
+ number.
+ When a long, wrapped line doesn't start with the first character, '-'
+ characters are put before the number.
+ See |hl-LineNr| for the highlighting used for the number.
+ When setting this option, 'number' is being reset.
+
*'remap'* *'noremap'*
'remap' boolean (default on)
global
Index: runtime/lang/menu_de_de.latin1.vim
===================================================================
*** runtime/lang/menu_de_de.latin1.vim (revision 908)
--- runtime/lang/menu_de_de.latin1.vim (working copy)
***************
*** 84,96 ****
menutrans F&ile\ Settings &Datei-Einstellungen

" Boolean options
! menutrans Toggle\ Line\ &Numbering<Tab>:set\ nu! Anzeige\ der\ Zeilen&nummer\ ein-\ und\ ausschalten<Tab>:set\ nu!
! menutrans Toggle\ &List\ Mode<Tab>:set\ list! &List-Modus\ ein-\ und\ ausschalten<Tab>:set\ list!
! menutrans Toggle\ Line\ &Wrap<Tab>:set\ wrap! &Zeilenumbruch\ ein-\ und\ ausschalten<Tab>:set\ wrap!
! menutrans Toggle\ W&rap\ at\ word<Tab>:set\ lbr! Umbruch\ an\ &Wortgrenzen\ ein-\ und\ ausschalten<Tab>:set\ lbr!
! menutrans Toggle\ &expand-tab<Tab>:set\ et! &Erweiterung\ von\ Tabulatoren\ ein-\ und\ ausschalten<Tab>:set\ et!
! menutrans Toggle\ &auto-indent<Tab>:set\ ai! &Automatische\ Einrückung\ ein-\ und\ ausschalten<Tab>:set\ ai!
! menutrans Toggle\ &C-indenting<Tab>:set\ cin! &C-Einrückung\ ein-\ und\ ausschalten<Tab>:set\ cin!

" other options
menutrans &Shiftwidth &Schiebeweite
--- 84,97 ----
menutrans F&ile\ Settings &Datei-Einstellungen

" Boolean options
! menutrans Toggle\ Line\ &Numbering<Tab>:set\ nu! Anzeige\ der\ Zeilen&nummer\ ein-\ und\ ausschalten<Tab>:set\ nu!
! menutrans Toggle\ relati&ve\ Line\ Numbering<Tab>:set\ rnu! Anzeige\ der\ relati&ven\ Zeilennummer\ ein-\ und\ ausschalten<Tab>:set\ rnu!
! menutrans Toggle\ &List\ Mode<Tab>:set\ list! &List-Modus\ ein-\ und\ ausschalten<Tab>:set\ list!
! menutrans Toggle\ Line\ &Wrap<Tab>:set\ wrap! &Zeilenumbruch\ ein-\ und\ ausschalten<Tab>:set\ wrap!
! menutrans Toggle\ W&rap\ at\ word<Tab>:set\ lbr! Umbruch\ an\ &Wortgrenzen\ ein-\ und\ ausschalten<Tab>:set\ lbr!
! menutrans Toggle\ &expand-tab<Tab>:set\ et! &Erweiterung\ von\ Tabulatoren\ ein-\ und\ ausschalten<Tab>:set\ et!
! menutrans Toggle\ &auto-indent<Tab>:set\ ai! &Automatische\ Einrückung\ ein-\ und\ ausschalten<Tab>:set\ ai!
! menutrans Toggle\ &C-indenting<Tab>:set\ cin! &C-Einrückung\ ein-\ und\ ausschalten<Tab>:set\ cin!

" other options
menutrans &Shiftwidth &Schiebeweite
Index: runtime/syntax/vim.vim
===================================================================
*** runtime/syntax/vim.vim (revision 908)
--- runtime/syntax/vim.vim (working copy)
***************
*** 20,26 ****
syn match vimCommand contained "\<z[-+^.=]"

" vimOptions are caught only when contained in a vimSet {{{2
! syn keyword vimOption contained acd ai akm al aleph allowrevins altkeymap ambiwidth ambw anti antialias ar arab arabic arabicshape ari arshape autochdir autoindent autoread autowrite autowriteall aw awa background backspace backup backupcopy backupdir backupext backupskip balloondelay ballooneval balloonexpr bdir bdlay beval bex bexpr bg bh bin binary biosk bioskey bk bkc bl bomb breakat brk browsedir bs bsdir bsk bt bufhidden buflisted buftype casemap cb ccv cd cdpath cedit cf cfu ch charconvert ci cin cindent cink cinkeys cino cinoptions cinw cinwords clipboard cmdheight cmdwinheight cmp cms co columns com comments commentstring compatible complete completefunc completeopt confirm consk conskey copyindent cot cp cpo cpoptions cpt cscopepathcomp cscopeprg cscopequickfix cscopetag cscopetagorder cscopeverbose cspc csprg csqf cst csto csverb cuc cul cursorcolumn cursorline cwh debug deco def define delcombine dex dg dict dictionary diff diffexpr diffopt digraph dip dir directory display dy ea ead eadirection eb ed edcompatible ef efm ei ek enc encoding endofline eol ep equalalways equalprg errorbells errorfile errorformat esckeys et eventignore ex expandtab exrc fcl fcs fdc fde fdi fdl fdls fdm fdn fdo fdt fen fenc fencs fex ff ffs fileencoding fileencodings fileformat fileformats filetype fillchars fk fkmap flp fml fmr fo foldclose foldcolumn foldenable foldexpr foldignore foldlevel foldlevelstart foldmarker foldmethod foldminlines foldnestmax foldopen foldtext formatexpr formatlistpat formatoptions formatprg fp fs fsync ft gcr gd gdefault gfm gfn gfs gfw ghr go gp grepformat grepprg gtl gtt guicursor guifont guifontset guifontwide guiheadroom guioptions guipty guitablabel guitabtooltip helpfile helpheight helplang hf hh hi hid hidden highlight history hk hkmap hkmapp hkp hl hlg hls hlsearch ic icon iconstring ignorecase im imactivatekey imak imc imcmdline imd imdisable imi iminsert ims imsearch inc include includeexpr incsearch inde indentexpr indentkeys indk inex inf infercase insertmode is isf isfname isi isident isk iskeyword isp isprint joinspaces js key keymap keymodel keywordprg km kmp kp langmap langmenu laststatus lazyredraw lbr lcs linebreak lines linespace lisp lispwords list listchars lm lmap loadplugins lpl ls lsp lw lz ma macatsui magic makeef makeprg mat matchpairs matchtime maxcombine maxfuncdepth maxmapdepth maxmem maxmempattern maxmemtot mco mef menuitems mfd mh mis mkspellmem ml mls mm mmd mmp mmt mod modeline modelines modifiable modified more mouse mousef mousefocus mousehide mousem mousemodel mouses mouseshape mouset mousetime mp mps msm mzq mzquantum nf nrformats nu number numberwidth nuw odev oft ofu omnifunc opendevice operatorfunc opfunc osfiletype pa para paragraphs paste pastetoggle patchexpr patchmode path pdev penc pex pexpr pfn ph pheader pi pm pmbcs pmbfn popt preserveindent previewheight previewwindow printdevice printencoding printexpr printfont printheader printmbcharset printmbfont printoptions prompt pt pumheight pvh pvw qe quoteescape readonly remap report restorescreen revins ri rightleft rightleftcmd rl rlc ro rs rtp ru ruf ruler rulerformat runtimepath sb sbo sbr sc scb scr scroll scrollbind scrolljump scrolloff scrollopt scs sect sections secure sel selection selectmode sessionoptions sft sh shcf shell shellcmdflag shellpipe shellquote shellredir shellslash shelltemp shelltype shellxquote shiftround shiftwidth shm shortmess shortname showbreak showcmd showfulltag showmatch showmode showtabline shq si sidescroll sidescrolloff siso sj slm sm smartcase smartindent smarttab smc smd sn so softtabstop sol sp spc spell spellcapcheck spellfile spelllang spellsuggest spf spl splitbelow splitright spr sps sr srr ss ssl ssop st sta stal startofline statusline stl stmp sts su sua suffixes suffixesadd sw swapfile swapsync swb swf switchbuf sws sxq syn synmaxcol syntax ta tabline tabpagemax tabstop tag tagbsearch taglength tagrelative tags tagstack tal tb tbi tbidi tbis tbs tenc term termbidi termencoding terse textauto textmode textwidth tf tgst thesaurus tildeop timeout timeoutlen title titlelen titleold titlestring tl tm to toolbar toolbariconsize top tpm tr ts tsl tsr ttimeout ttimeoutlen ttm tty ttybuiltin ttyfast ttym ttymouse ttyscroll ttytype tw tx uc ul undolevels updatecount updatetime ut vb vbs vdir ve verbose verbosefile vfile vi viewdir viewoptions viminfo virtualedit visualbell vop wa wak warn wb wc wcm wd weirdinvert wfh wfw wh whichwrap wi wig wildchar wildcharm wildignore wildmenu wildmode wildoptions wim winaltkeys window winfixheight winfixwidth winheight winminheight winminwidth winwidth wiv wiw wm wmh wmnu wmw wop wrap wrapmargin wrapscan write writeany writebackup writedelay ws ww

" vimOptions: These are the turn-off setting variants {{{2
syn keyword vimOption contained noacd noai noakm noallowrevins noaltkeymap noanti noantialias noar noarab noarabic noarabicshape noari noarshape noautochdir noautoindent noautoread noautowrite noautowriteall noaw noawa nobackup noballooneval nobeval nobin nobinary nobiosk nobioskey nobk nobl nobomb nobuflisted nocf noci nocin nocindent nocompatible noconfirm noconsk noconskey nocopyindent nocp nocscopetag nocscopeverbose nocst nocsverb nocuc nocul nocursorcolumn nocursorline nodeco nodelcombine nodg nodiff nodigraph nodisable noea noeb noed noedcompatible noek noendofline noeol noequalalways noerrorbells noesckeys noet noex noexpandtab noexrc nofen nofk nofkmap nofoldenable nogd nogdefault noguipty nohid nohidden nohk nohkmap nohkmapp nohkp nohls nohlsearch noic noicon noignorecase noim noimc noimcmdline noimd noincsearch noinf noinfercase noinsertmode nois nojoinspaces nojs nolazyredraw nolbr nolinebreak nolisp nolist noloadplugins nolpl nolz noma nomacatsui nomagic nomh noml nomod nomodeline nomodifiable nomodified nomore nomousef nomousefocus nomousehide nonu nonumber noodev noopendevice nopaste nopi nopreserveindent nopreviewwindow noprompt nopvw noreadonly noremap norestorescreen norevins nori norightleft norightleftcmd norl norlc noro nors noru noruler nosb nosc noscb noscrollbind noscs nosecure nosft noshellslash noshelltemp noshiftround noshortname noshowcmd noshowfulltag noshowmatch noshowmode nosi nosm nosmartcase nosmartindent nosmarttab nosmd nosn nosol nospell nosplitbelow nosplitright nospr nosr nossl nosta nostartofline nostmp noswapfile noswf nota notagbsearch notagrelative notagstack notbi notbidi notbs notermbidi noterse notextauto notextmode notf notgst notildeop notimeout notitle noto notop notr nottimeout nottybuiltin nottyfast notx novb novisualbell nowa nowarn nowb noweirdinvert nowfh nowfw nowildmenu nowinfixheight nowinfixwidth nowiv nowmnu nowrap nowrapscan nowrite nowriteany nowritebackup nows
--- 20,26 ----
syn match vimCommand contained "\<z[-+^.=]"

" vimOptions are caught only when contained in a vimSet {{{2
! syn keyword vimOption contained acd ai akm al aleph allowrevins altkeymap ambiwidth ambw anti antialias ar arab arabic arabicshape ari arshape autochdir autoindent autoread autowrite autowriteall aw awa background backspace backup backupcopy backupdir backupext backupskip balloondelay ballooneval balloonexpr bdir bdlay beval bex bexpr bg bh bin binary biosk bioskey bk bkc bl bomb breakat brk browsedir bs bsdir bsk bt bufhidden buflisted buftype casemap cb ccv cd cdpath cedit cf cfu ch charconvert ci cin cindent cink cinkeys cino cinoptions cinw cinwords clipboard cmdheight cmdwinheight cmp cms co columns com comments commentstring compatible complete completefunc completeopt confirm consk conskey copyindent cot cp cpo cpoptions cpt cscopepathcomp cscopeprg cscopequickfix cscopetag cscopetagorder cscopeverbose cspc csprg csqf cst csto csverb cuc cul cursorcolumn cursorline cwh debug deco def define delcombine dex dg dict dictionary diff diffexpr diffopt digraph dip dir directory display dy ea ead eadirection eb ed edcompatible ef efm ei ek enc encoding endofline eol ep equalalways equalprg errorbells errorfile errorformat esckeys et eventignore ex expandtab exrc fcl fcs fdc fde fdi fdl fdls fdm fdn fdo fdt fen fenc fencs fex ff ffs fileencoding fileencodings fileformat fileformats filetype fillchars fk fkmap flp fml fmr fo foldclose foldcolumn foldenable foldexpr foldignore foldlevel foldlevelstart foldmarker foldmethod foldminlines foldnestmax foldopen foldtext formatexpr formatlistpat formatoptions formatprg fp fs fsync ft gcr gd gdefault gfm gfn gfs gfw ghr go gp grepformat grepprg gtl gtt guicursor guifont guifontset guifontwide guiheadroom guioptions guipty guitablabel guitabtooltip helpfile helpheight helplang hf hh hi hid hidden highlight history hk hkmap hkmapp hkp hl hlg hls hlsearch ic icon iconstring ignorecase im imactivatekey imak imc imcmdline imd imdisable imi iminsert ims imsearch inc include includeexpr incsearch inde indentexpr indentkeys indk inex inf infercase insertmode is isf isfname isi isident isk iskeyword isp isprint joinspaces js key keymap keymodel keywordprg km kmp kp langmap langmenu laststatus lazyredraw lbr lcs linebreak lines linespace lisp lispwords list listchars lm lmap loadplugins lpl ls lsp lw lz ma macatsui magic makeef makeprg mat matchpairs matchtime maxcombine maxfuncdepth maxmapdepth maxmem maxmempattern maxmemtot mco mef menuitems mfd mh mis mkspellmem ml mls mm mmd mmp mmt mod modeline modelines modifiable modified more mouse mousef mousefocus mousehide mousem mousemodel mouses mouseshape mouset mousetime mp mps msm mzq mzquantum nf nrformats nu number numberwidth nuw odev oft ofu omnifunc opendevice operatorfunc opfunc osfiletype pa para paragraphs paste pastetoggle patchexpr patchmode path pdev penc pex pexpr pfn ph pheader pi pm pmbcs pmbfn popt preserveindent previewheight previewwindow printdevice printencoding printexpr printfont printheader printmbcharset printmbfont printoptions prompt pt pumheight pvh pvw qe quoteescape readonly relativenumber remap report restorescreen revins ri rightleft rightleftcmd rl rlc rnu ro rs rtp ru ruf ruler rulerformat runtimepath sb sbo sbr sc scb scr scroll scrollbind scrolljump scrolloff scrollopt scs sect sections secure sel selection selectmode sessionoptions sft sh shcf shell shellcmdflag shellpipe shellquote shellredir shellslash shelltemp shelltype shellxquote shiftround shiftwidth shm shortmess shortname showbreak showcmd showfulltag showmatch showmode showtabline shq si sidescroll sidescrolloff siso sj slm sm smartcase smartindent smarttab smc smd sn so softtabstop sol sp spc spell spellcapcheck spellfile spelllang spellsuggest spf spl splitbelow splitright spr sps sr srr ss ssl ssop st sta stal startofline statusline stl stmp sts su sua suffixes suffixesadd sw swapfile swapsync swb swf switchbuf sws sxq syn synmaxcol syntax ta tabline tabpagemax tabstop tag tagbsearch taglength tagrelative tags tagstack tal tb tbi tbidi tbis tbs tenc term termbidi termencoding terse textauto textmode textwidth tf tgst thesaurus tildeop timeout timeoutlen title titlelen titleold titlestring tl tm to toolbar toolbariconsize top tpm tr ts tsl tsr ttimeout ttimeoutlen ttm tty ttybuiltin ttyfast ttym ttymouse ttyscroll ttytype tw tx uc ul undolevels updatecount updatetime ut vb vbs vdir ve verbose verbosefile vfile vi viewdir viewoptions viminfo virtualedit visualbell vop wa wak warn wb wc wcm wd weirdinvert wfh wfw wh whichwrap wi wig wildchar wildcharm wildignore wildmenu wildmode wildoptions wim winaltkeys window winfixheight winfixwidth winheight winminheight winminwidth winwidth wiv wiw wm wmh wmnu wmw wop wrap wrapmargin wrapscan write writeany writebackup writedelay ws ww

" vimOptions: These are the turn-off setting variants {{{2
syn keyword vimOption contained noacd noai noakm noallowrevins noaltkeymap noanti noantialias noar noarab noarabic noarabicshape noari noarshape noautochdir noautoindent noautoread noautowrite noautowriteall noaw noawa nobackup noballooneval nobeval nobin nobinary nobiosk nobioskey nobk nobl nobomb nobuflisted nocf noci nocin nocindent nocompatible noconfirm noconsk noconskey nocopyindent nocp nocscopetag nocscopeverbose nocst nocsverb nocuc nocul nocursorcolumn nocursorline nodeco nodelcombine nodg nodiff nodigraph nodisable noea noeb noed noedcompatible noek noendofline noeol noequalalways noerrorbells noesckeys noet noex noexpandtab noexrc nofen nofk nofkmap nofoldenable nogd nogdefault noguipty nohid nohidden nohk nohkmap nohkmapp nohkp nohls nohlsearch noic noicon noignorecase noim noimc noimcmdline noimd noincsearch noinf noinfercase noinsertmode nois nojoinspaces nojs nolazyredraw nolbr nolinebreak nolisp nolist noloadplugins nolpl nolz noma nomacatsui nomagic nomh noml nomod nomodeline nomodifiable nomodified nomore nomousef nomousefocus nomousehide nonu nonumber noodev noopendevice nopaste nopi nopreserveindent nopreviewwindow noprompt nopvw noreadonly noremap norestorescreen norevins nori norightleft norightleftcmd norl norlc noro nors noru noruler nosb nosc noscb noscrollbind noscs nosecure nosft noshellslash noshelltemp noshiftround noshortname noshowcmd noshowfulltag noshowmatch noshowmode nosi nosm nosmartcase nosmartindent nosmarttab nosmd nosn nosol nospell nosplitbelow nosplitright nospr nosr nossl nosta nostartofline nostmp noswapfile noswf nota notagbsearch notagrelative notagstack notbi notbidi notbs notermbidi noterse notextauto notextmode notf notgst notildeop notimeout notitle noto notop notr nottimeout nottybuiltin nottyfast notx novb novisualbell nowa nowarn nowb noweirdinvert nowfh nowfw nowildmenu nowinfixheight nowinfixwidth nowiv nowmnu nowrap nowrapscan nowrite nowriteany nowritebackup nows
Index: runtime/menu.vim
===================================================================
*** runtime/menu.vim (revision 908)
--- runtime/menu.vim (working copy)
***************
*** 269,274 ****
--- 269,275 ----

" Boolean options
an 20.440.100 &Edit.F&ile\ Settings.Toggle\ Line\ &Numbering<Tab>:set\ nu! :set nu! nu?<CR>
+ an 20.440.105 &Edit.F&ile\ Settings.Toggle\ relati&ve\ Line\ Numbering<Tab>:set\ rnu! :set rnu! rnu?<CR>
an 20.440.110 &Edit.F&ile\ Settings.Toggle\ &List\ Mode<Tab>:set\ list! :set list! list?<CR>
an 20.440.120 &Edit.F&ile\ Settings.Toggle\ Line\ &Wrap<Tab>:set\ wrap! :set wrap! wrap?<CR>
an 20.440.130 &Edit.F&ile\ Settings.Toggle\ W&rap\ at\ word<Tab>:set\ lbr! :set lbr! lbr?<CR>
Index: runtime/optwin.vim
===================================================================
*** runtime/optwin.vim (revision 908)
--- runtime/optwin.vim (working copy)
***************
*** 361,366 ****
--- 361,369 ----
call append("$", "number\tshow the line number for each line")
call append("$", "\t(local to window)")
call <SID>BinOptionL("nu")
+ call append("$", "relativenumber\tshow the relative line number for each line")
+ call append("$", "\t(local to window)")
+ call <SID>BinOptionL("rnu")
if has("linebreak")
call append("$", "numberwidth\tnumber of columns to use for the line number")
call append("$", "\t(local to window)")
Index: src/proto/misc2.pro
===================================================================
*** src/proto/misc2.pro (revision 908)
--- src/proto/misc2.pro (working copy)
***************
*** 2,7 ****
--- 2,8 ----
int virtual_active __ARGS((void));
int getviscol __ARGS((void));
int getviscol2 __ARGS((colnr_T col, colnr_T coladd));
+ linenr_T get_cursor_rel_lnum __ARGS((win_T *wp, linenr_T lnum));
int coladvance_force __ARGS((colnr_T wcol));
int coladvance __ARGS((colnr_T wcol));
int getvpos __ARGS((pos_T *pos, colnr_T wcol));
***************
*** 82,95 ****
int update_keys __ARGS((int c));
void crypt_init_keys __ARGS((char_u *passwd));
char_u *get_crypt_key __ARGS((int store, int twice));
! void *vim_findfile_init __ARGS((char_u *path, char_u *filename, char_u *stopdirs, int level, int free_visited, int need_dir, void *search_ctx, int tagfile, char_u *rel_fname));
char_u *vim_findfile_stopdir __ARGS((char_u *buf));
void vim_findfile_cleanup __ARGS((void *ctx));
! char_u *vim_findfile __ARGS((void *search_ctx));
! void vim_findfile_free_visited __ARGS((void *search_ctx));
char_u *find_file_in_path __ARGS((char_u *ptr, int len, int options, int first, char_u *rel_fname));
char_u *find_directory_in_path __ARGS((char_u *ptr, int len, int options, char_u *rel_fname));
! char_u *find_file_in_path_option __ARGS((char_u *ptr, int len, int options, int first, char_u *path_option, int need_dir, char_u *rel_fname, char_u *suffixes));
int vim_chdir __ARGS((char_u *new_dir));
int get_user_name __ARGS((char_u *buf, int len));
void sort_strings __ARGS((char_u **files, int count));
--- 83,96 ----
int update_keys __ARGS((int c));
void crypt_init_keys __ARGS((char_u *passwd));
char_u *get_crypt_key __ARGS((int store, int twice));
! void *vim_findfile_init __ARGS((char_u *path, char_u *filename, char_u *stopdirs, int level, int free_visited, int find_what, void *search_ctx_arg, int tagfile, char_u *rel_fname));
char_u *vim_findfile_stopdir __ARGS((char_u *buf));
void vim_findfile_cleanup __ARGS((void *ctx));
! char_u *vim_findfile __ARGS((void *search_ctx_arg));
! void vim_findfile_free_visited __ARGS((void *search_ctx_arg));
char_u *find_file_in_path __ARGS((char_u *ptr, int len, int options, int first, char_u *rel_fname));
char_u *find_directory_in_path __ARGS((char_u *ptr, int len, int options, char_u *rel_fname));
! char_u *find_file_in_path_option __ARGS((char_u *ptr, int len, int options, int first, char_u *path_option, int find_what, char_u *rel_fname, char_u *suffixes));
int vim_chdir __ARGS((char_u *new_dir));
int get_user_name __ARGS((char_u *buf, int len));
void sort_strings __ARGS((char_u **files, int count));
Index: src/edit.c
===================================================================
*** src/edit.c (revision 908)
--- src/edit.c (working copy)
***************
*** 6165,6171 ****
)
textwidth -= 1;
#endif
! if (curwin->w_p_nu)
textwidth -= 8;
}
if (textwidth < 0)
--- 6165,6171 ----
)
textwidth -= 1;
#endif
! if (curwin->w_p_nu || curwin->w_p_rnu)
textwidth -= 8;
}
if (textwidth < 0)
Index: src/ex_cmds.c
===================================================================
*** src/ex_cmds.c (revision 908)
--- src/ex_cmds.c (working copy)
***************
*** 3462,3467 ****
--- 3462,3468 ----
curbuf->b_p_ma = FALSE; /* not modifiable */
curbuf->b_p_bin = FALSE; /* reset 'bin' before reading file */
curwin->w_p_nu = 0; /* no line numbers */
+ curwin->w_p_rnu = 0; /* no relative line numbers */
#ifdef FEAT_SCROLLBIND
curwin->w_p_scb = FALSE; /* no scroll binding */
#endif
Index: src/gui.c
===================================================================
*** src/gui.c (revision 908)
--- src/gui.c (working copy)
***************
*** 4355,4361 ****
max += W_WIDTH(curwin) - 1;
#endif
/* The line number isn't scrolled, thus there is less space when
! * 'number' is set (also for 'foldcolumn'). */
size -= curwin_col_off();
#ifndef SCROLL_PAST_END
max -= curwin_col_off();
--- 4355,4361 ----
max += W_WIDTH(curwin) - 1;
#endif
/* The line number isn't scrolled, thus there is less space when
! * 'number' or 'relativenumber' is set (also for 'foldcolumn'). */
size -= curwin_col_off();
#ifndef SCROLL_PAST_END
max -= curwin_col_off();
Index: src/misc1.c
===================================================================
*** src/misc1.c (revision 908)
--- src/misc1.c (working copy)
***************
*** 1744,1750 ****
col += 1;

/*
! * Add column offset for 'number' and 'foldcolumn'.
*/
width = W_WIDTH(wp) - win_col_off(wp);
if (width <= 0)
--- 1744,1750 ----
col += 1;

/*
! * Add column offset for 'number', 'relativenumber' and 'foldcolumn'.
*/
width = W_WIDTH(wp) - win_col_off(wp);
if (width <= 0)
***************
*** 1805,1811 ****
col += win_lbr_chartabsize(wp, s, (colnr_T)col, NULL) - 1;

/*
! * Add column offset for 'number', 'foldcolumn', etc.
*/
width = W_WIDTH(wp) - win_col_off(wp);
if (width <= 0)
--- 1805,1811 ----
col += win_lbr_chartabsize(wp, s, (colnr_T)col, NULL) - 1;

/*
! * Add column offset for 'number', 'relativenumber', 'foldcolumn', etc.
*/
width = W_WIDTH(wp) - win_col_off(wp);
if (width <= 0)
Index: src/misc2.c
===================================================================
*** src/misc2.c (revision 908)
--- src/misc2.c (working copy)
***************
*** 72,77 ****
--- 72,127 ----
}

/*
+ * Get the line number relative to the actual cursor position, i.e. the
+ * difference between line number and cursor position
+ */
+ linenr_T
+ get_cursor_rel_lnum(wp, lnum)
+ win_T *wp;
+ linenr_T lnum; /* line number to get the result for */
+ {
+ linenr_T cursor = wp->w_cursor.lnum;
+ linenr_T retval = 0;
+
+ #ifdef FEAT_FOLDING
+ if (hasAnyFolding(wp))
+ {
+ if (lnum > cursor)
+ {
+ while (lnum > cursor)
+ {
+ (void)hasFolding(lnum, &lnum, NULL);
+ /* if lnum and cursor are in the same fold,
+ * now lnum <= cursor */
+ if (lnum > cursor)
+ retval ++;
+ lnum --;
+ }
+ }
+ else if (lnum < cursor)
+ {
+ while (lnum < cursor)
+ {
+ (void)hasFolding(lnum, NULL, &lnum);
+ /* if lnum and cursor are in the same fold,
+ * now lnum >= cursor */
+ if (lnum < cursor)
+ retval --;
+ lnum ++;
+ }
+ }
+ /* else if (lnum == cursor)
+ * retval = 0;
+ */
+ }
+ else
+ #endif
+ retval = lnum - cursor;
+
+ return retval;
+ }
+
+ /*
* Go to column "wcol", and add/insert white space as necessary to get the
* cursor in that column.
* The caller must have saved the cursor line for undo!
Index: src/move.c
===================================================================
*** src/move.c (revision 908)
--- src/move.c (working copy)
***************
*** 904,917 ****
}

/*
! * Compute offset of a window, occupied by line number, fold column and sign
! * column (these don't move when scrolling horizontally).
*/
int
win_col_off(wp)
win_T *wp;
{
! return ((wp->w_p_nu ? number_width(wp) + 1 : 0)
#ifdef FEAT_CMDWIN
+ (cmdwin_type == 0 || wp != curwin ? 0 : 1)
#endif
--- 904,917 ----
}

/*
! * Compute offset of a window, occupied by absolute or relative line number,
! * fold column and sign column (these don't move when scrolling horizontally).
*/
int
win_col_off(wp)
win_T *wp;
{
! return (((wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) + 1 : 0)
#ifdef FEAT_CMDWIN
+ (cmdwin_type == 0 || wp != curwin ? 0 : 1)
#endif
***************
*** 937,949 ****

/*
* Return the difference in column offset for the second screen line of a
! * wrapped line. It's 8 if 'number' is on and 'n' is in 'cpoptions'.
*/
int
win_col_off2(wp)
win_T *wp;
{
! if (wp->w_p_nu && vim_strchr(p_cpo, CPO_NUMCOL) != NULL)
return number_width(wp) + 1;
return 0;
}
--- 937,950 ----

/*
* Return the difference in column offset for the second screen line of a
! * wrapped line. It's 8 if 'number' or 'relativenumber' is on and 'n' is in
! * 'cpoptions'.
*/
int
win_col_off2(wp)
win_T *wp;
{
! if ((wp->w_p_nu || wp->w_p_rnu) && vim_strchr(p_cpo, CPO_NUMCOL) != NULL)
return number_width(wp) + 1;
return 0;
}
***************
*** 1205,1221 ****
if (prev_skipcol != curwin->w_skipcol)
redraw_later(NOT_VALID);

#ifdef FEAT_SYN_HL
! /* Redraw when w_virtcol changes and 'cursorcolumn' is set, or when w_row
! * changes and 'cursorline' is set. */
! if (((curwin->w_p_cuc && (curwin->w_valid & VALID_VIRTCOL) == 0)
! || (curwin->w_p_cul && (curwin->w_valid & VALID_WROW) == 0))
# ifdef FEAT_INS_EXPAND
! && !pum_visible()
# endif
! )
! redraw_later(SOME_VALID);
! #endif

curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
}
--- 1206,1227 ----
if (prev_skipcol != curwin->w_skipcol)
redraw_later(NOT_VALID);

+ /* Redraw when w_row changes and 'relativenumber' is set */
+ if (((curwin->w_valid & VALID_WROW) == 0 && (curwin->w_p_rnu
#ifdef FEAT_SYN_HL
! /* or when w_row changes and 'cursorline' is set. */
! || curwin->w_p_cul
! #endif
! ))
! #ifdef FEAT_SYN_HL
! /* or when w_virtcol changes and 'cursorcolumn' is set */
! || (curwin->w_p_cuc && (curwin->w_valid & VALID_VIRTCOL) == 0)
! #endif
! )
# ifdef FEAT_INS_EXPAND
! if (!pum_visible())
# endif
! redraw_later(SOME_VALID);

curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
}
Index: src/netbeans.c
===================================================================
*** src/netbeans.c (revision 908)
--- src/netbeans.c (working copy)
***************
*** 3032,3038 ****

if (bufno >= 0 && curwin != NULL && curwin->w_buffer == curbuf)
{
! int col = mouse_col - W_WINCOL(curwin) - (curwin->w_p_nu ? 9 : 1);
long off = pos2off(curbuf, &curwin->w_cursor);

/* sync the cursor position */
--- 3032,3039 ----

if (bufno >= 0 && curwin != NULL && curwin->w_buffer == curbuf)
{
! int col = mouse_col - W_WINCOL(curwin)
! - ((curwin->w_p_nu || curwin->w_p_rnu) ? 9 : 1);
long off = pos2off(curbuf, &curwin->w_cursor);

/* sync the cursor position */
Index: src/normal.c
===================================================================
*** src/normal.c (revision 908)
--- src/normal.c (working copy)
***************
*** 7748,7755 ****
}
else
i = curwin->w_leftcol;
! /* Go to the middle of the screen line. When 'number' is on and lines
! * are wrapping the middle can be more to the left.*/
if (cap->nchar == 'm')
i += (W_WIDTH(curwin) - curwin_col_off()
+ ((curwin->w_p_wrap && i > 0)
--- 7748,7756 ----
}
else
i = curwin->w_leftcol;
! /* Go to the middle of the screen line. When 'number' or
! * 'relativenumber' is on and lines are wrapping the middle can be more
! * to the left.*/
if (cap->nchar == 'm')
i += (W_WIDTH(curwin) - curwin_col_off()
+ ((curwin->w_p_wrap && i > 0)
Index: src/option.c
===================================================================
*** src/option.c (revision 908)
--- src/option.c (working copy)
***************
*** 207,212 ****
--- 207,213 ----
# define PV_LBR OPT_WIN(WV_LBR)
#endif
#define PV_NU OPT_WIN(WV_NU)
+ #define PV_RNU OPT_WIN(WV_RNU)
#ifdef FEAT_LINEBREAK
# define PV_NUW OPT_WIN(WV_NUW)
#endif
***************
*** 1998,2003 ****
--- 1999,2007 ----
(char_u *)NULL, PV_NONE,
#endif
{(char_u *)2000L, (char_u *)0L}},
+ {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
+ (char_u *)VAR_WIN, PV_RNU,
+ {(char_u *)FALSE, (char_u *)0L}},
{"remap", NULL, P_BOOL|P_VI_DEF,
(char_u *)&p_remap, PV_NONE,
{(char_u *)TRUE, (char_u *)0L}},
***************
*** 7331,7336 ****
--- 7335,7353 ----
curwin->w_leftcol = 0;
}

+ /* If 'number' is set, reset 'relativenumber'. */
+ else if ((int *)varp == &curwin->w_p_nu)
+ {
+ if (curwin->w_p_nu)
+ curwin->w_p_rnu = FALSE;
+ }
+ /* If 'relativenumber' is set, reset 'number'. */
+ else if ((int *)varp == &curwin->w_p_rnu)
+ {
+ if (curwin->w_p_rnu)
+ curwin->w_p_nu = FALSE;
+ }
+
#ifdef FEAT_WINDOWS
else if ((int *)varp == &p_ea)
{
***************
*** 9039,9044 ****
--- 9056,9062 ----
case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
#endif
case PV_NU: return (char_u *)&(curwin->w_p_nu);
+ case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
#ifdef FEAT_LINEBREAK
case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
#endif
***************
*** 9224,9229 ****
--- 9242,9248 ----
#endif
to->wo_list = from->wo_list;
to->wo_nu = from->wo_nu;
+ to->wo_rnu = from->wo_rnu;
#ifdef FEAT_LINEBREAK
to->wo_nuw = from->wo_nuw;
#endif
Index: src/option.h
===================================================================
*** src/option.h (revision 908)
--- src/option.h (working copy)
***************
*** 1031,1036 ****
--- 1031,1037 ----
, WV_LBR
#endif
, WV_NU
+ , WV_RNU
#ifdef FEAT_LINEBREAK
, WV_NUW
#endif
Index: src/screen.c
===================================================================
*** src/screen.c (revision 908)
--- src/screen.c (working copy)
***************
*** 420,428 ****
check_for_delay(FALSE);

#ifdef FEAT_LINEBREAK
! /* Force redraw when width of 'number' column changes. */
if (curwin->w_redr_type < NOT_VALID
! && curwin->w_nrwidth != (curwin->w_p_nu ? number_width(curwin) : 0))
curwin->w_redr_type = NOT_VALID;
#endif

--- 420,430 ----
check_for_delay(FALSE);

#ifdef FEAT_LINEBREAK
! /* Force redraw when width of 'number' or 'relativenumber' column
! * changes. */
if (curwin->w_redr_type < NOT_VALID
! && curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu)
! ? number_width(curwin) : 0))
curwin->w_redr_type = NOT_VALID;
#endif

***************
*** 861,868 ****
#endif

#ifdef FEAT_LINEBREAK
! /* Force redraw when width of 'number' column changes. */
! i = wp->w_p_nu ? number_width(wp) : 0;
if (wp->w_nrwidth != i)
{
type = NOT_VALID;
--- 863,871 ----
#endif

#ifdef FEAT_LINEBREAK
! /* Force redraw when width of 'number' or 'relativenumber' column
! * changes. */
! i = (wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) : 0;
if (wp->w_nrwidth != i)
{
type = NOT_VALID;
***************
*** 2108,2114 ****
/* Build the fold line:
* 1. Add the cmdwin_type for the command-line window
* 2. Add the 'foldcolumn'
! * 3. Add the 'number' column
* 4. Compose the text
* 5. Add the text
* 6. set highlighting for the Visual area an other text
--- 2111,2117 ----
/* Build the fold line:
* 1. Add the cmdwin_type for the command-line window
* 2. Add the 'foldcolumn'
! * 3. Add the 'number' or 'relativenumber' column
* 4. Compose the text
* 5. Add the text
* 6. set highlighting for the Visual area an other text
***************
*** 2170,2176 ****
ScreenAttrs[off + (p) + ri] = v
#endif

! /* Set all attributes of the 'number' column and the text */
RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col);

#ifdef FEAT_SIGNS
--- 2173,2180 ----
ScreenAttrs[off + (p) + ri] = v
#endif

! /* Set all attributes of the 'number' or 'relativenumber' column and the
! * text */
RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col);

#ifdef FEAT_SIGNS
***************
*** 2196,2213 ****
#endif

/*
! * 3. Add the 'number' column
*/
! if (wp->w_p_nu)
{
len = W_WIDTH(wp) - col;
if (len > 0)
{
int w = number_width(wp);

if (len > w + 1)
len = w + 1;
! sprintf((char *)buf, "%*ld ", w, (long)lnum);
#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
/* the line number isn't reversed */
--- 2200,2226 ----
#endif

/*
! * 3. Add the 'number' or 'relativenumber' column
*/
! if (wp->w_p_nu || wp->w_p_rnu)
{
len = W_WIDTH(wp) - col;
if (len > 0)
{
int w = number_width(wp);
+ long num;

if (len > w + 1)
len = w + 1;
!
! if (wp->w_p_nu)
! /* 'number' */
! num = (long)lnum;
! else
! /* 'relativenumber', don't use negative numbers */
! num = (long)abs((int)get_cursor_rel_lnum(wp, lnum));
!
! sprintf((char *)buf, "%*ld ", w, (long)num);
#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
/* the line number isn't reversed */
***************
*** 3287,3295 ****
if (draw_state == WL_NR - 1 && n_extra == 0)
{
draw_state = WL_NR;
! /* Display the line number. After the first fill with blanks
! * when the 'n' flag isn't in 'cpo' */
! if (wp->w_p_nu
&& (row == startrow
#ifdef FEAT_DIFF
+ filler_lines
--- 3300,3308 ----
if (draw_state == WL_NR - 1 && n_extra == 0)
{
draw_state = WL_NR;
! /* Display the absolute or relative line number. After the
! * first fill with blanks when the 'n' flag isn't in 'cpo' */
! if ((wp->w_p_nu || wp->w_p_rnu)
&& (row == startrow
#ifdef FEAT_DIFF
+ filler_lines
***************
*** 3303,3310 ****
#endif
)
{
sprintf((char *)extra, "%*ld ",
! number_width(wp), (long)lnum);
if (wp->w_skipcol > 0)
for (p_extra = extra; *p_extra == ' '; ++p_extra)
*p_extra = '-';
--- 3316,3333 ----
#endif
)
{
+ long num;
+
+ if (wp->w_p_nu)
+ /* 'number' */
+ num = (long)lnum;
+ else
+ /* 'relativenumber', don't use negative numbers */
+ num = (long)abs((int)get_cursor_rel_lnum(wp,
+ lnum));
+
sprintf((char *)extra, "%*ld ",
! number_width(wp), num);
if (wp->w_skipcol > 0)
for (p_extra = extra; *p_extra == ' '; ++p_extra)
*p_extra = '-';
***************
*** 4652,4658 ****
else
--n_skip;

! /* Only advance the "vcol" when after the 'number' column. */
if (draw_state >= WL_SBR
#ifdef FEAT_DIFF
&& filler_todo <= 0
--- 4675,4682 ----
else
--n_skip;

! /* Only advance the "vcol" when after the 'number' or 'relativenumber'
! * column. */
if (draw_state >= WL_SBR
#ifdef FEAT_DIFF
&& filler_todo <= 0
***************
*** 9567,9574 ****

#if defined(FEAT_LINEBREAK) || defined(PROTO)
/*
! * Return the width of the 'number' column.
! * Caller may need to check if 'number' is set.
* Otherwise it depends on 'numberwidth' and the line count.
*/
int
--- 9591,9598 ----

#if defined(FEAT_LINEBREAK) || defined(PROTO)
/*
! * Return the width of the 'number' and 'relativenumber' column.
! * Caller may need to check if 'number' or 'relativenumber' is set.
* Otherwise it depends on 'numberwidth' and the line count.
*/
int
***************
*** 9578,9584 ****
int n;
linenr_T lnum;

! lnum = wp->w_buffer->b_ml.ml_line_count;
if (lnum == wp->w_nrwidth_line_count)
return wp->w_nrwidth_width;
wp->w_nrwidth_line_count = lnum;
--- 9602,9614 ----
int n;
linenr_T lnum;

! if (wp->w_p_nu)
! /* 'numer' */
! lnum = wp->w_buffer->b_ml.ml_line_count;
! else
! /* 'relativenumber' */
! lnum = wp->w_height;
!
if (lnum == wp->w_nrwidth_line_count)
return wp->w_nrwidth_width;
wp->w_nrwidth_line_count = lnum;
Index: src/structs.h
===================================================================
*** src/structs.h (revision 908)
--- src/structs.h (working copy)
***************
*** 169,174 ****
--- 169,176 ----
#define w_p_list w_onebuf_opt.wo_list /* 'list' */
int wo_nu;
#define w_p_nu w_onebuf_opt.wo_nu /* 'number' */
+ int wo_rnu;
+ #define w_p_rnu w_onebuf_opt.wo_rnu /* 'relativenumber' */
#ifdef FEAT_LINEBREAK
long wo_nuw;
# define w_p_nuw w_onebuf_opt.wo_nuw /* 'numberwidth' */
***************
*** 1885,1891 ****
recomputed */
#endif
#ifdef FEAT_LINEBREAK
! int w_nrwidth; /* width of 'number' column being used */
#endif

/*
--- 1887,1894 ----
recomputed */
#endif
#ifdef FEAT_LINEBREAK
! int w_nrwidth; /* width of 'number' and 'relativenumber'
! column being used */
#endif

/*

Markus Heidelberg

unread,
Feb 21, 2008, 4:48:35 AM2/21/08
to vim...@googlegroups.com
Am Thursday, 21. February 2008 schrieb Markus Heidelberg:
> Am Wednesday, 13. February 2008 schrieb Nick Gravgaard:
> >
> > Hi everyone,
> >
> > I have an idea which I think will make Vim much faster and easier to
> > use. I find that over 4 lines or so, it becomes difficult to quickly
> > count the number of lines I want to delete/yank/shift or whatever, and
> > so I usually revert to using linewise Visual mode to select the lines I
> > want to perform the operation on. Obviously it's much faster to (for
> > example) press 23d than to press V followed by down 23 times and finally
> > d to delete, but the problem is knowing how many lines I want to perform
> > the operation on. I believe this could be easily rectified if Vim could
> > display relative line numbers in the left hand margin (with the current
> > line being 1, the next being 2, and so on). Then the user could just
> > look down to the last line they want to operate on, see how many lines
> > it is from the cursor, and type the command.
>
> I also thought it could be useful in some cases, so I've just tried it the last
> days. Here's the patch (based on svn revision 908, latest patch 258).
>
> To use it set the new option 'relativenumber' or 'rnu'.
>
> I have implemented 'relativenumber' and 'number' exclusive-or, i.e. setting
> either resets the other. That was more uncomplicated and I don't think many
> people want to display absolute and relative line numbers side by side. It
> would be just too confusing.
>
> :print :list and :number don't use 'relativenumber'.

Hmm, I think I have to configure the mailer.
But I already sent a patch some weeks ago.

Nevertheless, second try as attachement.

Markus

relativenumber.diff

Erik Falor

unread,
Feb 21, 2008, 10:35:44 AM2/21/08
to vim...@googlegroups.com


On 2/21/08, Markus Heidelberg <markus.h...@web.de> wrote:

> To use it set the new option 'relativenumber' or 'rnu'.


Wow.  That is so cool.  :)

Nick Gravgaard

unread,
Feb 21, 2008, 10:43:26 AM2/21/08
to vim...@googlegroups.com
On Thu, 21 Feb 2008 08:35:44 -0700, "Erik Falor" <ewf...@gmail.com>
said:

> On 2/21/08, Markus Heidelberg <markus.h...@web.de> wrote:
> >
> >
> > > To use it set the new option 'relativenumber' or 'rnu'.
> >
> >
> Wow. That is so cool. :)

Damn - I haven't got a build environment set up. I don't suppose anyone
has a Windows executable I could play with?

Nick Gravgaard

unread,
Feb 21, 2008, 12:09:58 PM2/21/08
to vim...@googlegroups.com
On Thu, 21 Feb 2008 10:36:40 +0100, "Markus Heidelberg"
<markus.h...@web.de> said:
> Am Wednesday, 13. February 2008 schrieb Nick Gravgaard:
> >
> > Hi everyone,
> >
> > I have an idea which I think will make Vim much faster and easier to
> > use. I find that over 4 lines or so, it becomes difficult to quickly
> > count the number of lines I want to delete/yank/shift or whatever, and
> > so I usually revert to using linewise Visual mode to select the lines I
> > want to perform the operation on. Obviously it's much faster to (for
> > example) press 23d than to press V followed by down 23 times and finally
> > d to delete, but the problem is knowing how many lines I want to perform
> > the operation on. I believe this could be easily rectified if Vim could
> > display relative line numbers in the left hand margin (with the current
> > line being 1, the next being 2, and so on). Then the user could just
> > look down to the last line they want to operate on, see how many lines
> > it is from the cursor, and type the command.
>
> I also thought it could be useful in some cases, so I've just tried it
> the last
> days. Here's the patch (based on svn revision 908, latest patch 258).
>
> To use it set the new option 'relativenumber' or 'rnu'.

Cool. I've just had a play (thanks for the Windows exe Erik!), and I
like this a lot.

I know it seems a bit strange, but in order that that both 2d- and 2dd
work, shouldn't it look like this instead?

-3 aaaa
-2 bbbb <-- 2d- deletes from the current line to here
-1 cccc
1 dddd <-- current line
2 eeee <-- 2dd deletes from the current line to here
3 ffff
4 gggg

Erik Falor

unread,
Feb 21, 2008, 12:14:55 PM2/21/08
to vim...@googlegroups.com
On 2/21/08, Nick Gravgaard <m...@nickgravgaard.com> wrote:
Cool. I've just had a play (thanks for the Windows exe Erik!), and I
like this a lot.

I know it seems a bit strange, but in order that that both 2d- and 2dd
work, shouldn't it look like this instead?

  -3  aaaa
  -2  bbbb <-- 2d- deletes from the current line to here
  -1  cccc
  1  dddd <-- current line
  2  eeee <-- 2dd deletes from the current line to here
  3  ffff
  4  gggg

The way it stands now, commands like 5j/5k work correctly.

Markus Heidelberg

unread,
Feb 21, 2008, 2:23:53 PM2/21/08
to vim...@googlegroups.com
Am Thursday, 21. February 2008 schrieb Nick Gravgaard:
> I know it seems a bit strange, but in order that that both 2d- and 2dd
> work, shouldn't it look like this instead?
>
> -3 aaaa
> -2 bbbb <-- 2d- deletes from the current line to here
> -1 cccc
> 1 dddd <-- current line
> 2 eeee <-- 2dd deletes from the current line to here
> 3 ffff
> 4 gggg

That's weird. Having zero as base has the advantage, that you can use the
commands in both directions - up and down - the same way. Then use 2dj instead
of 3dd and 2dk works similar in the opposite direction.
Of course then the number doesn't represent the number of lines you want to
delete. But that's not what you want, you just want to have the lines from 0
to the relative line number be deleted. As with movement commands 2j 2k 2+ 2-.

And you cannot compare 2d- with 2dd, you have to compare it with 2d+. Then
again it simply works well with zero-base.

Markus

Nick Gravgaard

unread,
Feb 21, 2008, 2:37:59 PM2/21/08
to vim...@googlegroups.com
On Thu, 21 Feb 2008 20:23:53 +0100, "Markus Heidelberg"
<markus.h...@web.de> said:
>
> Am Thursday, 21. February 2008 schrieb Nick Gravgaard:
> > I know it seems a bit strange, but in order that that both 2d- and 2dd
> > work, shouldn't it look like this instead?
> >
> > -3 aaaa
> > -2 bbbb <-- 2d- deletes from the current line to here
> > -1 cccc
> > 1 dddd <-- current line
> > 2 eeee <-- 2dd deletes from the current line to here
> > 3 ffff
> > 4 gggg
>
> That's weird. Having zero as base has the advantage, that you can use the
> commands in both directions - up and down - the same way. Then use 2dj
> instead
> of 3dd and 2dk works similar in the opposite direction.
> Of course then the number doesn't represent the number of lines you want
> to
> delete. But that's not what you want, you just want to have the lines
> from 0
> to the relative line number be deleted. As with movement commands 2j 2k
> 2+ 2-.

Ah yes, I hadn't thought of the movement commands. I guess I'll have to
get in the habit of adding 1 to the relative line number, or campaign to
have a setting to make the dd, yy and >> style commands count from zero
;)

> And you cannot compare 2d- with 2dd, you have to compare it with 2d+.

Sure, but 2dd is quicker to type than 2d+, and I'm not sure how many
people really use 2d-.

Markus Heidelberg

unread,
Feb 21, 2008, 3:11:27 PM2/21/08
to vim...@googlegroups.com

But how would you delete 2 lines upwards? 1k2dd?
However, it will not be consistent with your downwards command, because there
is no equivalent for 2dd in the other direction.

> > And you cannot compare 2d- with 2dd, you have to compare it with 2d+.
>
> Sure, but 2dd is quicker to type than 2d+, and I'm not sure how many
> people really use 2d-.

I don't. I use 2dj and 2dk, not 2d+ and 2d-.

Nick Gravgaard

unread,
Feb 21, 2008, 3:36:40 PM2/21/08
to vim...@googlegroups.com
On Thu, 21 Feb 2008 21:11:27 +0100, "Markus Heidelberg"

Of course. I'll try training myself to use this instead.

Before I do though, is there any way to script Vim so that dd (for
instance) counts from zero?

Tony Mechelynck

unread,
Feb 21, 2008, 3:46:10 PM2/21/08
to vim...@googlegroups.com

For a precompiled Windows installer (currently 7.1.262), see
https://sourceforge.net/project/showfiles.php?group_id=43866&package_id=39721
-- that's a version with (only) Bram's official patches.

To compile your own, see for example
http://users.skynet.be/antoine.mechelynck/vim/compile.htm which shows the two
compilers I used when I was on Windows. I recommend gcc in preference to
BCC32, the latter (at least on W98) doesn't have all the Unicode functions
needed by gvim with +multi_byte


Best regards,
Tony.
--
Systems have sub-systems and sub-systems have sub-systems and so on ad
infinitum -- which is why we're always starting over.
-- Epigrams in Programming, ACM SIGPLAN Sept. 1982

Andy Wokula

unread,
Feb 22, 2008, 8:52:01 AM2/22/08
to vim...@googlegroups.com
Nick Gravgaard schrieb:

>>>> And you cannot compare 2d- with 2dd, you have to compare it with 2d+.
>>> Sure, but 2dd is quicker to type than 2d+, and I'm not sure how many
>>> people really use 2d-.
>> I don't. I use 2dj and 2dk, not 2d+ and 2d-.
>
> Of course. I'll try training myself to use this instead.
>
> Before I do though, is there any way to script Vim so that dd (for
> instance) counts from zero?

:nnoremap <expr> dd v:count ? "dj" : "dd"

dd -> dd
1dd -> 1dj
2dd -> 2dj

" map more operators this way:
" :h operator
" maps "~" if 'tildeop' set
for opr in split("c d y g~ gu gU ! = gq gw g? > <lt> zf "." ~"[&top])
exec "nn <expr>" opr.opr "v:count ? '".opr."j' : '".opr.opr."'"
echo "nn <expr>" opr.opr "v:count ? '".opr."j' : '".opr.opr."'"
if strlen(opr) == 2
exec "nn <expr>" opr.opr[1] "v:count ? '".opr."j' : '".opr.opr."'"
echo "nn <expr>" opr.opr[1] "v:count ? '".opr."j' : '".opr.opr."'"
endif
endfor
unlet opr

" Side note:
" "zff" doesn't wait for a character, as long as there is no user omap
" for f{char}, like "ff", "fa", etc.

--
Andy

Nick Gravgaard

unread,
Feb 25, 2008, 10:42:15 AM2/25/08
to vim...@googlegroups.com
On Fri, 22 Feb 2008 14:52:01 +0100, "Andy Wokula" <anw...@yahoo.de>
said:
>

Brilliant. Works a treat, thanks!

Erik Falor

unread,
Mar 27, 2008, 12:03:22 PM3/27/08
to vim...@googlegroups.com
Now that we've had this patch for over a month, how does everybody feel about this feature?  

I, for one, use it more than occasionally, and find it to be immensly helpful.  I would like to see this
patch incorporated into th e mainline.  Bram, what are the chances of that happening?

Markus Heidelberg

unread,
Mar 29, 2008, 8:33:48 AM3/29/08
to vim...@googlegroups.com
Erik Falor, 27.03.2008:

> Now that we've had this patch for over a month, how does everybody feel
> about this feature?
>
> I, for one, use it more than
> occasionally, and find it to be immensly helpful. I would like to see this
> patch incorporated into th e mainline. Bram, what are the chances of that
> happening?

Hello Erik

This patch is listed in the todo.txt as a possible candidate for Vim 7.2. The
todo.txt can be obtained from the current runtime files (with aap or rsync).
I currently have the option activated all the time for both testing and using
purposes.

Markus

Tony Mechelynck

unread,
Mar 29, 2008, 10:28:53 AM3/29/08
to vim...@googlegroups.com

The current todo.txt can also be obtained by ":help todo.txt" if you
have an up-to-date installation of Vim (with up-to-date runtime files)
or as http://ftp.vim.org/pub/vim/runtime/doc/todo.txt in any case.

Best regards,
Tony.
--
"We demand rigidly defined areas of doubt and uncertainty!"
-- Vroomfondel

Erik Falor

unread,
Mar 31, 2008, 11:26:02 AM3/31/08
to vim...@googlegroups.com
On 3/29/08, Tony Mechelynck <antoine.m...@gmail.com> wrote:
The current todo.txt can also be obtained by ":help todo.txt" if you
have an up-to-date installation of Vim (with up-to-date runtime files)
or as http://ftp.vim.org/pub/vim/runtime/doc/todo.txt in any case.

Best regards,
Tony.

Thank you Markus and Tony for pointing this out.  I got my runtime files from SVN, which
weren't as up-to-date.  I'll look forward to that as well as the other features slated for 7.2.

Milan Vancura

unread,
Jul 7, 2008, 3:53:14 AM7/7/08
to vim...@googlegroups.com
Markus wrote:
> I have adapted my relativenumber patch to Vim 7.2a, initial version was from
> 21.02.2008. Unfortunately it didn't get into mainline yet.
>
> Short description:
> Set the new option 'relativenumber' or 'rnu' to display relative line numbers.
> With it you can just read the values for [count], that is used in very many
> commands (e.g. j k + - y d c < > gq gw =), without calculating it by yourself.
> This evolves the power of the count mechanism more than ever.

Hi,

I remember Nick Gravgaard already needed such option and I wrote a simple vim
script doing that, with no patch. It is not ideal of course (no events used,
for example - one must press a hot key with this alpha version of the script)
but it shows the problem probably has a solution even using vim script language
only. What do you think?

Milan

P.S.: the old e-mail with the script:

> >
> > Nick Gravgaard <m...@nickgravgaard.com> escrit:


> >
> > > if Vim could display relative line numbers
> > > in the left hand margin (with the current

> > > line being 1, the next being 2, and so on)
> >
> >
> > Yes, this is easy, vim can.
> >
> >
> > This is easy implementable in vimscript
> > using the *SIGNS* (:help signs).
> > Plus, use the CursorMoved autocommand.
> >
> > Learn vim scripting yourself, or ask someone
> > who has vimscript experience to write such script.
> > Couple of hours if you already have experience with
> > vimscript, or several days if it's your first nontrivial vim script.
>
> I've tried it. It's my first attempt to write vim script but it seems it works.
> I hope it helps you, Nick. Feel free to modify it etc.
>
> BTW: Does some experienced vim scripter know how to define a sign with
> text=' 1' (starting with a space)? I wanted to align numbers to the right but I
> failed. None of "escaping" syntaxes worked.
>

> Milan


> --
> Milan Vancura, Prague, Czech Republic, Europe
>
> >

> function! RelLinesInit ()
> sign define l_0 text=-- texthl=Search
> let index=1
> while index<=70
> let sindex = (index < 10 ? "0" : "") . index
> exe "sign define l_" . index . " text=" . sindex . " texthl=Search"
> let index+=1
> endwhile
> endfunction
>
> function! RelLines ()
> call RelLinesClear()
> let lcur=line(".")
> let ltop=line("w0")
> let lbot=line("w$")
> let index=ltop
> while index <= lbot
> let inum=index-lcur
> let anum= inum < 0 ? -inum : inum
> if anum < 70
> exe "sign place " . (70 + inum) . " line=" . index . " name=l_" . anum . " buffer=" . bufnr("%")
> endif
> let index+=1
> endwhile
> endfunction
>
> function! RelLinesClear ()
> let index=0
> while index<=140
> exe "silent sign unplace " . index . " buffer=" . bufnr("%")
> let index+=1
> endwhile
> endfunction
>
> map <silent> <special> <F11> :call RelLines()
>
> map <silent> <special> <F12> :call RelLinesClear()
>
>
> call RelLinesInit()


Markus Heidelberg

unread,
Jul 7, 2008, 1:21:43 PM7/7/08
to vim...@googlegroups.com
Milan Vancura, 07.07.2008:

>
> Markus wrote:
> > I have adapted my relativenumber patch to Vim 7.2a, initial version was from
> > 21.02.2008. Unfortunately it didn't get into mainline yet.
> >
> > Short description:
> > Set the new option 'relativenumber' or 'rnu' to display relative line numbers.
> > With it you can just read the values for [count], that is used in very many
> > commands (e.g. j k + - y d c < > gq gw =), without calculating it by yourself.
> > This evolves the power of the count mechanism more than ever.
>
> Hi,
>
> I remember Nick Gravgaard already needed such option and I wrote a simple vim
> script doing that, with no patch. It is not ideal of course (no events used,
> for example - one must press a hot key with this alpha version of the script)
> but it shows the problem probably has a solution even using vim script language
> only. What do you think?

I think this is a kind of feature, that should just be available as a simple
and efficient :set option. I don't know much about VimScript, but I guess it
could be feasible to implement it without functional drawbacks. But then you
could also implement the 'number' option in VimScript and throw out of the
sources.
Anyway there would still remain the performance issue. And of course the
missing operator convenience of the :set command. So I really think such
features belong into the sources.

Markus

Richard Hartmann

unread,
Jul 8, 2008, 10:26:05 AM7/8/08
to vim...@googlegroups.com
On Mon, Jul 7, 2008 at 19:21, Markus Heidelberg
<markus.h...@web.de> wrote:


> So I really think such
> features belong into the sources.

Agreed, for the reasons you stated. We will have to see if Bram is
willing to accept the patch, at some point. Alternatively, the 'MM tree'
of VIM is something that might be worthwhile to use, if it ever sees the
light of day.


Richard

Reply all
Reply to author
Forward
0 new messages