From a30524a9fc3e79ae9982b5e93888ee4bc0c1f4db Mon Sep 17 00:00:00 2001 From: Tomek Łaziuk Date: Mon, 17 Aug 2015 23:18:47 +0200 Subject: user options for copy and paste commands added in this commit: user custom options for copy and paste commands more specific and unique checks for build-in mappings checking if plugin was initialized moved to very first lines --- README.md | 34 +++++++++++++++++++++++++++------- plugin/system_copy.vim | 35 +++++++++++++++++++++++++---------- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index f87b360..e04c753 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ System Copy =========== -System copy provides vim mappings for copying / pastying text to the os specific +System copy provides vim mappings for copying / pasting 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 @@ -22,25 +22,45 @@ object. For instance: In addition, `cP` is mapped to copy the current line directly. -The sequence `cv` is mapped to paste the content of system clipboard. +The sequence `cv` is mapped to paste the content of system clipboard to the +next line. Clipboard Utilities ------------------- - - OSX - pbcopy - - Windows - clip - - Linux - xsel + - OSX - `pbcopy` and `pbpaste` + - Windows - `clip` and `paste` + - Linux - `xsel` + +Options +------- + +`system-copy` uses default copy and paste command based on your OS, but +you can override either of these commands if you have more specific needs. + +To declare custom copy command use following example: +``` vim +let g:system_copy#copy_command='xclip -sel clipboard' +``` +And to declare custom paste command use: +``` vim +let g:system_copy#paste_command='xclip -sel clipboard -o' +``` Installation ------------ -If you don't have a preferred installation method, I recommend using [Vundle][]. +If you don't have a preferred installation method, I recommend using [Vundle](https://github.com/VundleVim/Vundle.vim). Assuming you have Vundle installed and configured, the following steps will install the plugin: -Add the following line to your `~/.vimrc` and then run `PluginInstall` from +Add the following line to your `~/.vimrc` and then run `:PluginInstall` from within Vim: ``` vim +call vundle#begin() +" ... Plugin 'christoomey/vim-system-copy' +" ... +call vundle#end() ``` diff --git a/plugin/system_copy.vim b/plugin/system_copy.vim index 2c6bc7c..d280e1e 100644 --- a/plugin/system_copy.vim +++ b/plugin/system_copy.vim @@ -1,3 +1,8 @@ +if exists('g:loaded_system_copy') || v:version < 700 + finish +endif +let g:loaded_system_copy = 1 + let s:blockwise = 'blockwise visual' let s:visual = 'visual' let s:motion = 'motion' @@ -6,11 +11,6 @@ let s:mac = 'mac' let s:windows = 'windows' let s:linux = 'linux' -if exists('g:loaded_system_copy') || &cp || v:version < 700 - finish -endif -let g:loaded_system_copy = 1 - function! s:system_copy(type, ...) abort let mode = resolve_mode(a:type, a:0) if mode == s:linewise @@ -21,8 +21,9 @@ function! s:system_copy(type, ...) abort else silent exe "normal! `[v`]y" endif - silent call system(s:CopyCommandForCurrentOS(), getreg('@')) - echohl String | echon 'Copied to system clipboard via: ' . mode | echohl None + let command = s:CopyCommandForCurrentOS() + silent call system(command, getreg('@')) + echohl String | echon 'Copied to clipboard using: ' . command | echohl None endfunction function! s:system_paste() abort @@ -59,6 +60,9 @@ function! s:currentOS() endfunction function! s:CopyCommandForCurrentOS() + if exists('g:system_copy#copy_command') + return g:system_copy#copy_command + endif let os = currentOS() if os == s:mac return 'pbcopy' @@ -70,6 +74,9 @@ function! s:CopyCommandForCurrentOS() endfunction function! s:PasteCommandForCurrentOS() + if exists('g:system_copy#paste_command') + return g:system_copy#paste_command + endif let os = currentOS() if os == s:mac return 'pbpaste' @@ -85,12 +92,20 @@ nnoremap SystemCopy :set opfunc=system_copyg@ nnoremap SystemCopyLine :set opfunc=system_copyexe 'norm! 'v:count1.'g@_' nnoremap SystemPaste :call system_paste() -if !hasmapto('SystemCopy') || maparg('cp','n') ==# '' - xmap cp SystemCopy +if !hasmapto('SystemCopy', 'n') || maparg('cp', 'n') ==# '' nmap cp SystemCopy +endif + +if !hasmapto('SystemCopy', 'v') || maparg('cp', 'v') ==# '' + xmap cp SystemCopy +endif + +if !hasmapto('SystemCopyLine', 'n') || maparg('cP', 'n') ==# '' nmap cP SystemCopyLine endif -if !hasmapto('SystemPaste') || maparg('cv','n') ==# '' +if !hasmapto('SystemPaste', 'n') || maparg('cv', 'n') ==# '' nmap cv SystemPaste endif + +" vim:ts=2:sw=2:sts=2 -- cgit v1.2.3