From 8fdb2daa889703bfca28d309e73b1ffd421d1f9b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 15 Oct 2015 11:33:44 -0400 Subject: Add `:SystemCopy` command Enable System Copy to be executed from command mode. :SystemCopy will copy the current line. A range can be specified to copy multiple lines: :15,24SystemCopy This lets users to copy lines without moving the cursor, and allows for repeatability using the `@:` command. --- plugin/system_copy.vim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'plugin') diff --git a/plugin/system_copy.vim b/plugin/system_copy.vim index d280e1e..89c5c26 100644 --- a/plugin/system_copy.vim +++ b/plugin/system_copy.vim @@ -7,6 +7,7 @@ let s:blockwise = 'blockwise visual' let s:visual = 'visual' let s:motion = 'motion' let s:linewise = 'linewise' +let s:command_mode = 'command mode' let s:mac = 'mac' let s:windows = 'windows' let s:linux = 'linux' @@ -16,6 +17,8 @@ function! s:system_copy(type, ...) abort if mode == s:linewise let lines = { 'start': line("'["), 'end': line("']") } silent exe lines.start . "," . lines.end . "y" + elseif mode == s:command_mode + silent exe a:1 . "," . a:2 . "y" elseif mode == s:visual || mode == s:blockwise silent exe "normal! `<" . a:type . "`>y" else @@ -34,7 +37,9 @@ endfunction function! s:resolve_mode(type, arg) let visual_mode = a:arg != 0 - if visual_mode + if a:type == s:command_mode + return s:command_mode + elseif visual_mode return (a:type == '') ? s:blockwise : s:visual elseif a:type == 'line' return s:linewise @@ -87,6 +92,8 @@ function! s:PasteCommandForCurrentOS() endif endfunction +command! -range SystemCopy call system_copy(s:command_mode, , ) + 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