tags:

views:

293

answers:

5

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.

A: 

I don't know how to do that on Windows. With KDE, the clipboard has a history that you can select from, so you could do the paste, select the previous selection from the clipboard, and paste in the new location.

That said, it sounds like it might make more sense for you to have it in only one location, then write a script to take that input and create the output you need. Can you elaborate more on what it is you are trying to accomplish?

retracile
I'm trying to copy a line from a different application and paste it in two places in vim. As simple as it gets.
Mosh
That's the mechanics of it, yes. I'm asking if you should step back and think about the task you are trying to achieve -- is there a better approach that doesn't involve repetitious cut-n-paste?
retracile
I'm at lost. There's a piece of text I need to paste in two different places, any ideas?
Mosh
+1  A: 

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.

too much php
A: 

Check the value of the 'guioptions' options. Make sure the 'a' flag is not set. Also, check that the 'clipboard' option and verify that neither the 'unnamed' or 'autoselect' flags are set.

:set go-=a
:set clipboard-=unnamed
Steve K
Thank you for your answer, but I can't seem to implement it right. Again, my work sequence is copy on external program, mark text to be replaced on Vim paste over it. Mark another bit of text in Vim and then I'm unable to paste the copied text. I tried pasting with "+p, but I got the same results. Did I get your answer wrong? (I use clipboard=unnamed).
Mosh
So I installed Vim on my laptop and checked my first answer, it doesn't work. I edited my answer with a new suggestion. I'm guessing it's the presence of the 'unnamed' flag causing you trouble.
Steve K
A: 

I don't know if I misunderstand you but I tried what you are doing and I have no problem in doing that with the + drop-register.

My workflow:

  1. copy a sentence in an external application (ie. browser)
  2. visual select a sentence in vim and replaced it with "+p or p (with clipboard=unnamed set)
  3. visually select another sentence and replace it with "+p

Sadly when pasting the second time you have to explicitly paste from the + register. Therefore I would recommend a mapping for p/P instead of using clipboard=unnamed

nmap p "+p

Try using

:registers

to see the contents of the different registers.

kongo2002
Thank you for your answer. I'm working on a Windows machine, so when I check the :registers, I don't have the + register. Also, no register contains the text I copied from the external application (Not even the * register, which is overwritten with the text I copied upon).
Mosh
+1  A: 

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.
exclipy