I wanted to copy some code I have from Neovim to Firefox, but the stuff I yanked doesn't carry over outside Neovim.
After I checked :checkhealth, this what it said:
What should I do to handle this issue?
In order to be able to paste text copied from Neovim to any app, you have to copy the text to the system clipboard. You can do that as follows:
Install a clipboard tool, because, as indicated in your screenshot, you don't have one installed.
If you are on an Xorg session, you may install either xsel or xclip by running:
sudo apt install xsel
or:
sudo apt install xclip
If you are on a Wayland session, you may install wl-clipboard by running:
sudo apt install wl-clipboard
Select the text you wish to copy in Neovim.
Press the following keys one at a time: "+y
This copies (y) the selected text to the selection register ("+).
Paste the selected text to the app you wish to using the usual paste shortcut Ctrl+V.
To make things easier, you can also have the text you copy in Neovim always copied to the system clipboard by adding the following in your ~/.config/nvim/init.vim file (create the file if it doesn't exist or go to the correct file location if you use a custom Neovim setup):
set clipboard=unnamedplus
If you are using the Lua API for configuring Neovim, you can achieve the same using the command in kkvamshee's answer.
You can also achieve this by adding following line to your init.lua file, if you are using the Lua API to configure Neovim:
vim.api.nvim_set_option("clipboard", "unnamed")
I just tested my nvim and my Copy/Paste/Mouse related config options from (~/.config/nvim/init.vim) are:
set mouse=nv " middle-click paste with
set hlsearch " highlight search
set clipboard+=unnamedplus " using system clipboard
# with these plugins
call plug#begin("~/.vim/plugged")
" Plugin Section
Plug 'dracula/vim'
Plug 'ryanoasis/vim-devicons'
" Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Plug 'scrooloose/nerdtree'
Plug 'preservim/nerdcommenter'
Plug 'mhinz/vim-startify'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()
Now Copy works by double-clicking or clicking+draging the mouse to highlight your text selection, right-click then brings up a mini-menu with Copy, Paste, Etc. Select Copy.
Now all of 1) middle-clicking, 2) right-clicking for the mini-menu again to select Paste & 3) the old staple option Ctrl+v will perform the Paste both inside another xfce4-terminal using nvim on a text file or using Firefox on Ask Ubuntu to do this.
And Yeah, I saw the above post, I have xsel 1.2.1-1 installed. If you need my entire nvim/init.vim config file just let me know. Cheers, Jono
I have stumbled upon the same issue and BeastOfCaerbannog's answer is what does the trick.
In Wayland I have the following keybinding in init.lua:
-- Copy/paste from system clipboard
vim.keymap.set({ 'n', 'x' }, 'cp', '"+y')
vim.keymap.set({ 'n', 'x' }, 'cv', '"+p')
-- Delete without changing the registers
vim.keymap.set({ 'n', 'x' }, 'x', '"_x')
This works by using visual mode to select the relevant block of code and using the cp keybing to copy it to system clipboard.
For pasting you need to be in normal mode, and press cv
This works for both X11 and Wayland, the respective clipboard managers just need to be installed (wl-clipboard in my case).