From aefaff602daead79cf3cc448503e2ad0b2995bee Mon Sep 17 00:00:00 2001 From: Zaq? Wiedmann Date: Thu, 28 May 2015 13:50:07 -0700 Subject: added support for linux and windows --- README.md | 17 ++++++++++++----- plugin/system_copy.vim | 13 ++++++++++++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4a8082a..e7f6b5e 100644 --- a/README.md +++ b/README.md @@ -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 SystemCopy :call system_copy(visualmode(),visualmode() ==# 'V' ? 1 : 0) nnoremap SystemCopy :set opfunc=system_copyg@ nnoremap SystemCopyLine :set opfunc=system_copyexe 'norm! 'v:count1.'g@_' -- cgit v1.2.3