1
1
" yankring.vim - Yank / Delete Ring for Vim
2
2
" ---------------------------------------------------------------
3
- " Version: 4.0
4
- " Authors: David Fishburn <fishburn@ianywhere .com>
5
- " Last Modified: Thu 19 Jun 2008 10:27:24 PM Eastern Daylight Time
3
+ " Version: 4.1
4
+ " Authors: David Fishburn <dfishburn.vim@gmail .com>
5
+ " Last Modified: 2008 Aug 09
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
9
- " License: GPL (Gnu Public License)
9
+ " License: GPL (Gnu Public License)
10
10
" GetLatestVimScripts: 1234 1 :AutoInstall: yankring.vim
11
11
12
12
if exists (' loaded_yankring' ) || &cp
@@ -18,7 +18,7 @@ if v:version < 700
18
18
finish
19
19
endif
20
20
21
- let loaded_yankring = 40
21
+ let loaded_yankring = 41
22
22
23
23
let s: yr_has_voperator = 0
24
24
if v: version > 701 || ( v: version == 701 && has (" patch205" ) )
@@ -139,12 +139,11 @@ if !exists('g:yankring_to_keys')
139
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
140
endif
141
141
142
- " Some operating pending motions need to be specified
143
- " using v: to make the actions inclusive, instead of exclusive.
144
- " The f and t motions need this for sure.
145
- if ! exists (' g:yankring_o_inclusive' )
146
- let g: yankring_o_inclusive = ' \(\e\|\f\|i\|\t\|\$\)'
142
+ " Allow the user to specify what operator pending motions to map
143
+ if ! exists (' g:yankring_ignore_operator' )
144
+ let g: yankring_ignore_operator = ' g~ gu gU ! = gq g? > < zf g@'
147
145
endif
146
+ let g: yankring_ignore_operator = ' ' .g: yankring_ignore_operator .' '
148
147
149
148
" Whether we sould map the . operator
150
149
if ! exists (' g:yankring_map_dot' )
@@ -161,7 +160,7 @@ if !exists('g:yankring_v_key')
161
160
endif
162
161
163
162
if ! exists (' g:yankring_del_v_key' )
164
- let g: yankring_del_v_key = ' d'
163
+ let g: yankring_del_v_key = ' d x '
165
164
endif
166
165
167
166
if ! exists (' g:yankring_paste_n_bkey' )
@@ -1104,18 +1103,24 @@ function! s:YRPaste(replace_last_paste_selection, nextvalue, direction, ...)
1104
1103
return
1105
1104
else
1106
1105
" Check for the expression register, in this special case
1107
- " we must copy it's content into the default buffer and paste
1106
+ " we must copy it's evaluation into the default buffer and paste
1108
1107
if user_register == ' ='
1109
- let user_register = ' '
1110
- call setreg (default_buffer, histget (' =' , -1 ) )
1108
+ " Save the default register since Vim will only
1109
+ " allow the expression register to be pasted once
1110
+ " and will revert back to the default buffer
1111
+ let save_default_reg = @"
1112
+ call setreg (default_buffer, eval (histget (' =' , -1 )) )
1111
1113
else
1112
1114
let user_register = ' "' .user_register
1113
1115
endif
1114
1116
exec " normal! " .
1115
1117
\ ((cmd_mode== ' n' ) ? " " : " gv" ).
1116
1118
\ ((v_count > 0 )?(v_count):' ' ).
1117
- \ user_register.
1119
+ \ (( user_register== ' = ' )? ' ' :user_register) .
1118
1120
\ a: direction
1121
+ if user_register == ' ='
1122
+ let @" = save_default_reg
1123
+ endif
1119
1124
" In this case, we have bypassed the yankring
1120
1125
" If the user hits next or previous we want the
1121
1126
" next item pasted to be the top of the yankring.
@@ -1258,17 +1263,24 @@ function! YRMapsExpression(motion)
1258
1263
let cmds = cmds . c
1259
1264
endif
1260
1265
1261
- " Check if we are performing an action that will
1262
- " take us into insert mode
1263
- if ' [cCsS]' !~ v: operator
1264
- " If we have not entered insert mode, feed the call
1265
- " to record the current change when the function ends.
1266
- " This is necessary since omaps do not update registers
1267
- " until the function completes.
1268
- " The InsertLeave event will handle the motions
1269
- " that place us in insert mode and record the
1270
- " changes when insert mode ends.
1271
- let cmds = cmds . " :silent! call YRRecord3()\<CR> "
1266
+ " There are a variety of commands which do not change the
1267
+ " registers, so these operators should be ignored when
1268
+ " determining which operations to record
1269
+ " Simple example is '=' which simply formats the
1270
+ " the selected text.
1271
+ if ' \(' .escape (join (split (g: yankring_ignore_operator ), ' \|' ), ' /.*~$^[]' ).' \) ' !~ escape (v: operator , ' /.*~$^[]' )
1272
+ " Check if we are performing an action that will
1273
+ " take us into insert mode
1274
+ if ' [cCsS]' !~ escape (v: operator , ' /.*~$^[]' )
1275
+ " If we have not entered insert mode, feed the call
1276
+ " to record the current change when the function ends.
1277
+ " This is necessary since omaps do not update registers
1278
+ " until the function completes.
1279
+ " The InsertLeave event will handle the motions
1280
+ " that place us in insert mode and record the
1281
+ " changes when insert mode ends.
1282
+ let cmds = cmds . " :silent! call YRRecord3()\<CR> "
1283
+ endif
1272
1284
endif
1273
1285
1274
1286
" echo cmds
@@ -1299,7 +1311,7 @@ function! s:YRMapsCreate()
1299
1311
" Loop through and prompt the user for all buffer connection parameters.
1300
1312
for o_map in o_maps
1301
1313
if strlen (o_map) > 0
1302
- exec ' onoremap <script> <expr> ' .o_map." YRMapsExpression('" .o_map." ')"
1314
+ exec ' onoremap <script> <expr> ' .o_map." YRMapsExpression('" .substitute ( o_map, " ' " , " '' " , ' g ' ) ." ')"
1303
1315
endif
1304
1316
endfor
1305
1317
@@ -1308,7 +1320,7 @@ function! s:YRMapsCreate()
1308
1320
" Loop through and prompt the user for all buffer connection parameters.
1309
1321
for to_map in to_maps
1310
1322
if strlen (to_map) > 0
1311
- exec ' onoremap <script> <expr> ' .to_map." YRMapsExpression('" .to_map." ')"
1323
+ exec ' onoremap <script> <expr> ' .to_map." YRMapsExpression('" .substitute ( to_map, " ' " , " '' " , ' g ' ) ." ')"
1312
1324
endif
1313
1325
endfor
1314
1326
endif
@@ -1324,7 +1336,14 @@ function! s:YRMapsCreate()
1324
1336
exec ' vnoremap <silent>' .g: yankring_v_key ." :YRYankRange 'v'<CR>"
1325
1337
endif
1326
1338
if g: yankring_del_v_key != ' '
1327
- exec ' vnoremap <silent>' .g: yankring_del_v_key ." :YRDeleteRange 'v'<CR>"
1339
+ for v_map in split (g: yankring_del_v_key )
1340
+ if strlen (v_map) > 0
1341
+ try
1342
+ exec ' vnoremap <silent>' .v_map." :YRDeleteRange 'v'<CR>"
1343
+ catch
1344
+ endtry
1345
+ endif
1346
+ endfor
1328
1347
endif
1329
1348
if g: yankring_paste_n_bkey != ' '
1330
1349
exec ' nnoremap <silent>' .g: yankring_paste_n_bkey ." :<C-U>YRPaste 'P'<CR>"
@@ -1400,7 +1419,14 @@ function! s:YRMapsDelete()
1400
1419
exec ' vunmap ' .g: yankring_v_key
1401
1420
endif
1402
1421
if g: yankring_del_v_key != ' '
1403
- exec ' vunmap ' .g: yankring_del_v_key
1422
+ for v_map in split (g: yankring_del_v_key )
1423
+ if strlen (v_map) > 0
1424
+ try
1425
+ exec ' vunmap ' .v_map
1426
+ catch
1427
+ endtry
1428
+ endif
1429
+ endfor
1404
1430
endif
1405
1431
if g: yankring_paste_n_bkey != ' '
1406
1432
exec ' nunmap ' .g: yankring_paste_n_bkey
@@ -2047,7 +2073,7 @@ endfunction
2047
2073
" Call YRFocusGained to check if the clipboard has been updated
2048
2074
augroup YankRing
2049
2075
autocmd !
2050
- autocmd VimEnter * :call <SID> YRInit ()
2076
+ " autocmd VimEnter * :call <SID>YRInit()
2051
2077
autocmd WinLeave * :call <SID> YRWinLeave ()
2052
2078
autocmd FocusGained * :if has (' clipboard' ) | call <SID> YRFocusGained () | endif
2053
2079
autocmd InsertLeave * :call <SID> YRInsertLeave ()
0 commit comments