Easiest way to add system clipboard in neovim

There are multiple ways to copy text from neovim to system clipboard, but I found below method much easier.


  1. Install xclip

Xclip is an command line utility which provides an interface to X selections (“the clipboard”) from the command line. Xclip program are available in the official repositories of most modern Linux distributions.

On Arch Linux:

 sudo pacman -S xclip

On Debian/Ubuntu:

 sudo apt install xclip

On Fedora:

 sudo dnf xclip 
  1. Add a shortcut key in init.vim/init.lua file

Neovim offers configuration via init.vim (standard vim script) and init.lua (lua script). Copy and paste the below command according to the config file you are using.

For init.vim:

 vmap <C-c> "yy <Bar> :call system('xclip', @y)<CR> 

For init.lua:

 vim.cmd[[vmap <C-c> "yy <Bar> :call system('xclip', @y)<CR> ]]

Once saved you can use Control + C command in neovim visual mode to copy the text to system clipboard.


There are multiple methods to achieve the same result, but I think this method is the easisest because of less modification required.