diff options
| -rw-r--r-- | README.md | 8 | ||||
| -rw-r--r-- | plugin/system_copy.vim | 38 |
2 files changed, 46 insertions, 0 deletions
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 = <SID>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 <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@ + +if !hasmapto('<Plug>SystemCopy') || maparg('cp','n') ==# '' + xmap cp <Plug>SystemCopy + nmap cp <Plug>SystemCopy + nmap cP <Plug>SystemCopyLine +endif |
