mirror of
https://github.com/amix/vimrc
synced 2025-07-03 14:14:59 +08:00
add supertab plugin and vim-system-copy plugin
This commit is contained in:
66
sources_forked/vim-system-copy/README.md
Normal file
66
sources_forked/vim-system-copy/README.md
Normal file
@ -0,0 +1,66 @@
|
||||
System Copy
|
||||
===========
|
||||
|
||||
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
|
||||
from Vim into the system clipboard.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
System copy provides a mapping to copy to the system clipboard using a motion
|
||||
or visual selection. It also provides a mapping for pasting from the system
|
||||
clipboard.
|
||||
|
||||
The default mapping is `cp`, and can be followed by any motion or text
|
||||
object. For instance:
|
||||
|
||||
- `cpiw` => copy word into system clipboard
|
||||
- `cpi'` => copy inside single quotes to system clipboard
|
||||
|
||||
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.
|
||||
|
||||
Clipboard Utilities
|
||||
-------------------
|
||||
|
||||
- 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](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
|
||||
within Vim:
|
||||
|
||||
``` vim
|
||||
call vundle#begin()
|
||||
" ...
|
||||
Plugin 'christoomey/vim-system-copy'
|
||||
" ...
|
||||
call vundle#end()
|
||||
```
|
111
sources_forked/vim-system-copy/plugin/system_copy.vim
Normal file
111
sources_forked/vim-system-copy/plugin/system_copy.vim
Normal file
@ -0,0 +1,111 @@
|
||||
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'
|
||||
let s:linewise = 'linewise'
|
||||
let s:mac = 'mac'
|
||||
let s:windows = 'windows'
|
||||
let s:linux = 'linux'
|
||||
|
||||
function! s:system_copy(type, ...) abort
|
||||
let mode = <SID>resolve_mode(a:type, a:0)
|
||||
if mode == s:linewise
|
||||
let lines = { 'start': line("'["), 'end': line("']") }
|
||||
silent exe lines.start . "," . lines.end . "y"
|
||||
elseif mode == s:visual || mode == s:blockwise
|
||||
silent exe "normal! `<" . a:type . "`>y"
|
||||
else
|
||||
silent exe "normal! `[v`]y"
|
||||
endif
|
||||
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
|
||||
let command = <SID>PasteCommandForCurrentOS()
|
||||
put =system(command)
|
||||
echohl String | echon 'Pasted to vim using: ' . command | echohl None
|
||||
endfunction
|
||||
|
||||
function! s:resolve_mode(type, arg)
|
||||
let visual_mode = a:arg != 0
|
||||
if visual_mode
|
||||
return (a:type == '') ? s:blockwise : s:visual
|
||||
elseif a:type == 'line'
|
||||
return s:linewise
|
||||
else
|
||||
return s:motion
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:currentOS()
|
||||
let os = substitute(system('uname'), '\n', '', '')
|
||||
let known_os = 'unknown'
|
||||
if has("gui_mac") || os ==? 'Darwin'
|
||||
let known_os = s:mac
|
||||
elseif has("gui_win32")
|
||||
let known_os = s:windows
|
||||
elseif os ==? 'Linux'
|
||||
let known_os = s:linux
|
||||
else
|
||||
exe "normal \<Esc>"
|
||||
throw "unknown OS: " . os
|
||||
endif
|
||||
return known_os
|
||||
endfunction
|
||||
|
||||
function! s:CopyCommandForCurrentOS()
|
||||
if exists('g:system_copy#copy_command')
|
||||
return g:system_copy#copy_command
|
||||
endif
|
||||
let os = <SID>currentOS()
|
||||
if os == s:mac
|
||||
return 'pbcopy'
|
||||
elseif os == s:windows
|
||||
return 'clip'
|
||||
elseif os == s:linux
|
||||
return 'xsel --clipboard --input'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:PasteCommandForCurrentOS()
|
||||
if exists('g:system_copy#paste_command')
|
||||
return g:system_copy#paste_command
|
||||
endif
|
||||
let os = <SID>currentOS()
|
||||
if os == s:mac
|
||||
return 'pbpaste'
|
||||
elseif os == s:windows
|
||||
return 'paste'
|
||||
elseif os == s:linux
|
||||
return 'xsel --clipboard --output'
|
||||
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@
|
||||
nnoremap <silent> <Plug>SystemCopyLine :<C-U>set opfunc=<SID>system_copy<Bar>exe 'norm! 'v:count1.'g@_'<CR>
|
||||
nnoremap <silent> <Plug>SystemPaste :<C-U>call <SID>system_paste()<CR>
|
||||
|
||||
if !hasmapto('<Plug>SystemCopy', 'n') || maparg('cp', 'n') ==# ''
|
||||
nmap cp <Plug>SystemCopy
|
||||
endif
|
||||
|
||||
if !hasmapto('<Plug>SystemCopy', 'v') || maparg('cp', 'v') ==# ''
|
||||
xmap cp <Plug>SystemCopy
|
||||
endif
|
||||
|
||||
if !hasmapto('<Plug>SystemCopyLine', 'n') || maparg('cP', 'n') ==# ''
|
||||
nmap cP <Plug>SystemCopyLine
|
||||
endif
|
||||
|
||||
if !hasmapto('<Plug>SystemPaste', 'n') || maparg('cv', 'n') ==# ''
|
||||
nmap cv <Plug>SystemPaste
|
||||
endif
|
||||
|
||||
" vim:ts=2:sw=2:sts=2
|
Reference in New Issue
Block a user