views:

172

answers:

2

Community Wiki

As the documentation of the yank system shows (thanks Michal), The Vim yank system seems to be more intricate then a standard clipboard. I therefore think it beneficial if vim veterans could perhaps show us some different styles of making use of this mechanism. particularly with the usage of vim for complicated projects without the use of a heavyweight IDE (say C++ ?).

Original Question

Now that I am using vim for everything I type, rather then just for configuring servers, I wan't to sort out the following trivialities. I tried to formulate Google search queries but the results didn't address my questions :D.

Question one: How do I yank and replace multiple times ?

Once I have something in the yank history (if that is what its called) and then highlight and use the 'p' char in command mode the replaced text is put at the front of the yank history; therefore subsequent replace operations do not use the the text I intended. I imagine this to be a usefull feature under certain circumstances but I do not have a need for it in my workflow.

Question two: How do I type text without causing the line to ripple forward ?

I use hard-tab stops to allign my code in a certain way -- e.g.,

FunctionNameX     ( lala * land               );
FunctionNameProto (                           );

When I figure out what needs to go into the second function, how do I insert it without move the text up ?

Question three Is there a way of having a uniform yank history across gvim instances on the same machine ? I have > 1 monitors. Just wondering, atm I am using highlight + mouse middle click.

+3  A: 

Answer one: A relevant, if not particularly encouraging, qoute from the Vim docs (see :help put-Visual-mode):

When using a put command like |p| or |P| in Visual mode, Vim will try to replace the selected text with the contents of the register. Whether this works well depends on the type of selection and the type of the text in the register. With blockwise selection it also depends on the size of the block and whether the corners are on an existing character. (Implementation detail: it actually works by first putting the register after the selection and then deleting the selection.)
The previously selected text is put in the unnamed register. If you want to put the same text into a Visual selection several times you need to use another register. E.g., yank the text to copy, Visually select the text to replace and use "0p . You can repeat this as many times as you like, the unnamed register will be changed each time.

Answer two: R (the capital 'R') puts you in replace mode.

I'm missing answer three, I'm afraid.

Answer three: Not quite matching the "uniform yank history" spec, but "+y yanks to clipboard and "+p pastes from clipboard if a clipboard is available.

Michał Marczyk
Thank you for both answers, I am reading the documentation now. I didn't even realize that the concept of "registers" was available. I might find a way to benefit from it :D
Hassan Syed
It just occurred to me that you can use "+y for yank to clipboard and "+p for paste from clipboard when your environment provides this sort of functionality (and most likely it does). Does this solve your third issue?
Michał Marczyk
Yes indeed it does, thank you Michal. Especially for the reference to the put documentation. It will aid me immensely.
Hassan Syed
You're welcome. I'll edit in the third answer now.
Michał Marczyk
+3  A: 

Yank into a buffer

:y b

yanks into buffer b

And

:p b 

places it.

I think there are more named buffers available.

RdM
Yes indeed, a-z for programmer use, and 0-9 used by the "clipboard" like mechanism. as yanking goes on the elements in 0-9 ripple forward and the elements on the tail start dropping off, as you yank . +1 as it is a quick and dirty answer for people who do not want to read the documentation :D
Hassan Syed