vim wsl copy to windows system clipboard 1

vim wsl copy to windows system clipboard

# if you want to paste from windows clipboard into vim
# while in Insert Mode press Shift+Ins and confirm paste

# to make vim yank to windows clipboard 
# put the following in your .vimrc
# *you don't need to yank to a specific register
" WSL yank support
let s:clip = '/mnt/c/Windows/System32/clip.exe'  " change this path according to your mount point
if executable(s:clip)
    augroup WSLYank
        autocmd!
        autocmd TextYankPost * if v:event.operator ==# 'y' | call system(s:clip, @0) | endif
    augroup END
endif

Here is what the above code is Doing:
1. It checks if the clip.exe is available in the system.
2. If it is available, it creates a new autocommand group called WSLYank.
3. It then adds a new autocommand to the group. This autocommand will be triggered after every yank operation.
4. The autocommand checks if the yank operation was performed using the y operator.
5. If the yank operation was performed using the y operator, it calls the clip.exe with the yanked text as the argument.
6. The clip.exe then copies the text to the Windows clipboard.

Similar Posts