How to paste clipboard text into vim?

Asked

Viewed 7,285 times

7

Researching the Cheat sheet of some places, I discovered how to see the transfer area (the Registers) no vim, :reg.

saída do console para o comando :reg

However, I could not use these records, even using the commands demonstrated on the websites.


  • How do I paste text from the clipboard?
  • How to 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 Paste simple of vim.

  • How to access other saved texts in the records?

  • Just one remark: the vim logs, and the Yank and Paste operations usually have no relation to the OS Clipboard. For integration see this link http://vim.wikia.com/wiki/Accessing_the_system_clipboard

2 answers

6


How do I paste text from the clipboard?

I usually use the key p to paste after cursor. Shift + p to glue before (or P, capital).

How to select and copy something from vim itself?

Without using graphic resources, the following is used:

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

How to access other saved texts in the records?

First you need to define the records. I will use your examples from print. Anyway, to set a record r, we use " + to. Use next y + y to copy the current line to the record a.

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

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

Remembering that all operations must be done outside the insertion mode to work.


In the insertion mode

The good old Ctrl + V for Windows, click the middle mouse button for Linux and Command + V for Mac paste the clipboard text into Vim.

  • 1

    recalling that in the insertion mode Ctrl + V only obeys line breaks correctly if use :set paste before

  • I usually select text for 2 ways: (1) 'y' + motion keys (arrows, w, b, etc.) and (2) 'v' + motion keys + 'y', which is more versatile: for example, 'v' + 2 times right arrow + 'y' copies 3 characters, which can be pasted with 'p' (purists would probably use hjkl keys as movement keys, but this is unnecessary)

0

If I’ve been using Linux you have an "extra clipboard" called visual Selection, any selection with the mouse puts the selected content in it, to paste this content into the Insert mode do:

Ctrl-r *

Now if copying 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 insert these contents with:

"*p
"+p

To place these contents in the respective "Clipboards", select the desired section and do:

 "*y
 "+y

A common problem with newer vim users is when trying to copy a snippet to overwrite another, when deleting the target content it overwrites what was copied, but not the "zero" record, which contains the last snippet copied.

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

Ctrl-r 0

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

"Add

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

In global mode we can for example add all lines containing the word 'ERROR' to the record a so that we can glue it in gold excerpt or archive of the vim:

:g/ERROR/normal! "Ayy

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

 qaq

The theme can extend a lot because the vim records go beyond, I advise a calm deal on :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' 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.