hmukos
hmukos

Reputation: 57

How to efficiently yank to system clipboard in WSL2 neovim?

I've installed win32yank through chocolatey and changed clipboard setting in init.vim:

set clipboard=unnamedplus

Everything works however I notice that copy and paste operations now have very slight but noticeable delay. Is there any alternative way to copy to system clipboard? (I'm using neovim in WSL2 Ubuntu)

Upvotes: 0

Views: 3732

Answers (3)

Ninh Dương
Ninh Dương

Reputation: 1

ArchLinux WSL2
Winyank :

 !!!!!! : turn off fast on startup menu (poweroption) fix lag clipboard

# win32yank
curl -sLo/tmp/win32yank.zip https://github.com/equalsraf/win32yank/releases/download/v0.0.4/win32yank-x64.zip

# unzip
unzip -p /tmp/win32yank.zip win32yank.exe > /tmp/win32yank.exe

# Cấp quyền thực thi và di chuyển vào /usr/local/bin
chmod +x /tmp/win32yank.exe
sudo mv /tmp/win32yank.exe /usr/local/bin/ //use local

# Xóa file zip tạm
rm /tmp/win32yank.zip
Sau khi cài đặt, thêm dòng sau vào file ~/.config/nvim/init.lua:

set clipboard=unnamedplus

vim.g.clipboard = {
  name = 'win32yank',
  copy = {
    ['+'] = 'win32yank.exe -i --crlf',
    ['*'] = 'win32yank.exe -i --crlf',
  },
  paste = {
    ['+'] = 'win32yank.exe -o --lf',
    ['*'] = 'win32yank.exe -o --lf',
  },
  cache_enabled = 0,
} 

OK let go !!

Upvotes: 0

b0nes
b0nes

Reputation: 103

I've expanded on Matt's feedback and put this in my vimrc:

let mapleader=" "
noremap <Leader>y "+y
noremap <Leader>p "+p
noremap <Leader>d "+d

Select a block of text, press and then either y/p/d for yanking, pasting and deleting lines into the system buffer. It automagically seems to work with win32yank.exe (which is in my PATH in WSL2).

Upvotes: 0

Matt
Matt

Reputation: 15091

Just remove clipboard option. It's harmful and useless.

What it essentially does, it prepends "quote-plus" to all yank/delete/put commands automatically. Instead of this, manually type "+ when you want to access system clipboard and don't when you don't.

Upvotes: 1

Related Questions