]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - plugin/screenpastePlugin.vim
shell: set GOTOOLCHAIN=local
[config/dotfiles.git] / plugin / screenpastePlugin.vim
1 " File:          screenpaste.vim
2 " Description:   pastes/inserts current GNU Screen buffer in (almost) any mode
3 " Version:       7.0
4 " Mercurial:     $Id: screenpastePlugin.vim,v c90c865d65f4 2008-11-15 00:10 +0100 blacktrash $
5 " Author:        Christian Ebert <blacktrash@gmx.net>
6 " URL:           http://www.vim.org/script.php?script_id=1512
7 " Requirements:  GNU Screen must be in $PATH
8 " Documentation: in separate file, screenpaste.txt
9 "
10 " GetLatestVimScripts: 1512 1 :AutoInstall: screenpaste.zip
11
12 if exists("g:loaded_screenpaste") || &cp
13   finish
14 endif
15 let g:loaded_screenpaste = "7.0"
16
17 " Init: store 'compatible' settings {{{1
18 let s:save_cpo = &cpo
19 set cpo&vim
20
21 " Run Checks: for Vim version, system() and Screen executable {{{1
22 function! s:Screen_CleanUp(msg) " {{{2
23   echohl WarningMsg
24   echomsg "screenpaste:" a:msg "Plugin not loaded"
25   echohl None
26   let g:loaded_screenpaste = "no"
27   let &cpo = s:save_cpo
28   unlet! g:screen_clmode g:screen_executable g:screen_register
29         \ g:screen_visualselect g:screen_wait
30 endfunction
31 " }}}2
32
33 " bail out if not Vim7 or greater
34 if v:version < 700
35   call <SID>Screen_CleanUp("Vim7 or greater required.")
36   finish
37 endif
38
39 " bail out if system() is not available
40 if !exists("*system")
41   call <SID>Screen_CleanUp("builtin system() function not available.")
42   finish
43 endif
44
45 " g:screen_executable: name of GNU Screen executable
46 if !exists("g:screen_executable")
47   let g:screen_executable = "screen"
48 endif
49 " bail out if GNUscreen is not present
50 if !executable(g:screen_executable)
51   call <SID>Screen_CleanUp("`".g:screen_executable."' not executable.")
52   finish
53 endif
54
55 " More Global Variables: {{{1
56 function! s:Screen_Default(val,cur,def) " {{{2
57   echomsg "screenpaste: `".a:cur."':"
58         \ "invalid value for screen_clmode."
59         \ "Reset to '".a:def."' (default)"
60   execute "let" a:val "= '".a:def."'"
61 endfunction
62 " }}}2
63
64 " g:screen_clmode: how screenpaste behaves in Vim's command-line
65 if !exists("g:screen_clmode")
66   let g:screen_clmode = "search"
67 elseif g:screen_clmode !~# '^\%(s\%(earch\|ub\)\|noesc\)$'
68   call <SID>Screen_Default("g:screen_clmode",g:screen_clmode,"search")
69 endif
70
71 " g:screen_register: instead of register "0 use this one
72 if !exists("g:screen_register")
73   let g:screen_register = '"'
74 elseif g:screen_register !~ '^["0-9a-zA-Z]$'
75   call <SID>Screen_Default("g:screen_register",g:screen_register,'"')
76 endif
77
78 " g:screen_visualselect: select area after paste in visual mode
79 if !exists("g:screen_visualselect")
80   let g:screen_visualselect = 0
81 endif
82
83 " g:screen_wait: how long to wait for Screen to write exchange file
84 if !exists("g:screen_wait")
85   let g:screen_wait = "333m"
86 elseif g:screen_wait !~# '^\d\+m\?$'
87   call <SID>Screen_Default("g:screen_wait",g:screen_wait,"333m")
88 endif
89
90 " Mappings: propose defaults {{{1
91 if !hasmapto("<Plug>ScreenpastePut") " nvo
92   map  <unique> <Leader>p <Plug>ScreenpastePut
93 endif
94 if !hasmapto("<Plug>ScreenpasteGPut") " nvo
95   map  <unique> <Leader>gp <Plug>ScreenpasteGPut
96 endif
97 if !hasmapto("<Plug>ScreenpastePutBefore", "n")
98   nmap <unique> <Leader>P <Plug>ScreenpastePutBefore
99 endif
100 if !hasmapto("<Plug>ScreenpasteGPutBefore", "n")
101   nmap <unique> <Leader>gP <Plug>ScreenpasteGPutBefore
102 endif
103 if !hasmapto("<Plug>ScreenpastePut", "ic")
104   map! <unique> <Leader>p <Plug>ScreenpastePut
105 endif
106
107 " Internal Mappings: {{{1
108 nnoremap <script> <silent> <Plug>ScreenpastePut
109       \ :call screenpaste#Screen_NPut("p")<CR>
110 nnoremap <script> <silent> <Plug>ScreenpasteGPut
111       \ :call screenpaste#Screen_NPut("gp")<CR>
112 nnoremap <script> <silent> <Plug>ScreenpastePutBefore
113       \ :call screenpaste#Screen_NPut("P")<CR>
114 nnoremap <script> <silent> <Plug>ScreenpasteGPutBefore
115       \ :call screenpaste#Screen_NPut("gP")<CR>
116 vnoremap <script> <silent> <Plug>ScreenpastePut
117       \ :<C-U> call screenpaste#Screen_VPut("")<CR>
118 vnoremap <script> <silent> <Plug>ScreenpasteGPut
119       \ :<C-U> call screenpaste#Screen_VPut("g")<CR>
120 inoremap <script> <silent> <Plug>ScreenpastePut
121       \ <C-R>=screenpaste#Screen_IPut()<CR><C-R>=screenpaste#Screen_TwRestore()<CR>
122 cnoremap <script>          <Plug>ScreenpastePut
123       \ <C-R>=screenpaste#Screen_CPut()<CR>
124
125 " Commands: {{{1
126 " configuration for command-line-mode
127 command -nargs=1 -complete=custom,screenpaste#Screen_ClCfgComplete
128       \ ScreenCmdlineConf call screenpaste#Screen_ClConfig(<f-args>, 1)
129 command ScreenCmdlineInfo call screenpaste#Screen_ClConfig(g:screen_clmode, 1)
130 command ScreenSearch      call screenpaste#Screen_ClConfig("search", 1)
131 command ScreenSub         call screenpaste#Screen_ClConfig("sub", 1)
132 command ScreenNoEsc       call screenpaste#Screen_ClConfig("noesc", 1)
133 " yank Screen buffer into register (default: screen_register)
134 command -register ScreenYank call screenpaste#Screen_Yank("<register>")
135 " buffer operation
136 command -count=0 -bang -register ScreenPut
137       \ call screenpaste#Screen_PutCommand("<count>", "<bang>", "<register>")
138
139 " }}}1
140 " Finale: cleanup and restore 'compatible' settings {{{1
141
142 " Purge Functions that have done their one-time duty
143 delfunction <SID>Screen_CleanUp
144 delfunction <SID>Screen_Default
145
146 let &cpo = s:save_cpo
147 unlet s:save_cpo
148
149 finish
150 " }}}1
151 " EOF vim600: set foldmethod=marker: