comparison plugin/xsel.vim @ 0:c293edf9fbac default tip

Initial revision
author Guido Berhoerster <guido+vim@berhoerster.name>
date Sat, 14 Mar 2015 10:57:21 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c293edf9fbac
1 " Vim xsel integration plugin
2 " Maintainer: Guido Berhoerster <guido+vim@berhoerster.name>
3 " Latest Revision: 2009-02-14
4 " License:
5 " Copyright (c) 2009 <guido+vim@berhoerster.name>
6 "
7 " Permission is hereby granted, free of charge, to any person obtaining
8 " a copy of this software and associated documentation files (the
9 " "Software"), to deal in the Software without restriction, including
10 " without limitation the rights to use, copy, modify, merge, publish,
11 " distribute, sublicense, and/or sell copies of the Software, and to
12 " permit persons to whom the Software is furnished to do so, subject to
13 " the following conditions:
14 "
15 " The above copyright notice and this permission notice shall be included
16 " in all copies or substantial portions of the Software.
17 "
18 " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 " EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 " Requirements: xsel (see http://www.vergenet.net/~conrad/software/xsel/)
26
27 if exists("g:loaded_xsel")
28 finish
29 endif
30 let g:loaded_xsel = 1
31
32 let s:save_cpo = &cpo
33 set cpo&vim
34
35 try
36 if !hasmapto('<Plug>XselGetClipboard')
37 map <unique> <Leader>gc <Plug>XselGetClipboard
38 endif
39 noremap <unique> <script> <silent> <Plug>XselGetClipboard :call <SID>GetClipboard('"')<CR>
40
41 if !hasmapto('<Plug>XselSetClipboard')
42 map <unique> <Leader>sc <Plug>XselSetClipboard
43 endif
44 noremap <unique> <script> <silent> <Plug>XselSetClipboard :call <SID>SetClipboard('"')<CR>
45
46 if !exists(":GetClipboard")
47 command -nargs=0 -register GetClipboard :call s:GetClipboard('<reg>')
48 endif
49
50 if !exists(":SetClipboard")
51 command -nargs=0 -register SetClipboard :call s:SetClipboard('<reg>')
52 endif
53
54 function! s:GetClipboard(reg)
55 let s:reg = a:reg
56 if empty(s:reg)
57 let s:reg='"'
58 endif
59 call setreg(s:reg, system("xsel -o -b"))
60 if v:shell_error != 0
61 redraw!
62 echohl ErrorMsg | echo "***error*** (GetClipboard) error executing xsel" | echohl None
63 endif
64 endfunction
65
66 function! s:SetClipboard(reg)
67 let s:reg = a:reg
68 if empty(s:reg)
69 let s:reg='"'
70 endif
71 call system("xsel -i -b", getreg(s:reg))
72 if v:shell_error != 0
73 redraw!
74 echohl ErrorMsg | echo "***error*** (SetClipboard) error executing xsel" | echohl None
75 endif
76 endfunction
77 finally
78 let &cpo = s:save_cpo
79 endtry