How to paste text from clipboard into vim?

6
Searching the cheat sheet of some places, I discovered how to see the clipboard (the registers ) in vim, :reg .

However, I was not able to use these records, even using the commands displayed on the sites.

  • How do I paste text from the clipboard?
  • How do you select and copy something from vim itself?

  

EDIT - > Texts copied from other programs appear in the list of records as a fourth item , and end up not being accessible by the simple paste of vim.   

  • How to access the other texts saved in the records?

    
asked by anonymous 05.04.2017 / 21:41

2 answers

5
  

How do I paste a text from the clipboard?

I usually use the p key to paste past the cursor. Shift + p to paste before (or still P , upper case).

  

How do you select and copy something from vim itself?

Without using graphics, use the following:

  • y + y copies the cursor line;
  • y + number + arrow copies number lines in the direction of the arrow. If it is up, copy the number lines above. Down, the number lines below.
  

How do I access the other texts saved in the records?

First you need to define the records. I'll use your print examples. However, to define a r register, we use " and to . > to copy the current line to the a registry.

To concatenate an existing value in a , use " + A (yes, uppercase).

To paste the contents of the a registry, use " + to + p .

Remembering that all operations must be done outside of insert mode to work.

In insert mode

for Mac paste the text from the Clipboard into Vim.

    
05.04.2017 / 21:54
0

If you have been using Linux you have an "additional clipboard" called visual selection, any selection with the mouse places the selected content in it, to paste this content in insert mode do

Ctrl-r *

Now if you copy in the browser for example using Ctrl-c the content also goes to the default Clipboard, in insert mode insert this content with:

Ctrl-r +

In normal mode you can enter these contents with:

"*p
"+p

To paste these contents into the respective "Transfer areas", select the desired section and do:

 "*y
 "+y

A common problem for novice vim users is when you try to copy one excerpt to overwrite another, by deleting the destination content it overwrites what has been copied but not the 0 "zero" record, which contains the last excerpt copied.

To paste what was copied over a passage that has just been deleted do: (in Insert Mode)

Ctrl-r 0

Finally you can copy from ourto vim file or even a different snippet from the same file to records ranging from 'a' to 'z'. Type, select an excerpt and type "ay , or delete a line by adding its contents to the a register, do:

"Add

When using a capital letter, vim "adds" the content to the record without overwriting it.

In global mode we can for example add all rows containing the word 'ERROR' to the a registry so that we can paste it into gold snippet or vim file:

:g/ERROR/normal! "Ayy

To ensure you must clean the contents of the 'a' record by doing

 qaq

The theme can be extended a lot because the vim records go further, I advise one to deal calmly with :h registers . but follow some pearls:

Ctrl-r / .................. insere a última busca (Modo Insert)
Ctrl-r : .................. insere o último comando
Ctrl-r % .................. insere o nome do arquivo
:put a  ................... insere o conteúdo do registro 'a' 
    
30.08.2017 / 15:24