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.
- 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
sudo apt install xclip
sudo dnf xclip
- 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.
vmap <C-c> "yy <Bar> :call system('xclip', @y)<CR>
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.<