Reputation: 9986
I'd like to replace current string line with another (for example the another line is placed in 5 lines above current line). I can do it with a pair of commands
dd
:-5t-1
Is there the shorter way to obtain same goal?
Upvotes: 1
Views: 141
Reputation: 172510
If you don't mind a plugin, my LineJuggler plugin offers a ]r
command (and many more):
]r Fetch the line [count] visible lines above the current line and replace the current line with it.
With it, your example would be the short and easy 5]r
In addition, the companion LineJugglerCommands plugin now offers a similar :Replace
Ex command. Again, your example would be
:Replace -5
Upvotes: 1
Reputation: 196456
dd
:-5t-1
is already pretty short if you ask me. But you can squeeze everything into a one-liner:
:d|-5t-1
and remove the 1
because it's implied by -
:
:d|-5t-
Barring making a custom command or mapping I don't see how you could make it shorter.
Upvotes: 3
Reputation: 195029
:-5y<CR>Vp
is it shorter?
if you need do that really often, add this into your vimrc:
command! -range R d|<line1>,<line2>t-
then you can just do :-5R
replace current line with -5
line
or 2,4R
to cp line 2-4 (3 lines) to current line, and replace current line.
Upvotes: 2