1
1
" yankring.vim - Yank / Delete Ring for Vim
2
2
" ---------------------------------------------------------------
3
- " Version: 4.1
3
+ " Version: 5.0
4
4
" Authors: David Fishburn <[email protected] >
5
- " Last Modified: 2008 Aug 09
5
+ " Last Modified: 2008 Sep 21
6
6
" Script: http://www.vim.org/scripts/script.php?script_id=1234
7
7
" Based On: Mocked up version by Yegappan Lakshmanan
8
8
" http://groups.yahoo.com/group/vim/post?act=reply&messageNum=34406
@@ -18,7 +18,7 @@ if v:version < 700
18
18
finish
19
19
endif
20
20
21
- let loaded_yankring = 41
21
+ let loaded_yankring = 50
22
22
23
23
let s: yr_has_voperator = 0
24
24
if v: version > 701 || ( v: version == 701 && has (" patch205" ) )
@@ -123,20 +123,22 @@ if !exists('g:yankring_n_keys')
123
123
" to gain the omap support.
124
124
if s: yr_has_voperator == 1
125
125
" 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 '
127
127
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'
129
129
endif
130
130
endif
131
131
132
132
" Allow the user to specify what operator pending motions to map
133
133
if ! 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`'
135
138
endif
136
139
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'
140
142
endif
141
143
142
144
" Allow the user to specify what operator pending motions to map
@@ -705,7 +707,7 @@ endfunction
705
707
706
708
707
709
" Adds this value to the yankring.
708
- function YRRecord (... )
710
+ function ! YRRecord (... )
709
711
710
712
let register = ' "'
711
713
if a: 0 > 0
@@ -1247,20 +1249,24 @@ endfunction
1247
1249
1248
1250
1249
1251
" Create the default maps
1250
- function ! YRMapsExpression (motion)
1252
+ function ! YRMapsExpression (sid , motion, ... )
1251
1253
let cmds = a: motion
1252
1254
1255
+ " OLD ANDY
1253
1256
" Check if we are in operator-pending mode
1254
1257
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> "
1259
1261
" Abort if the user hits Control C
1260
1262
echomsg " YR:Aborting command:" .v: operator .a: motion
1261
1263
return " \<C-C> "
1262
1264
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
1264
1270
endif
1265
1271
1266
1272
" There are a variety of commands which do not change the
@@ -1279,57 +1285,48 @@ function! YRMapsExpression(motion)
1279
1285
" The InsertLeave event will handle the motions
1280
1286
" that place us in insert mode and record the
1281
1287
" changes when insert mode ends.
1282
- let cmds = cmds . " :silent! call YRRecord3() \<CR> "
1288
+ let cmds .= a: sid . " record "
1283
1289
endif
1284
1290
endif
1285
1291
1286
1292
" echo cmds
1287
1293
return cmds
1294
+
1288
1295
endfunction
1289
1296
1290
1297
1291
1298
" Create the default maps
1292
1299
function ! 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
1295
1301
" calls to the YRYankCount function
1296
- let n_maps = split (g: yankring_n_keys, ' , ' )
1302
+ let n_maps = split (g: yankring_n_keys )
1297
1303
" 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"
1305
1309
endfor
1306
1310
1307
1311
" 7.1.patch205 introduces the v:operator function which was essential
1308
1312
" to gain the omap support.
1309
1313
if s: yr_has_voperator == 1
1310
- let o_maps = split (g: yankring_o_keys, ' , ' )
1314
+ let o_maps = split (g: yankring_o_keys )
1311
1315
" 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 ,' \"' ). ' ")'
1316
1318
endfor
1317
1319
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)'
1325
1322
endfor
1326
1323
endif
1327
1324
1328
1325
if g: yankring_map_dot == 1
1329
1326
if s: yr_has_voperator == 1
1330
- exec " nnoremap <script> < expr> . YRMapsExpression('.') "
1327
+ nmap < expr> . YRMapsExpression(" <SID> ",".")
1331
1328
else
1332
- exec " nnoremap <silent> . :<C-U>YRYankCount '.'<CR>"
1329
+ nnoremap <silent> . :<C-U> YRYankCount '.'<CR>
1333
1330
endif
1334
1331
endif
1335
1332
if g: yankring_v_key != ' '
@@ -1377,39 +1374,24 @@ endfunction
1377
1374
" Create the default maps
1378
1375
function ! s: YRMapsDelete ()
1379
1376
1380
- " Iterate through a comma separated list of mappings and create
1377
+ " Iterate through a space separated list of mappings and create
1381
1378
" calls to an appropriate YankRing function
1382
- let n_maps = split (g: yankring_n_keys, ' , ' )
1379
+ let n_maps = split (g: yankring_n_keys )
1383
1380
" 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
1402
1386
endfor
1403
1387
1404
- let to_maps = split (g: yankring_to_keys , ' , ' )
1388
+ let o_maps = split (g: yankring_o_keys )
1405
1389
" 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
1413
1395
endfor
1414
1396
1415
1397
if g: yankring_map_dot == 1
@@ -1847,10 +1829,8 @@ function! s:YRWindowActionN(op, cmd_mode)
1847
1829
return
1848
1830
endif
1849
1831
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
1854
1834
1855
1835
if g: yankring_window_auto_close == 1 && v_count == 0
1856
1836
exec ' bdelete ' .bufnr (s: yr_buffer_name )
@@ -2042,7 +2022,7 @@ endfunction
2042
2022
2043
2023
function ! s: YRFocusGained ()
2044
2024
" If the clipboard has changed record it inside the yankring
2045
- if @+ != s: yr_prev_clipboard
2025
+ if len ( @+ ) > 0 && @+ != s: yr_prev_clipboard
2046
2026
silent ! call YRRecord (" +" )
2047
2027
let s: yr_prev_clipboard = @+
2048
2028
endif
@@ -2082,6 +2062,9 @@ augroup END
2082
2062
2083
2063
" copy register
2084
2064
inoremap <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
+
2085
2068
2086
2069
" Public commands
2087
2070
command ! YRClear call s: YRClear ()
0 commit comments