diff options
| author | Teddy Wing | 2015-10-15 11:33:44 -0400 |
|---|---|---|
| committer | Teddy Wing | 2015-10-15 11:57:48 -0400 |
| commit | 8fdb2daa889703bfca28d309e73b1ffd421d1f9b (patch) | |
| tree | a230feb19a3646a1862dbad07ea311824907b41b | |
| parent | a30524a9fc3e79ae9982b5e93888ee4bc0c1f4db (diff) | |
| download | vim-system-copy-add-command-mode.tar.bz2 | |
Add `:SystemCopy` commandadd-command-mode
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.
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | plugin/system_copy.vim | 9 |
2 files changed, 12 insertions, 1 deletions
@@ -25,6 +25,10 @@ In addition, `cP` is mapped to copy the current line directly. The sequence `cv` is mapped to paste the content of system clipboard to the next line. +A command is also included that will copy the current line or a range of lines: + +`:15,24SystemCopy` => copy lines 15–24 into system clipboard + Clipboard Utilities ------------------- 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 <SID>system_copy(s:command_mode, <line1>, <line2>) + 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@ nnoremap <silent> <Plug>SystemCopyLine :<C-U>set opfunc=<SID>system_copy<Bar>exe 'norm! 'v:count1.'g@_'<CR> |
