Skip to content

Commit b9f55ed

Browse files
dfishburnvim-scripts
authored andcommitted
Version 4.1
NF: The yankring now allows you to override which operators should be ignored (yankring_ignore_operator). By default this is set for the standard Vim operators which do not modify any registers (Examples: = and gu) (Andy Wokula). NF: The yankring did not map v_x (Matt Tolton). BF: The expression register (quote=) was not accounted for correctly (Agathoklis Hatzimanikas). BF: Using the v:operator variable must be escaped when used in a regular expression.
1 parent c5868dc commit b9f55ed

File tree

2 files changed

+77
-33
lines changed

2 files changed

+77
-33
lines changed

doc/yankring.txt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
*yankring.txt* For Vim version 7.0.
22

3-
Author: David Fishburn June 24, 2008
4-
Version: 4.0
3+
Author: David Fishburn August 9, 2008
4+
Version: 4.1
55

66
For instructions on installing this file, type
77
:help add-local-help |add-local-help| inside Vim.
@@ -212,6 +212,13 @@ your |.vimrc|.
212212
the top 10 elements in the yankring are in the numbered reqisters 0-9
213213
you can put the following in your |vimrc| >
214214
let g:yankring_manage_numbered_reg = 1
215+
yankring_ignore_operator
216+
< Default: 'g~ gu gU ! = gq g? > < zf g@'
217+
There are a number of Vim operations which do not change any
218+
registers, and therefore should not be captured by the yankring.
219+
This list is used to ignore the appropriate operators.
220+
You can put the following in your |vimrc| >
221+
let g:yankring_ignore_operator = 'g~ gu gU ! = gq g? > < zf g@'
215222
216223
<
217224
3.2 Default Keys *yankring-mappings*
@@ -965,6 +972,17 @@ mapping: >
965972
==============================================================================
966973
7. History *yankring-history*
967974

975+
4.1: August 9, 2008:
976+
NF: The yankring now allows you to override which operators should
977+
be ignored (yankring_ignore_operator). By default this is
978+
set for the standard Vim operators which do not modify any
979+
registers (Examples: = and gu) (Andy Wokula).
980+
NF: The yankring did not map v_x (Matt Tolton).
981+
BF: The expression register (quote_=) was not accounted for correctly
982+
(Agathoklis Hatzimanikas).
983+
BF: Using the v:operator variable must be escaped when used in
984+
a regular expression.
985+
968986
4.0: June 24, 2008:
969987
NF: The yankring by default now captures all |text-objects| and
970988
all motions (|motion.txt|) which Vim supports. Version 3.0 only

plugin/yankring.vim

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
" yankring.vim - Yank / Delete Ring for Vim
22
" ---------------------------------------------------------------
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
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
9-
" License: GPL (Gnu Public License)
9+
" License: GPL (Gnu Public License)
1010
" GetLatestVimScripts: 1234 1 :AutoInstall: yankring.vim
1111

1212
if exists('loaded_yankring') || &cp
@@ -18,7 +18,7 @@ if v:version < 700
1818
finish
1919
endif
2020

21-
let loaded_yankring = 40
21+
let loaded_yankring = 41
2222

2323
let s:yr_has_voperator = 0
2424
if v:version > 701 || ( v:version == 701 && has("patch205") )
@@ -139,12 +139,11 @@ if !exists('g:yankring_to_keys')
139139
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`'
140140
endif
141141

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@'
147145
endif
146+
let g:yankring_ignore_operator = ' '.g:yankring_ignore_operator.' '
148147

149148
" Whether we sould map the . operator
150149
if !exists('g:yankring_map_dot')
@@ -161,7 +160,7 @@ if !exists('g:yankring_v_key')
161160
endif
162161

163162
if !exists('g:yankring_del_v_key')
164-
let g:yankring_del_v_key = 'd'
163+
let g:yankring_del_v_key = 'd x'
165164
endif
166165

167166
if !exists('g:yankring_paste_n_bkey')
@@ -1104,18 +1103,24 @@ function! s:YRPaste(replace_last_paste_selection, nextvalue, direction, ...)
11041103
return
11051104
else
11061105
" 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
11081107
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)) )
11111113
else
11121114
let user_register = '"'.user_register
11131115
endif
11141116
exec "normal! ".
11151117
\ ((cmd_mode=='n') ? "" : "gv").
11161118
\ ((v_count > 0)?(v_count):'').
1117-
\ user_register.
1119+
\ ((user_register=='=')?'':user_register).
11181120
\ a:direction
1121+
if user_register == '='
1122+
let @" = save_default_reg
1123+
endif
11191124
" In this case, we have bypassed the yankring
11201125
" If the user hits next or previous we want the
11211126
" next item pasted to be the top of the yankring.
@@ -1258,17 +1263,24 @@ function! YRMapsExpression(motion)
12581263
let cmds = cmds . c
12591264
endif
12601265

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
12721284
endif
12731285

12741286
" echo cmds
@@ -1299,7 +1311,7 @@ function! s:YRMapsCreate()
12991311
" Loop through and prompt the user for all buffer connection parameters.
13001312
for o_map in o_maps
13011313
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')."')"
13031315
endif
13041316
endfor
13051317

@@ -1308,7 +1320,7 @@ function! s:YRMapsCreate()
13081320
" Loop through and prompt the user for all buffer connection parameters.
13091321
for to_map in to_maps
13101322
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')."')"
13121324
endif
13131325
endfor
13141326
endif
@@ -1324,7 +1336,14 @@ function! s:YRMapsCreate()
13241336
exec 'vnoremap <silent>'.g:yankring_v_key." :YRYankRange 'v'<CR>"
13251337
endif
13261338
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
13281347
endif
13291348
if g:yankring_paste_n_bkey != ''
13301349
exec 'nnoremap <silent>'.g:yankring_paste_n_bkey." :<C-U>YRPaste 'P'<CR>"
@@ -1400,7 +1419,14 @@ function! s:YRMapsDelete()
14001419
exec 'vunmap '.g:yankring_v_key
14011420
endif
14021421
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
14041430
endif
14051431
if g:yankring_paste_n_bkey != ''
14061432
exec 'nunmap '.g:yankring_paste_n_bkey
@@ -2047,7 +2073,7 @@ endfunction
20472073
" Call YRFocusGained to check if the clipboard has been updated
20482074
augroup YankRing
20492075
autocmd!
2050-
autocmd VimEnter * :call <SID>YRInit()
2076+
" autocmd VimEnter * :call <SID>YRInit()
20512077
autocmd WinLeave * :call <SID>YRWinLeave()
20522078
autocmd FocusGained * :if has('clipboard') | call <SID>YRFocusGained() | endif
20532079
autocmd InsertLeave * :call <SID>YRInsertLeave()

0 commit comments

Comments
 (0)