Paste multiple times

What is the best way to replace multiple lines with clipboard content?

The problem I am facing is that when I hold a line and paste it on top of another line, the β€œYankees” are replaced by a line that I just replace. Now, if I want to replace another row with the same row, I have to go back and pull it again.

There must be a better way to do this.

+58
vim copy paste
Aug 23 '11 at 15:58
source share
6 answers

I have this in my .vimrc:

xnoremap p pgvy 

(note: this will only work with the default case, but this mapping is easy to remember). Writing a more complex version would be possible. Alternatively, you can still use P to get old behavior.

+74
Aug 23 '11 at 16:10
source share

"0 should have the contents of your yank. It's a little more tedious for input, but "0p should do what you want.

Alternatively, do not select or replace old lines in front. If you find these search strings, just press n. over and over (after the initial p ), then when they are all inserted, do ndd and then as many n. as possible n. .

The biggest mental switch I need to make when you move to Vim is to figure out how to apply group changes sequentially. That is, instead of doing a bunch of edits on the line, and then doing a bunch of the same changes on another line, I will do the first edit on a bunch of lines (with a lot of use of the effect . ), Then the second edit on many lines, etc. . Alternatively, using macros can help because they are fantastic, but sometimes a little more tedious to work correctly with "complex" changes.

+17
Aug 23 '11 at 17:20
source share

When pasted over a selection in Vim, it will replace the default case with the contents of the selection. If pasting over the selection deletes the contents of the clipboard register, then most likely you have the following line in your .vimrc

 set clipboard=unnamed 

One option is to delete this and use the explicit clipboard register "+

Another option is to use any of the other explicitly named registers (az). After the first paste returns the string back to "c , then use "cp to paste from there.

+11
Aug 23 '11 at 16:03
source share

I often use a different registry, copy the line needed for some named registry "ay , and then paste from there "ap

+11
Aug 23 '11 at 16:15
source share

use np , where n is the amount of time you want to insert rows, for example 3p will insert 3 rows.

+6
Aug 23 2018-11-21T00:
source share

Instead of using copy / paste, it is often better to use a text object command such as ciw to change the inner word. The advantage of this method is that it can be easily reproduced with the command . repeat.

  • yiw Yan is the inner word (copy the word under the cursor, say "first").
  • ... Move the cursor to another word (for example, "second").
  • ciw<Cr>0 Change "second" to replace it with "first" (this is Ctrl-R).
  • ... Move the cursor to another word (for example, "third").
  • . Change the "third" to replace it with "first."
+1
Aug 24 '17 at 7:29 on
source share



All Articles