1 " File: screenpaste.vim
2 " Description: pastes/inserts current GNU Screen buffer in (almost) any mode
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
10 " GetLatestVimScripts: 1512 1 :AutoInstall: screenpaste.zip
12 if exists("g:loaded_screenpaste") || &cp
15 let g:loaded_screenpaste = "7.0"
17 " Init: store 'compatible' settings {{{1
21 " Run Checks: for Vim version, system() and Screen executable {{{1
22 function! s:Screen_CleanUp(msg) " {{{2
24 echomsg "screenpaste:" a:msg "Plugin not loaded"
26 let g:loaded_screenpaste = "no"
28 unlet! g:screen_clmode g:screen_executable g:screen_register
29 \ g:screen_visualselect g:screen_wait
33 " bail out if not Vim7 or greater
35 call <SID>Screen_CleanUp("Vim7 or greater required.")
39 " bail out if system() is not available
41 call <SID>Screen_CleanUp("builtin system() function not available.")
45 " g:screen_executable: name of GNU Screen executable
46 if !exists("g:screen_executable")
47 let g:screen_executable = "screen"
49 " bail out if GNUscreen is not present
50 if !executable(g:screen_executable)
51 call <SID>Screen_CleanUp("`".g:screen_executable."' not executable.")
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."'"
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")
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,'"')
78 " g:screen_visualselect: select area after paste in visual mode
79 if !exists("g:screen_visualselect")
80 let g:screen_visualselect = 0
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")
90 " Mappings: propose defaults {{{1
91 if !hasmapto("<Plug>ScreenpastePut") " nvo
92 map <unique> <Leader>p <Plug>ScreenpastePut
94 if !hasmapto("<Plug>ScreenpasteGPut") " nvo
95 map <unique> <Leader>gp <Plug>ScreenpasteGPut
97 if !hasmapto("<Plug>ScreenpastePutBefore", "n")
98 nmap <unique> <Leader>P <Plug>ScreenpastePutBefore
100 if !hasmapto("<Plug>ScreenpasteGPutBefore", "n")
101 nmap <unique> <Leader>gP <Plug>ScreenpasteGPutBefore
103 if !hasmapto("<Plug>ScreenpastePut", "ic")
104 map! <unique> <Leader>p <Plug>ScreenpastePut
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>
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>")
136 command -count=0 -bang -register ScreenPut
137 \ call screenpaste#Screen_PutCommand("<count>", "<bang>", "<register>")
140 " Finale: cleanup and restore 'compatible' settings {{{1
142 " Purge Functions that have done their one-time duty
143 delfunction <SID>Screen_CleanUp
144 delfunction <SID>Screen_Default
146 let &cpo = s:save_cpo
151 " EOF vim600: set foldmethod=marker: