How do I paste text from the system clipboard into Vim?
Answer
"+p
Explanation
The "+p command pastes the contents of the system clipboard into Vim. The "+ register is Vim's connection to the operating system clipboard, allowing you to paste text copied from other applications like your browser, terminal, or text editor.
How it works
"tells Vim you are specifying a register+is the system clipboard register (the OS clipboard)ppastes the register contents after the cursor
Example
You copy the text Hello from Chrome in your web browser using Cmd+C (or Ctrl+C). Switch to Vim and press "+p in normal mode. The text Hello from Chrome is pasted at the cursor position.
The two clipboard registers
Vim has two clipboard-related registers:
"+— the system clipboard (what you copy with Cmd+C / Ctrl+C in other apps)"*— the primary selection (on Linux/X11, this is the text you highlight with the mouse; on macOS,"*and"+behave the same)
Tips
- Use
"+yto yank (copy) text from Vim to the system clipboard - Use
"+P(uppercase P) to paste the clipboard contents before the cursor - Use
"+yyto copy the entire current line to the system clipboard - If you want
yandpto always use the system clipboard, add this to your vimrc:
set clipboard=unnamedplus
- To check if your Vim build supports the clipboard, run
:echo has('clipboard')— it should return1 - If clipboard support is missing, install a Vim build with
+clipboard(e.g.,brew install vimon macOS orsudo apt install vim-gtk3on Ubuntu) - In insert mode, use
<C-r>+to paste from the system clipboard without leaving insert mode