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