1

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?

3 Answers 3

3
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.

Sign up to request clarification or add additional context in comments.

Comments

2
:-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.

Comments

1

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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.