4 ms·
A question for the Vim experts. How do I do the below in Vim? I yank a text and then visually select another text and copy the yanked text over the selected tex
by barfoomoo 16y ago
A question for the Vim experts. How do I do the below in Vim? I yank a text and then visually select another text and copy the yanked text over the selected text. Once I do this, if I try to visually select another text and copy the previously yanked text over it, it does not work. How does one do this with Vim?
- rlpb 16y agoIf I understand your problem correctly, you want to use registers. Say you yank a text visually by using V, the arrow keys, and then y. Instead, use V, the arrow keys, then "ay That stores the yanked text into the "a" register. When you put, instead of just p, use "ap That puts from the "a" register, and you can repeat the action since the register is never overwritten unless you tell it to. You can also use b through to z to store other things. The same registers can also be used to store macros and marks. Usually you use the default register (I think it's ") and this register also gets various stuff saved to it automatically (eg. stuff you delete). (This is how stuff like xp to swap the current and next character works)
- barfoomoo 16y agoThanks for that suggestion. Any idea why Vim behaves like this? Say I visually select something and yank it and then go on pressing p it pastes the yanked text any no of times. But, if I select a text and then try to replace it with the yanked text, I can do it only once. The next time, the yanked text seems to be removed from the register. Why this difference in behavior?
- mileszs 16y agoWhen you select some text and 'put' over it, Vim yanks the selected text into the default register. The text that you just put is still put-able via "2p, if you'd like to put it again. Vim is essentially saving that selected text for you, just in case. I hope that answers your question.
- pyre 16y ago> That puts from the "a" register, and you can repeat > the action since the register is never overwritten > unless you tell it to. You can also use b through > to z to store other things. The '+' register is used to interface with the X11 (or Windows) clipboard. Example: "+P Paste from clipboard "+y Yank to clipboard "+gP Paste from clipboard, move cursor to end of pasted text
- graywh 16y agoUse "0 before put/paste in visual mode to specify register 0, which always contains the last yank.