1

I'm using neovim 0.8.2

Is there a way to automatically mirror last yanked text to system clipboard, regardless of which register I used to yank it to? So if I run something like "ayiw I will have it yanked both to a register and to +?

I was thinking of utilizing TextYankPost autocommand to set let @+ = @... to the content of last used register, but how do I get the name of the last used register?

1 Answer 1

3

I believe you could achieve that with:

set clipboard=unnamedplus

More information about unnamedplus with :help unnamedplus

A variant of the "unnamed" flag which uses the
clipboard register '+' (|quoteplus|) instead of
register '*' for all yank, delete, change and put
operations which would normally go to the unnamed
register.  When "unnamed" is also included to the
option, yank operations (but not delete, change or
put) will additionally copy the text into register
'*'.
Only available with the |+X11| feature.
Availability can be checked with: >
    if has('unnamedplus')
11
  • Yep! Seems to be working as I expected, thank you!
    – xaxa
    Commented Jan 24, 2023 at 12:27
  • Thanks for the feedback :-). If the solution works for you don't forget to validate it using the v button next to the arrow voting buttons. It allow the question to rest ;-) Commented Jan 24, 2023 at 12:30
  • Hmm, sorry, looks like it doesn't quite work :) for some strange reason now I get both + and * registered filled correctly but when go to another application and hit ctrl+v I get wrong content
    – xaxa
    Commented Jan 24, 2023 at 12:35
  • Even if I explicitly specify "+yiw sync between vim and system clipboard seemed to stop working, although it did before. If I don't use set clipboard=unnamedplus it does work
    – xaxa
    Commented Jan 24, 2023 at 12:36
  • Maybe your system clipboard is * and you have to use set clipboard=unnamed Commented Jan 24, 2023 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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