What is the difference between the star register and the plus register?
Answer
"*p vs "+p
Explanation
How it works
Vim has two system clipboard registers that interact with the operating system:
"*-- the selection register (PRIMARY selection on Linux/X11, clipboard on macOS/Windows)"+-- the clipboard register (CLIPBOARD selection on Linux/X11, clipboard on macOS/Windows)
On Linux with X11, these are distinct:
"*holds text you have selected (highlighted) with the mouse. This is the PRIMARY selection, and you paste it with middle-click"+holds text you have explicitly copied with Ctrl-C or a Copy menu command. This is the CLIPBOARD, and you paste it with Ctrl-V
On macOS and Windows, both "* and "+ refer to the same system clipboard, so there is no practical difference.
To use them:
"*y-- yank to the selection register"*p-- paste from the selection register"+y-- yank to the clipboard register"+p-- paste from the clipboard register
Example
On a Linux system with X11:
- Select some text in a web browser by highlighting it with the mouse
- In Vim, type
"*pto paste the selected text (PRIMARY) - Now copy something in the browser using Ctrl-C
- In Vim, type
"+pto paste the copied text (CLIPBOARD)
If you want Vim to always use the system clipboard for all yank and put operations, add one of these to your vimrc:
set clipboard=unnamed " use "* for all operations
set clipboard=unnamedplus " use "+ for all operations
To check if your Vim build supports clipboard registers, run :echo has('clipboard'). A return value of 1 means it is supported.