From afc81a5d071640bfd3a22e2346135e08de4a7484 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 6 Jun 2021 22:07:16 +0800 Subject: [PATCH] [bugfix] unable to copy inline text --- cli/vim/init.vim | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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'