- relative numbers are just another tool in the toolbox
- they can be effective in terms of locality when a text-object doesn't cut it
(and for the lazy-minded among us)
- they pair nicely with commands that take ranges
- but they aren't the "be-all/end-all" of navigating and editing text
One thing to keep in mind is that
'relativenumber' are orthogonal. This means that both have uses, depending
on what the situation calls for.
Example 1: not using relative number
For jumping to the top for python imports, yes,
gg and then
<C-o> are the
easiest and most natural. (I'm not sure I really do anything else.)
Example 2: relative number when needed
When deleting a chunk of lines, text-objects are often a great way to go (
dii get heavy use, where
ii comes from
indent-object). Every now
and then, there's not one that's suitable, and so operation with a
relative-number is convenient.
Why? Well, relative numbers are generally 2-digits or less (my screen has about
45 lines total, and most text that needs edited near the cursor is, well, near
it). Line number can be quite a bit larger. This makes them easier to type.
It's similar to the classic idea of locality: benefit from having quick access
to nearby objects. (I happen to rarely use relative numbers greater than 9:
usually a text-object works at that point, and I'm too lazy to type counts with
more than a single digit, unless it's
999@@ or something: repeated digits are
But at the end of the day, either relative number or absolute numbering will
Example 3: getting more out of :
Another use case of relative numbers is
:-ranges: I find that many vim users
don't use Ex commands to their fullest extent (
:w are enough
for most people, especially with unimpaired making
:cn, and more, easily
accessible in normal mode). This isn't a critique of that way of using vim! But
it does mean that there is a significant part of the tool that's hidden behind
A couple of quick commands that I like:
:t) copies a range of lines to a target.
fantastically easy with relative number, compared to (e.g.)
p have line-wise analogues
:pu). It's pretty easy to grab text with
:+4y, wipe the file
:%d (not even relative numbers!), etc.
Both of these have the advantage of not moving the cursor! But they are
line-wise, so they don't work if you wanted a partial line—unless you're willing
to do some local editing after!
Generally, any command that takes a range is shorter to enter using relative
numbers unless your file is extremely short.
Example 4: avoiding absolute numbers when not needed
Error messages often contain absolute line numbers, and that's the only thing I
can think of that really use them. (Occasionally when discussing code with a
peer, they make a handy reference point: "see over here on line xxx." But then I
often jump there and highlight the text I'm talking about.)
And for error messages, the quickfix list and other features make avoiding
typing numbers possible. (I'd rather edit text that's structured by more than
lines (see ex. 2).)
If you use
k, you would have to find where you were (which isn't always
within view) and look at the number in the column, and go back there.
This is what I mean when I say they are orthogonal: the use-case of
relative-number is generally for things that are in view!
For things that aren't nearby, another technique is often better-suited.
But every now and then, relative number shines.