if system('uname -r') =~ "Microsoft"
augroup Yank
autocmd!
autocmd TextYankPost * :call system('clip.exe ',@")
augroup END
endif
uname
is a Linux terminal command which returns OS info, such that it will return Linux for WSL.
Whereas with -r
flag, the command returns release info of OS, thus it should include "Windows".
TextYankPost is a vim event (see :h TextYankPost in vim), which detect your text yank activity.
clip.exe is a Windows command prompt's command in WSL (see CLIP /? in command prompt) which copy text or return from a command into clipbord via text | clip.exe or command | clip.exe. Here the clip.exe is executed from vim by vim function system.
In Neovim one can use has('wsl') instead of system('uname -r') =~ "Microsoft".