0

Suppose you have 5 lines in current buffer among others. You yank them using 5Y, make a new buffer with e.g. tabe, and try to paste these 5 lines so that they are the only thing the new buffer would consist of. Yet if you use p, you get an empty line before the lines pasted. If you use P, you get an empty line after them.

Is there any way to paste without introducing extra lines and without doing fix-ups like k"_dd after p?

3

Yes there is! I do this all the time:

Vp

or

VP

If you paste in visual mode, the visual selection is replaced with the contents of the register, so you end up replacing an empty line with what you wanted, and get no extra line. The only downside to this approach is that it will empty out your register, so you'll have to re-yank if you want to paste it several times.

  • 1
    Or yank to a dedicated register (IIRC its only the " register thats overwritten in a visual paste, right? Or is it the register pasted from?) – D. Ben Knoble May 1 at 14:51
  • 1
    @D.BenKnoble Oh, that's a good point. It's just the " register, not the one pasted from. – DJMcMayhem May 1 at 14:55
  • Hmm, doesn't empty out mine. I must have changed something in my paste settings... – Ruslan May 1 at 15:17
  • 1
    @Ruslan technically the contents of the " register should be replaced by the selected text. Ive seen people create visual-mode mappings to avoid this though – D. Ben Knoble May 1 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.