diff --git a/bundle/vim-clipboard/autoload/clipboard.vim b/bundle/vim-clipboard/autoload/clipboard.vim index 95e9067d8..0ec8145b6 100644 --- a/bundle/vim-clipboard/autoload/clipboard.vim +++ b/bundle/vim-clipboard/autoload/clipboard.vim @@ -7,16 +7,57 @@ "============================================================================= " This script is based on kamilkrz (Kamil KrzeĊ›)'s idea about using clipboard. +function! s:set_command() abort + let yank = '' + let paste = '' + + " the logic is based on nvim's clipboard provider + + if has('mac') + let yank = ['pbcopy'] + let paste = ['pbpaste'] + elseif !empty($WAYLAND_DISPLAY) && executable('wl-copy') && executable('wl-paste') + let yank = ['wl-copy', '--foreground', '--type', 'text/plain'] + let paste = ['wl-paste', '--no-newline'] + elseif !empty($DISPLAY) && executable('xclip') + let yank = ['xclip', '-quiet', '-i', '-selection', 'clipboard'] + let paste = ['xclip', '-o', '-selection', 'clipboard'] + elseif !empty($DISPLAY) && executable('xsel') + let yank = ['xsel', '--nodetach', '-i', '-b'] + let paste = ['xsel', '-o', '-b'] + elseif executable('lemonade') + let yank = ['lemonade', 'copy'] + let paste = ['lemonade', 'paste'] + elseif executable('doitclient') + let yank = ['doitclient', 'wclip'] + let paste = ['doitclient', 'wclip', '-r'] + elseif executable('win32yank.exe') + if has('wsl') && getftype(exepath('win32yank.exe')) == 'link' + let win32yank = resolve(exepath('win32yank.exe')) + else + let win32yank = 'win32yank.exe' + endif + let yank = [win32yank, '-i', '--crlf'] + let paste = [win32yank, '-o', '--lf'] + elseif executable('termux-clipboard-set') + let yank = ['termux-clipboard-set'] + let paste = ['termux-clipboard-get'] + elseif !empty($TMUX) && executable('tmux') + let yank = ['tmux', 'load-buffer', '-'] + let paste = ['tmux', 'save-buffer', '-'] + endif + return [yank, paste] +endfunction function! clipboard#yank() abort - call system('win32yank.exe -i --crlf', GetSelectedText()) + call system(s:yank_cmd, GetSelectedText()) endfunction " The mode can be `p` or `P` function! clipboard#paste(mode) abort - let @" = system('win32yank.exe -o --lf') + let @" = system(s:paste_cmd) return a:mode endfunction @@ -26,3 +67,5 @@ function! GetSelectedText() let result = getreg("x") return result endfunction + +let [s:yank_cmd, s:paste_cmd] = s:set_command()