How to copy to the system clipboard in Vim
Type "+y and a motion ("+yy for the line) to copy to the system clipboard, and "+p to paste from it. Or add set clipboard=unnamedplus to your config so plain y and p use it.
Vim's y and p use Vim's own register, not the clipboard your other programs share. That's why a line yanked in Vim doesn't paste into your browser, and why p doesn't paste what you just copied there. Two registers reach the system clipboard: + and *. Name the register before the command, with a double quote: "+y copies to the clipboard, "+p pastes from it.
On Linux, + is the clipboard that Ctrl-C and Ctrl-V use, and * is the primary selection: whatever you last highlighted, the text a middle-click pastes. On macOS and Windows there is only one clipboard, and + and * both mean it.
Copy the error into the report
Select the two lines of the error with V and j, copy them with "+y, then go to the end with G and paste with "+p. In this page the clipboard is simulated and stays inside the editor; in your own Vim, the same keys reach every other program.
This editor needs a keyboard. Read on, and play it at your computer.
| Keys | What it does |
|---|---|
| "+yy | Copy the line to the system clipboard. |
| "+yiw | Copy the word under the cursor. |
| V or v, then "+y | Copy what you selected. |
| "+p / "+P | Paste from the clipboard after / before the cursor. |
:%y+ ↵ | Copy the whole file to the clipboard. |
| Ctrl-r+ | In Insert mode: paste the clipboard where you are typing. |
| "*y / "*p | On Linux, copy to and paste from the primary selection instead. |
:set clipboard=unnamedplus ↵ | Make every yank, delete and paste use the clipboard until Vim closes (in Vim on macOS and Windows, clipboard=unnamed). Put it in your config to keep it. |
Make y and p use the clipboard
If you'd rather every yank went to the clipboard, set the clipboard option once in your config. In Vim on Linux, add set clipboard=unnamedplus to ~/.vimrc; in Vim on macOS and Windows, set clipboard=unnamed (unnamedplus needs Vim's X11 or Wayland clipboard support). In Neovim, vim.opt.clipboard = 'unnamedplus' in init.lua works everywhere.
The cost: deletes go to the clipboard too, so dd or x replaces whatever you copied in your browser a moment ago.
When nothing reaches the clipboard
Vim can only reach the clipboard if it was built with clipboard support. Run vim --version in a terminal and look for +clipboard (supported) or -clipboard (not); inside Vim, :echo has('clipboard') prints 1 when it's there. Some Linux packages leave it out: on Debian and Ubuntu, the vim-gtk3 package has it.
Neovim has no build flag. It passes the text to a clipboard tool: pbcopy and pbpaste on macOS, which are always there; on Linux, wl-copy (from wl-clipboard) under Wayland, or xclip or xsel under X11; win32yank on Windows. :checkhealth says which one it found. Without one, Neovim 0.10 and later can use the terminal's own clipboard support (OSC 52) instead, if the terminal has it, which works over SSH too; it looks for it only while the clipboard option is unset.
Pasting while you type
In Insert mode, Ctrl-r then + inserts the clipboard where you're typing, without going back to Normal mode. It inserts the text as if you'd typed it, so auto-indent can still add to the indentation of each line. Ctrl-rCtrl-o+ inserts it literally and doesn't indent it.