How to Copy and Paste From System Clipboard in Vim and Neovim

Posted by Chaitanya Shahare on Thu, Aug 3, 2023

Command

To copy and paste from the system clipboard in Vim and Neovim, you can use the following command:

Vimscript (for Vim and Neovim with init.vim)

set clipboard=unnamedplus

Add this line to your ~/.vimrc for Vim or ~/.config/nvim/init.vim for Neovim to make it permanent:

set clipboard=unnamedplus

Lua (for Neovim with init.lua)

If you’re using Neovim with init.lua, add the following line to enable system clipboard access:

vim.opt.clipboard = "unnamedplus"

This will ensure that Vim/Neovim uses the system clipboard for all yank, delete, change, and put operations.

Usage

  • Copied text from your system clipboard can be pasted in Vim or Neovim using the p or P commands.
  • Text copied from Vim or Neovim using the y command can be pasted in any other application using Ctrl + V (or Cmd + V on macOS).