4

I often use registers in evil, but I have a common use case that I cannot seem to resolve. I would like to have all copied text stored somewhere that does not get overwritten when I explicitly make another copy to a specific register.


Here is an example:

I want to copy this FIRST line, so I copy it (without explicitly using a register)

I later realize that I want to copy this SECOND line as well, and I want to be able paste it separately from the FIRST line, so I copy it to a register (ie register j via "jVy)

I can easily paste that SECOND line (ie "jp), but how can I paste the FIRST line? The default register is overwritten by my second copy command (ie "*p would paste the SECOND line) and my clipboard stores the SECOND line as well (ie p would paste the SECOND line).

In sum, I don't want to explicitly use a register for all of my copy commands - that is too tedious. Is there a "default" register that I can use that is not overwritten when I copy to a specific register? Perhaps I can bind all copy commands to a specific register?

UPDATE

I prefer a solution that uses pure vim/evil commands, so that it is extensible for my other vim editors and vim plugins (ie JetBrains' idea-vim). I found my solution by using the 0 register. In my example above, I can paste the FIRST line by running "0p.

In hindsight, I think this solution would have been better suited for a vim-related forum, but I hope it proves helpful for other Evil-mode users.

5

Simply use the kill ring. In evil, your simplest option is to use evil-paste-pop, bound by default to C-p. Here's the docstring:

Replace the just-yanked stretch of killed text with a different stretch. This command is allowed only immediatly after a yank, evil-paste-before, evil-paste-after or evil-paste-pop. This command uses the same paste command as before, i.e., when used after evil-paste-after the new text is also yanked using evil-paste-after, used with the same paste-count argument.

So:

  1. Copy the first line (yy).
  2. Copy the second line into your register ("jyy)
  3. Paste (p), which pastes the second line.
  4. Cycle through the kill ring with C-p, which will switch out your first paste (the second line) with the previous line you copied.
  • thanks for you answer, the kill ring seems very useful. In this case, I prefer a solution that keeps with the vim registers and vim keybindings. Although my questions is probably for vim than emacs related, I hope future evil-users can benefit from this post and decide which solution is most beneficial for them. – modulitos May 9 '15 at 23:30
  • FYI, the kill ring is sufficiently useful that someone ported it to Vim as the yank ring. – Dan May 9 '15 at 23:47
2

I found a solution, which sticks to using the vim registers:

Just use the 0 register. In my example above, I can paste the FIRST line by running "0p.

Dan's kill-ring answer is also very helpful, and may be preferable for some. I prefer using the 0 register above because it keeps consistent with pure vim keybindings, which allows me to use it across other editors that support vim keybindings.

I also prefer to explicitly paste my first copy with one command, instead of cycling through all of my yanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.