I often want to copy a line and replace another line with the pasted copy. Is there a better way than Y on source line, go to the line that has to be replaced and Pjdd?

  • pkdd ? (It's one keypress less for the Shift) – yo' Feb 3 '15 at 19:04
  • that would be pkdd :) – Jasper Feb 3 '15 at 19:08
  • What did you say? :p – yo' Feb 3 '15 at 19:09
  • That's "register", not "buffer". – romainl Feb 3 '15 at 21:11

You can go to the source line, yank it with yy or Y, go back to the target line, and press Vp (select the line with a visual selection, and replace the visual selection with the previously yanked line).

  • For me, Y also yanks the whole line. Is this nonstandard? I usually prefer Y over yy. There is a difference however between D and dd. – Jasper Feb 3 '15 at 18:55
  • @Jasper Oh, sorry, answering from mobile and don't have an actual Vim instance to test. Edited. – Doorknob Feb 3 '15 at 19:00
  • @Jasper Y and yy are synonymous...per :h Y – jecxjo Apr 28 '16 at 19:09

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.