diff --git a/cli/vim/init.vim b/cli/vim/init.vim index c12be90..68c5c61 100644 --- a/cli/vim/init.vim +++ b/cli/vim/init.vim @@ -62,7 +62,20 @@ nnoremap 5 :b5 nnoremap w :w nnoremap :noh -xnoremap y :'<,'>:w !clip.exe +function! WSLCopy() + " Why is this not a built-in Vim script function?! + let [line_start, column_start] = getpos("'<")[1:2] + let [line_end, column_end] = getpos("'>")[1:2] + let lines = getline(line_start, line_end) + if len(lines) == 0 + return '' + endif + let lines[-1] = lines[-1][: column_end - (&selection == 'inclusive' ? 1 : 2)] + let lines[0] = lines[0][column_start - 1:] + call system('clip.exe', join(lines, "\n")) +endfunction + +xnoremap y :call WSLCopy() nmap "" ysiW" nmap '' ysiW'