Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy and paste from external source

Tags:

vim

I use vim (Actually gvim on windows) as my main text editor. In my work flow I have to copy sentences to/from various external sources, therefore I use clipboard=unnamed to save me key strokes (p instead of "*p).
I copy text from an outer source and I want to paste it over two different places in vim. I mark the first one (v) and then use p to paste over it. The problem is that at this point I lose the original buffer and can't paste it in the second place. It does not exist in the unnamed buffer, the * buffer or the numbered buffers. My guess is that pasting over selection is putting the "pasted over" text in the unnamed buffer.
How can I paste my original string in two locations? i.e. prevent it from getting lost from the buffers.

Thanks.

like image 647
Mosh Avatar asked Oct 13 '09 19:10

Mosh


People also ask

How do I copy from a source?

Copying and pasting text From the source document or webpage, copy the text to your clipboard. You can copy and paste text using Ctrl+C/Ctrl+V in Windows and Cmd+C/Cmd+V in Mac OS X. You can also use the right-click context menu.

How do I copy and paste external data in Excel?

Simply highlight the text you want to want to copy from the internet and type Ctrl+C to copy it into your clipboard. Then use the Ctrl+V command to paste the text into a cell of your choosing in your Excel spreadsheet. The pasted text will retain the formatting from the website.

How do you copy and paste information from a website?

Reviewing or editing in browserPress Ctrl+C to copy, Ctrl+X to cut, or Ctrl+V to paste the text or picture (Windows); or press ⌘+C, ⌘+X, or ⌘+V (Mac). On Chrome, Firefox, and Chromium-based Edge, you can also use Ctrl+Shift+V and ⌘+Shift+V to paste text only (pastes text without source formatting).

How do I copy and paste from anywhere?

Use Ctrl + C to copy something, then Ctrl + V to paste. If you want to cut instead of copying, use Ctrl + X. To paste the copied text, use the arrow keys or mouse to put the cursor where you want to insert the copied item and press Ctrl + V.


2 Answers

Try this:

:vmap p "_xP
  • vmap means to make a mapping that only applies in visual mode.
  • p is the key to create the mapping for.
  • "_ is the black hole register. This is used in any situation where you want to delete text without affecting any registers.
  • xP means delete the selected text, then paste before the resulting cursor position.
like image 66
exclipy Avatar answered Oct 04 '22 19:10

exclipy


You could set up a mapping to ease your pain:

:vmap <F5> "zxP

This will delete the visually selected text, but put it in a different register, so the clipboard isn't affected. Change <F5> to whatever is easiest for you.

like image 34
too much php Avatar answered Oct 04 '22 20:10

too much php