windows-subsystem-for-linuxneovim

Clipboard not shared between wsl and windows 10 neovim


I have a problem when using the paper clip in wsl, when using neovim when pressing yy to copy a line I can only paste it in neovim, but what I would like to do is paste it without any complications in a page or a txt file in windows with notepad, that was just an example, I would also like to be able to copy from windows and paste with the letter p in neovim directly, before I could do this, with the same previous configuration file, however I had to format my windows by virus.

Here my configuration file:

"set directory
set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath

"files
so ~\.config/nvim/.vim/plugins.vim
so ~\.config/nvim/.vim/plugin-config.vim
so ~\.config/nvim/.vim/maps.vim

set list

syntax enable

"show line number and relative number
set nu
set rnu
set numberwidth=1 "better show the numbers

"copy and paste with the mouse
set mouse=a

"enable copy and paste 'yy, p'
set clipboard=unnamed

"shows the pressed
set showcmd

"Show current column
set ruler

"perform indent
set smartindent

"does not create external files
set noswapfile
set nobackup

"Seaching
"moves to result as you type
set incsearch
"distinguish between upper and lower case when searching
set smartcase
"Highlight matches
set hlsearch
"Unless they contain at least one capital letter
set ignorecase


"tab of 4 spaces
set noexpandtab
set tabstop=4 shiftwidth=4
"Scheme
colorscheme gruvbox
let g:gruvbox_contrast_dark = "hard"
"set background=dark

"highlight Normal ctermbg=NONE
set laststatus=2
set noshowmode

" React
"set backupcopy=yes

"Fonts
set guifont=Hurmit_Nerd_Font_Mono:h12

"When a file is edited its indent file is loaded
filetype plugin indent on

"Encoding
set encoding=utf-8

Before I only required this:

"enable copy and paste 'yy, p'
set clipboard=unnamed

Or maybe I am missing some packages in Ubuntu to achieve it, if so could you tell me please? I already searched like crazy and I only found a solution is the following:

" WSL yank support
let s:clip = '/mnt/c/Windows/System32/clip.exe'  " change this path according to your mount point
if executable(s:clip)
    augroup WSLYank
        autocmd!
        autocmd TextYankPost * if v:event.operator ==# 'y' | call system(s:clip, @0) | endif
    augroup END
endif

However, this does not work in reverse, that is, if I copy something from windows, I cannot paste it in wsl

I have ubuntu 20.04, the same one I had before formatting, and I also have xclip, tmux, zsh, python3, python2, nodejs installed

Finally when doing a :%y I get this error, I also tried to put the let g: clipboard ..., but it doesn't work either

enter image description here


Solution

  • Neovim delegates clipboard access to external application. As you don't have any it cannot work. This is clearly written to you in the picture above.

    Windows clip is not supported because it cannot read from clipboard and xclip won't work because it needs X-server to work.

    Normally Neovim makes use of win32yank to access Windows clipboard. So try to download it and put somewhere on WSL path.

    let g:clipboard = {
          \   'name': 'win32yank-wsl',
          \   'copy': {
          \      '+': '/path-file/win32yank.exe -i --crlf',
          \      '*': '/path-file/win32yank.exe -i --crlf',
          \    },
          \   'paste': {
          \      '+': '/path-file/win32yank.exe -o --lf',
          \      '*': '/path-file/win32yank.exe -o --lf',
          \   },
          \   'cache_enabled': 0,
          \ }