11" yankring.vim - Yank / Delete Ring for Vim
22" ---------------------------------------------------------------
3- " Version: 4.1
3+ " Version: 5.0
44" Authors: David Fishburn <dfishburn.vim@gmail.com>
5- " Last Modified: 2008 Aug 09
5+ " Last Modified: 2008 Sep 21
66" Script: http://www.vim.org/scripts/script.php?script_id=1234
77" Based On: Mocked up version by Yegappan Lakshmanan
88" http://groups.yahoo.com/group/vim/post?act=reply&messageNum=34406
@@ -18,7 +18,7 @@ if v:version < 700
1818 finish
1919endif
2020
21- let loaded_yankring = 41
21+ let loaded_yankring = 50
2222
2323let s: yr_has_voperator = 0
2424if v: version > 701 || ( v: version == 701 && has (" patch205" ) )
@@ -123,20 +123,22 @@ if !exists('g:yankring_n_keys')
123123 " to gain the omap support.
124124 if s: yr_has_voperator == 1
125125 " Use omaps for the rest of the functionality
126- let g: yankring_n_keys = ' yy,Y,dd,D,x '
126+ let g: yankring_n_keys = ' Y D x X '
127127 else
128- let g: yankring_n_keys = ' x,yy,dd,yw,dw,ye,de,yE,dE, yiw, diw, yaw, daw,y$,d$,Y,D,yG,dG, ygg, dgg'
128+ let g: yankring_n_keys = ' x yy dd yw dw ye de yE dE yiw diw yaw daw y$ d$ Y D yG dG ygg dgg'
129129 endif
130130endif
131131
132132" Allow the user to specify what operator pending motions to map
133133if ! exists (' g:yankring_o_keys' )
134- let g: yankring_o_keys = ' b,B,w,W,e,E,f,F,t,T,$,G,;'
134+ " let g:yankring_o_keys = 'b,B,w,W,e,E,f,F,t,T,d,y,$,G,;'
135+ " o-motions and text objects, without zap-to-char motions
136+ let g: yankring_o_keys = ' b B w W e E d y $ G ;'
137+ let g: yankring_o_keys .= ' iw iW aw aW as is ap ip a] a[ i] i[ a) a( ab i) i( ib a> a< i> i< at it a} a{ aB i} i{ iB a" a'' a` i" i'' i`'
135138endif
136139
137- " Allow the user to specify what text objects to map
138- if ! exists (' g:yankring_to_keys' )
139- let g: yankring_to_keys = ' iw,iW,aw,aW,as,is,ap,ip,a],a[,i],i[,a),a(,ab,i),i(,ib,a>,a<,i>,i<,at,it,a},a{,aB,i},i{,iB,a",a'' ,a`,i",i'' ,i`'
140+ if ! exists (' g:yankring_zap_keys' )
141+ let g: yankring_zap_keys = ' f F t T'
140142endif
141143
142144" Allow the user to specify what operator pending motions to map
@@ -705,7 +707,7 @@ endfunction
705707
706708
707709" Adds this value to the yankring.
708- function YRRecord (... )
710+ function ! YRRecord (... )
709711
710712 let register = ' "'
711713 if a: 0 > 0
@@ -1247,20 +1249,24 @@ endfunction
12471249
12481250
12491251" Create the default maps
1250- function ! YRMapsExpression (motion)
1252+ function ! YRMapsExpression (sid , motion, ... )
12511253 let cmds = a: motion
12521254
1255+ " OLD ANDY
12531256 " Check if we are in operator-pending mode
12541257 if cmds = ~? ' \(f\|t\)'
1255- " If the operator pending mode is f or t
1256- " request the final character from the user
1257- let c = s: YRGetChar ()
1258- if c == " \<C-C> "
1258+ let zapto = a: 0== 0 ? " " : s: YRGetChar ()
1259+
1260+ if zapto == " \<C-C> "
12591261 " Abort if the user hits Control C
12601262 echomsg " YR:Aborting command:" .v: operator .a: motion
12611263 return " \<C-C> "
12621264 endif
1263- let cmds = cmds . c
1265+
1266+ let cmds = cmds . zapto
1267+ " if v:operator =~ '[cdy]'
1268+ " let cmds .= a:sid. "record"
1269+ " endif
12641270 endif
12651271
12661272 " There are a variety of commands which do not change the
@@ -1279,57 +1285,48 @@ function! YRMapsExpression(motion)
12791285 " The InsertLeave event will handle the motions
12801286 " that place us in insert mode and record the
12811287 " changes when insert mode ends.
1282- let cmds = cmds . " :silent! call YRRecord3() \<CR> "
1288+ let cmds .= a: sid . " record "
12831289 endif
12841290 endif
12851291
12861292 " echo cmds
12871293 return cmds
1294+
12881295endfunction
12891296
12901297
12911298" Create the default maps
12921299function ! s: YRMapsCreate ()
1293-
1294- " Iterate through a comma separated list of mappings and create
1300+ " Iterate through a space separated list of mappings and create
12951301 " calls to the YRYankCount function
1296- let n_maps = split (g: yankring_n_keys, ' , ' )
1302+ let n_maps = split (g: yankring_n_keys )
12971303 " Loop through and prompt the user for all buffer connection parameters.
1298- for n_map in n_maps
1299- if strlen (n_map) > 0
1300- " exec 'nnoremap <silent>'.n_map." :<C-U>YRYankCount '".n_map."'<CR>"
1301- " exec 'nnoremap <silent>'.n_map." :<C-U>YRYankCount '".n_map."'<CR>"
1302- " Andy Wokula's suggestion
1303- exec ' nnoremap <script> ' .n_map.' ' .n_map." :call YRRecord3()\<CR> "
1304- endif
1304+ for key in n_maps
1305+ " exec 'nnoremap <silent>'.key." :<C-U>YRYankCount '".key."'<CR>"
1306+ " exec 'nnoremap <silent>'.key." :<C-U>YRYankCount '".key."'<CR>"
1307+ " Andy Wokula's suggestion
1308+ exec ' nmap' key key ." <SID>record"
13051309 endfor
13061310
13071311 " 7.1.patch205 introduces the v:operator function which was essential
13081312 " to gain the omap support.
13091313 if s: yr_has_voperator == 1
1310- let o_maps = split (g: yankring_o_keys, ' , ' )
1314+ let o_maps = split (g: yankring_o_keys )
13111315 " Loop through and prompt the user for all buffer connection parameters.
1312- for o_map in o_maps
1313- if strlen (o_map) > 0
1314- exec ' onoremap <script> <expr> ' .o_map." YRMapsExpression('" .substitute (o_map, " '" , " ''" , ' g' )." ')"
1315- endif
1316+ for key in o_maps
1317+ exec ' omap <expr>' key ' YRMapsExpression("<SID>","' . escape (key ,' \"' ). ' ")'
13161318 endfor
13171319
1318- " Vim Text-Object maps
1319- let to_maps = split (g: yankring_to_keys , ' ,' )
1320- " Loop through and prompt the user for all buffer connection parameters.
1321- for to_map in to_maps
1322- if strlen (to_map) > 0
1323- exec ' onoremap <script> <expr> ' .to_map." YRMapsExpression('" .substitute (to_map, " '" , " ''" , ' g' )." ')"
1324- endif
1320+ for key in split (g: yankring_zap_keys )
1321+ exec ' omap <expr>' key ' YRMapsExpression("<SID>","' . key . ' ", 1)'
13251322 endfor
13261323 endif
13271324
13281325 if g: yankring_map_dot == 1
13291326 if s: yr_has_voperator == 1
1330- exec " nnoremap <script> < expr> . YRMapsExpression('.') "
1327+ nmap < expr> . YRMapsExpression(" <SID> ",".")
13311328 else
1332- exec " nnoremap <silent> . :<C-U>YRYankCount '.'<CR>"
1329+ nnoremap <silent> . :<C-U> YRYankCount '.'<CR>
13331330 endif
13341331 endif
13351332 if g: yankring_v_key != ' '
@@ -1377,39 +1374,24 @@ endfunction
13771374" Create the default maps
13781375function ! s: YRMapsDelete ()
13791376
1380- " Iterate through a comma separated list of mappings and create
1377+ " Iterate through a space separated list of mappings and create
13811378 " calls to an appropriate YankRing function
1382- let n_maps = split (g: yankring_n_keys, ' , ' )
1379+ let n_maps = split (g: yankring_n_keys )
13831380 " Loop through and prompt the user for all buffer connection parameters.
1384- for n_map in n_maps
1385- if strlen (n_map) > 0
1386- try
1387- silent ! exec ' nunmap ' .n_map
1388- catch
1389- endtry
1390- endif
1391- endfor
1392-
1393- let o_maps = split (g: yankring_o_keys , ' ,' )
1394- " Loop through and prompt the user for all buffer connection parameters.
1395- for o_map in o_maps
1396- if strlen (o_map) > 0
1397- try
1398- silent ! exec ' ounmap ' .o_map
1399- catch
1400- endtry
1401- endif
1381+ for key in n_maps
1382+ try
1383+ silent ! exec ' nunmap' key
1384+ catch
1385+ endtry
14021386 endfor
14031387
1404- let to_maps = split (g: yankring_to_keys , ' , ' )
1388+ let o_maps = split (g: yankring_o_keys )
14051389 " Loop through and prompt the user for all buffer connection parameters.
1406- for to_map in to_maps
1407- if strlen (to_map) > 0
1408- try
1409- silent ! exec ' ounmap ' .to_map
1410- catch
1411- endtry
1412- endif
1390+ for key in o_maps
1391+ try
1392+ silent ! exec ' ounmap' key
1393+ catch
1394+ endtry
14131395 endfor
14141396
14151397 if g: yankring_map_dot == 1
@@ -1847,10 +1829,8 @@ function! s:YRWindowActionN(op, cmd_mode)
18471829 return
18481830 endif
18491831
1850- " while v_count > 0
1851- call s: YRWindowAction (a: op , a: cmd_mode )
1852- let v_count = v_count - 1
1853- " endwhile
1832+ call s: YRWindowAction (a: op , a: cmd_mode )
1833+ let v_count = v_count - 1
18541834
18551835 if g: yankring_window_auto_close == 1 && v_count == 0
18561836 exec ' bdelete ' .bufnr (s: yr_buffer_name )
@@ -2042,7 +2022,7 @@ endfunction
20422022
20432023function ! s: YRFocusGained ()
20442024 " If the clipboard has changed record it inside the yankring
2045- if @+ != s: yr_prev_clipboard
2025+ if len ( @+ ) > 0 && @+ != s: yr_prev_clipboard
20462026 silent ! call YRRecord (" +" )
20472027 let s: yr_prev_clipboard = @+
20482028 endif
@@ -2082,6 +2062,9 @@ augroup END
20822062
20832063" copy register
20842064inoremap <script> <SID> YRGetChar <c-r> =YRGetChar()<CR>
2065+ nnoremap <silent> <SID> record :call YRRecord3()<cr>
2066+ inoremap <silent> <SID> record <C-R> =YRRecord3()<cr>
2067+
20852068
20862069" Public commands
20872070command ! YRClear call s: YRClear ()
0 commit comments