Skip to content

Instantly share code, notes, and snippets.

@bitroniq
Last active March 6, 2021 14:48
Show Gist options
  • Save bitroniq/94721ae9c70f6835850f5d863f46013f to your computer and use it in GitHub Desktop.
Save bitroniq/94721ae9c70f6835850f5d863f46013f to your computer and use it in GitHub Desktop.
Integrate VIM clipboard with Windows on WSL

Add this to .vimrc

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment