VIM: add to clipboard

I can copy to the clipboard, but how to add to the clipboard?

pe I use this in my code
let @+ = my_expression

but it overwrites the clipboard.

I know that I can use az register to add in
possible error let @B = my_expression
add to register b

but what to do when I want to add to the clipboard?

+8
vim append clipboard copy
source share
2 answers

using:

 let @+ = @+ . my_expression 

or shorter:

 let @+ .= my_expression 

Link:: :help :let.=

+13
source share

If you are not using macro photography, it’s probably worth checking out the recorders as well. :help registers was mind blowing.

In simplified form, there are 26 additional “custom clipboards” called registers, where you can store text, starting with a and going through z . You add text to the register in command mode by pressing " , naming the register (say f ), and then typing in the" motion "you want to select, text.

Copy with case (cursor in [T]):

Source File Status

 This is my first line. [T]his is my second line. This is my third line. 

Type "fyy in command mode to fill the register with one line ( yy ). Type p (* see below) to paste it immediately. Thus, the result of entering "fyyp exactly the same as yyp using the default clipboard .

Result

 This is my first line. This is my second line. [T]his is my second line. This is my third line. 

Adding to the register:

Use an uppercase letter to add to an existing case. In the above example, after pasting, press j to go through the line and then "fyy . Then enter p to insert. You have added . This is my third line.” To f content.

Result

 This is my first line. This is my second line. This is my second line. This is my third line. This is my second line. [T]his is my third line. 

(Using lowercase f , he would clear the contents of f and leave it only by holding "This is my third line.")

I did not find a way to add to the default register, so you are stuck with a few extra keystrokes while accessing the “named” registers, but with a little work, this is an easy way to add to the “clipboard” on the fly.

  • Why does p insert what is in register f right after you pulled in f ? Since your default case contains the last choice and apparently does not just hold on to what you added to f , but it extracts everything in f when added. In the first case, it may be more expressive: "the result of entering "fyy"fp exactly the same as yyp using the default clipboard."
+8
source share

All Articles