vimtricks.wiki Concise Vim tricks, one at a time.

How do I copy my most recent yank from register 0 into the system clipboard register?

Answer

:let @+ = @0

Explanation

When you yank text in Vim, register 0 always holds the most recent yank, independent of deletes that may have changed the unnamed register. If you want to export exactly that last yank to your OS clipboard without re-yanking, copy register 0 directly into +. This is precise and avoids accidental register churn during refactors.

How it works

  • @0 is the yank register: it tracks your latest yank operation
  • @+ is the system clipboard register (when clipboard support is available)
  • :let @+ = @0 copies text from yank register to clipboard in one step

Example

Suppose you yanked this symbol earlier:

UserServiceFactory

Later, after several deletes and edits, you can still push that exact yank to the OS clipboard with:

:let @+ = @0

Now pasting outside Vim yields:

UserServiceFactory

Tips

  • Use :echo @0 first if you want to inspect what will be copied
  • If your terminal Vim lacks clipboard support, @+ may be unavailable; check with :echo has('clipboard')
  • For scripting, :call setreg('+', getreg('0'), getregtype('0')) also preserves register type metadata

Next

How do I run a one-off macro without recording by executing keystrokes from an expression register?