Background: I am editing a reStructuredText table in vim. I would like to yank a line and paste it. The line only contains cell vertical delimiters (|
) so this operation corresponds to giving an existing row one more line of space in the source, but doesn't alone affect the output. A simple yyP
or yyp
, puts the cursor to column 1 after the operation.
Q: Is there an easy way to "yank and paste a line" and keep the cursor in the same column after the operation as before it?
After I wrote the question, it dawned on me to use a mark, and indeed that works: I can do mayyP
and then `a
to jump back to the desired column. That's a bit long though. So the question is, can I do this with less keystrokes?
Edit: As Shahbaz rightly points out, I can just write an alias, now I know how to do what I want. I am still interested in any shorter way that uses standard commands, in case I am missing some functionality that I should know about.
As @romainl says, you should :set nostartofline
(or :set nosol
for short). Then, instead of yyp
, use the :copy
command:
:copy .
:copy -
If :copy
is too long, you can use :co
or :t
. If you do not use any ex commands in between, then you can repeat the command with @:
and then with @@
.
:help :copy
:help @:
:help @
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With