Wednesday, May 29, 2013

Re: Why use relative line numbers?

On Wednesday, May 29, 2013 3:29:59 PM UTC-5, Chris Lott wrote:
> The discussion about relative line numbers raises the question (for
> me): why use relative line numbers at all?
>
> The main reason I keep reading is that instead of having to calculate
> how many lines one wants to move and then use, say, 5j to move there
> (or pressing j five times, yuck), one can immediately see that the
> desired line is 5 lines away.
>

Yes, also it's useful for things like 5dd (or d4j if you want no math at all).

> But if I am on line 7 and see something on another line, I can just
> use 12gg or 12G to get there.

It's more distracting if you get to 4 or more digits in the absolute line
number. I'd much rather do 3j than 54892G. And sometimes the linewise G/gg
command doesn't work for what I want anyway (but I can't think of any specific
examples).

> And if I have relative numbering on, it
> messes with specifying ranges (as far as I can tell). Does relative
> numbering offer other efficiencies?
>

You can use relative line numbers in ranges, so no problems there. E.g. replace
"foo" with "bar" from here to 5 lines down:

:.,.+5s/foo/bar/g

You can technically omit the . in most cases for efficiency but it's clearer
with in my opinion.

Some commands only work with relative numbers. For example, _ is mostly
synonymous with ^, but you can give it a count to also move to a different line
(at the beginning of the line). This count is (mostly) relative.

Other commands like J which take a count referring to number of lines, but don't
take motions at all, are more efficient with relative line numbering.

One unexpected use that I found is that Vim error messages give a line number
relative to the beginning of a function when a function throws the error.
Instead of counting lines I can cursor to the top of the function and see
exactly which line is at fault.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: