In vim, is there a more elegant way to jump to a line number under the cursor than
map gn "nyw@nG
"gn" or some other key combo? This necessitates ensuring the cursor is at the beginning of the string of numbers. Also, this macro COULD be a bit hazardous depending on what's in register "n".
Not entirely sure even why this works: @n
means to execute what's in register n (a number), not concatenate it with the "G".
Functions with something like
call cursor(expand("<cword>"),1)
don't seem to work either.
Thoughts?
I would recommend this:
It fixes a lot of the problems you have mentioned, for example:
Using
yiw
instead ofyw
fixes this problem. Read up on text objects!This will only execute any code if your cursor is over a number. Otherwise it does nothing.
There are also some other advantages:
Using
nnoremap
instead ofmap
is the best practice. It will save you a lot of headaches down the road! (more info)It doesn't mess with your
@n
register.Typing
@n
inserts the text inside the register n into the typeahead buffer, exactly as if you had typed it. So if a command is unfinished, it will sit there (as if you had typed it) waiting for the command to finish. You could even run a macro likewhich will sit there waiting for a motion, before deleting three of those motions.