8

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

1
  • thanks for your question. All i was trying to do is to print a 1Password fetched secret and added to the clipboard. I was using X but dimissed the obviouness around the X server. Thanks. For me it worked getting values from WSL to Windows11 with printf "$OnePASSWORDSecret" | clip.exe Commented Nov 27, 2023 at 22:52

1 Answer 1

11

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; xclip won't work, because it needs X-server to work (isn't it obvious from its name?) and so on.

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,
      \ }
4
  • 1
    Thank you very much for your help, before I understood well, try to do it all morning, you just need to add the necessary configuration in the init.vim, or .vimrc respectively
    – cacasswein
    Commented Apr 23, 2021 at 13:11
  • 5
    Where do I download win32yank? It's something you download on Windows side, not WSL side, right? EDIT: choco install win32yank. You don't actually even need to set the let g:clipboard part IF you use the lates neovim 0.5-dev (I'm on neovim-0.5.0+ubuntu2+git202105110234-133351cbf-d569569c9)
    – user10706046
    Commented May 18, 2021 at 13:38
  • @walnut_salami Here are the official instructions on how to install it.
    – 71GA
    Commented Apr 5, 2022 at 7:32
  • @Matt I tried installing win32yank-wsl on WSL Debian and it works inside WSL. But when I paste this vim configuration inside my init.vim this does not yet work! Is there any missing puzzle? Does this configuration of yours only define a clipboard inside vim? Do I have to do anything else to now use this defined clipboard?
    – 71GA
    Commented Apr 5, 2022 at 7:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.