Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
108 lines
3.3 KiB
VimL
108 lines
3.3 KiB
VimL
"=============================================================================
|
|
" clipboard.vim --- clipboard for neovim and vim8
|
|
" Copyright (c) 2016-2023 Wang Shidong & Contributors
|
|
" Author: Wang Shidong < wsdjeg@outlook.com >
|
|
" URL: https://spacevim.org
|
|
" License: GPLv3
|
|
"=============================================================================
|
|
|
|
let s:LOGGER =SpaceVim#logger#derive('clipboard')
|
|
|
|
" 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
|
|
|
|
" in vim8, system() do not support list argv
|
|
|
|
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 -i -selection clipboard'
|
|
let paste = 'xclip -o -selection clipboard'
|
|
elseif !empty($DISPLAY) && executable('xsel')
|
|
let yank = 'xsel -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 = shellescape(win32yank) . ' -i --crlf'
|
|
let paste = shellescape(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
|
|
|
|
" yank to system clipboard
|
|
function! clipboard#yank() abort
|
|
if !empty(s:yank_cmd)
|
|
call system(s:yank_cmd, s:get_selection_text())
|
|
else
|
|
if has('clipboard')
|
|
let @+ = s:get_selection_text()
|
|
else
|
|
endif
|
|
endif
|
|
endfunction
|
|
|
|
|
|
" The mode can be `p` or `P`
|
|
|
|
function! clipboard#paste(mode) abort
|
|
if !empty(s:paste_cmd)
|
|
let @" = system(s:paste_cmd)
|
|
else
|
|
if has('clipboard')
|
|
let @" = @+
|
|
else
|
|
endif
|
|
endif
|
|
return a:mode
|
|
endfunction
|
|
|
|
|
|
function! s:get_selection_text()
|
|
let [begin, end] = [getpos("'<"), getpos("'>")]
|
|
let lastchar = matchstr(getline(end[1])[end[2]-1 :], '.')
|
|
if begin[1] ==# end[1]
|
|
let lines = [getline(begin[1])[begin[2]-1 : end[2]-2]]
|
|
else
|
|
let lines = [getline(begin[1])[begin[2]-1 :]]
|
|
\ + (end[1] - begin[1] <# 2 ? [] : getline(begin[1]+1, end[1]-1))
|
|
\ + [getline(end[1])[: end[2]-2]]
|
|
endif
|
|
return join(lines, "\n") . lastchar . (visualmode() ==# 'V' ? "\n" : '')
|
|
endfunction
|
|
let [s:yank_cmd, s:paste_cmd] = s:set_command()
|
|
call s:LOGGER.info('yank_cmd is:' . string(s:yank_cmd))
|
|
call s:LOGGER.info('paste_cmd is:' . string(s:paste_cmd))
|
|
|
|
|
|
function! clipboard#set(yank, past) abort
|
|
let s:yank_cmd = a:yank
|
|
let s:paste_cmd = a:past
|
|
call s:LOGGER.info('yank_cmd is:' . string(s:yank_cmd))
|
|
call s:LOGGER.info('paste_cmd is:' . string(s:paste_cmd))
|
|
endfunction
|