brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: yank to the plus register to copy from Vim to the system clipboard

Clipboard
~/tips/tip-vim-plus-register-system-clipboard

"+p paste from the clipboard

Move text from Vim to any other program with a register.

You yank a line in Vim, switch to the browser, paste, and get something from an hour ago. Vim keeps its own registers, and the system clipboard is one specific register.

Prefix the command with "+:

"+yy      copy the current line
"+y       copy the visual selection
"+p       paste from the clipboard
:%y+      copy the whole file

I find the last one handy for grabbing a whole config file or a script to paste into a web form. In insert mode, Ctrl-R + pastes without leaving the mode.

First check that your Vim can do it:

vim --version | grep clipboard

You want +clipboard. With -clipboard the register does nothing useful, and you need a build with clipboard support.

On Linux there are two selections: "+ is the Ctrl+C and Ctrl+V clipboard, while "* is the middle click one. On other systems both point to the system clipboard.

Over SSH it usually fails, because Vim runs on the server and your clipboard lives on your own machine, unless X11 forwarding is set up. Vim then warns that the register isn’t available and uses register 0.

Further reading: Vim documentation: quote plus

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Clipboard tips xclip -selection clipboard < ~/.ssh/id_ed25519.pub uname -r | wl-copy dir | clip Command-C copy on the Mac cat ~/.ssh/id_ed25519.pub | pbcopy All Clipboard tips (6) All topics

Link