From 8527874d26d1a1f94bd81df686b65f1af5673dae Mon Sep 17 00:00:00 2001 From: Chris Toomey Date: Mon, 17 Feb 2014 14:06:04 -0500 Subject: Initial commit with mode resolution --- README.md | 8 ++++++++ plugin/system_copy.vim | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 README.md create mode 100644 plugin/system_copy.vim diff --git a/README.md b/README.md new file mode 100644 index 0000000..48c1afb --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +System Copy +=========== + +System copy provides a mapping to copy to the system clipboard. It accepts a +motion or can be used with a visual selction. + +`cpiw` => copy word into system clipboard +`cpi'` => copy inside single quotes to system clipboard diff --git a/plugin/system_copy.vim b/plugin/system_copy.vim new file mode 100644 index 0000000..f9ebba6 --- /dev/null +++ b/plugin/system_copy.vim @@ -0,0 +1,38 @@ +let s:blockwise = 'blockwise visual' +let s:visual = 'visual' +let s:motion = 'motion' +let s:linewise = 'linewise' + +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) + echohl String | echon 'Activated from: ' . mode | echohl None +endfunction + +function! s:resolve_mode(type, arg) + let visual_mode = a:arg != 0 + if visual_mode + if a:type == '' + return s:blockwise + else + return s:visual + end + elseif a:type == 'line' + return s:linewise + else + return s:motion + endif +endfunction + +xnoremap SystemCopy :call system_copy(visualmode(),visualmode() ==# 'V' ? 1 : 0) +nnoremap SystemCopy :set opfunc=system_copyg@ + +if !hasmapto('SystemCopy') || maparg('cp','n') ==# '' + xmap cp SystemCopy + nmap cp SystemCopy + nmap cP SystemCopyLine +endif -- cgit v1.2.3