SOFTELメモ Developer's blog

WSLのvimでのコピーをWindowsと共有する

2022/09/04 vim, windows ,

問題

wsl内で実行しているvimはヤンクしてもホストのWindows側のクリップボードには送り込めないのですね?

vimからWindows側にコピー&ペーストしたいのですが……

答え

clip.exe を使って送り込む手がある。

以下を .vimrc などに追記する。

" WSL clipboard
if !empty($WSL_DISTRO_NAME)
	let s:clip = '/mnt/c/Windows/System32/clip.exe'
	if executable(s:clip)
		augroup WSLYank
		autocmd!
		autocmd TextYankPost * if v:event.operator ==# 'y' | call system(s:clip, @0) | endif
		augroup END
	endif
endif

関連するメモ

コメント