diff options
| -rw-r--r-- | README.md | 17 | ||||
| -rw-r--r-- | plugin/system_copy.vim | 13 |
2 files changed, 24 insertions, 6 deletions
@@ -1,9 +1,9 @@ System Copy =========== -System copy provides vim mappings for copying text to the clipboard on OS X -using `pbcopy`. Most people will be happy just setting their Vim clipboard to -the system clipboard, but I find that doing so pollutes my clipboard history. +System copy provides vim mappings for copying text to the os specific +clipboard. Most people will be happy just setting their Vim clipboard to the +system clipboard, but I find that doing so pollutes my clipboard history. Instead, this plugin creates a unique mapping that explicitly pulls content from Vim into the system clipboard. @@ -21,6 +21,13 @@ object. For instance: In addition, `cP` is mapped to copy the current line directly. +Clipboard Utilities +------------------- + + - OSX - pbcopy + - Windows - clip + - Linux - xsel + Installation ------------ @@ -28,9 +35,9 @@ If you don't have a preferred installation method, I recommend using [Vundle][]. Assuming you have Vundle installed and configured, the following steps will install the plugin: -Add the following line to your `~/.vimrc` and then run `BundleInstall` from +Add the following line to your `~/.vimrc` and then run `PluginInstall` from within Vim: ``` vim -Bundle 'christoomey/vim-system-copy' +Plugin 'christoomey/vim-system-copy' ``` diff --git a/plugin/system_copy.vim b/plugin/system_copy.vim index 71a67f1..80a58f0 100644 --- a/plugin/system_copy.vim +++ b/plugin/system_copy.vim @@ -18,7 +18,7 @@ function! s:system_copy(type, ...) abort else silent exe "normal! `[v`]y" endif - silent call system('pbcopy', getreg('@')) + silent call system(s:CopyCommandForCurrentOS(), getreg('@')) echohl String | echon 'Copied to system clipboard via: ' . mode | echohl None endfunction @@ -33,6 +33,17 @@ function! s:resolve_mode(type, arg) endif endfunction +function! s:CopyCommandForCurrentOS() + let os = substitute(system('uname'), '\n', '', '') + if has("gui_mac") || os == 'Darwin' + return 'pbcopy' + elseif has("gui_win32") + return 'clip' + else + return 'xsel --clipboard --input' + endif +endfunction + xnoremap <silent> <Plug>SystemCopy :<C-U>call <SID>system_copy(visualmode(),visualmode() ==# 'V' ? 1 : 0)<CR> nnoremap <silent> <Plug>SystemCopy :<C-U>set opfunc=<SID>system_copy<CR>g@ nnoremap <silent> <Plug>SystemCopyLine :<C-U>set opfunc=<SID>system_copy<Bar>exe 'norm! 'v:count1.'g@_'<CR> |
