-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwsl-clip.vim
More file actions
38 lines (33 loc) · 1.22 KB
/
Copy pathwsl-clip.vim
File metadata and controls
38 lines (33 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
" --- WSL clipboard bridge for writes to the + register ------------------------
if exists('g:loaded_wsl_plus_clip') | finish | endif
let g:loaded_wsl_plus_clip = 1
function! s:IsWSL() abort
" Most reliable: Microsoft/WSL appears in kernel release
if filereadable('/proc/sys/kernel/osrelease')
let l:rel = join(readfile('/proc/sys/kernel/osrelease'), "\n")
return l:rel =~? 'microsoft' || l:rel =~? 'wsl'
endif
" Fallback: WSLENV is commonly set
return exists('$WSLENV')
endfunction
function! s:WSLClipFromPlus() abort
" Avoid recursion if something indirectly touches registers
if exists('s:_busy') && s:_busy | return | endif
let s:_busy = 1
try
" getreg('+') returns the text; preserve newlines exactly
let l:txt = getreg('+', 1, 1) " (reg, 1=raw, 1=list)
let l:payload = join(l:txt, "\n")
" Use stdin to avoid shell quoting issues
call system('wsl-clip', l:payload)
finally
let s:_busy = 0
endtry
endfunction
if s:IsWSL() && executable('wsl-clip')
augroup WslPlusToWindowsClipboard
autocmd!
" Fires whenever any y/d/c/... updates a register; filter only '+'
autocmd TextYankPost * if v:event.regname ==# '+' | call s:WSLClipFromPlus() | endif
augroup END
endif