iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐢

Sharing the Clipboard Between WSL Vim and Windows

に公開

Overview

By default, vim on WSL cannot share the clipboard with Windows.

In this article, I will introduce how to share the clipboard between vim on WSL and Windows.

Methods

Method 1

vim on WSL uses the X clipboard. Therefore, you can share the clipboard by enabling X using tools like VcXsrv.

Method 2

This is the method I am currently using.

It uses clip.exe to operate the Windows-side clipboard.

vnoremap <RightMouse> :w !clip.exe<CR><ESC>

If you want to sync automatically upon yanking instead of using a keybinding, you can do it like this:

augroup Yank
  au!
  autocmd TextYankPost * :call system('clip.exe', @")
augroup END

In conjunction with tmux, I use Windows Terminal's Paste (Shift + Right Click) for pasting.

Discussion