Skip to content

Commit 2a381c8

Browse files
dfishburnvim-scripts
authored andcommitted
Version 5.0
NF: The yankring can recognize certain Vim commands which do not change the contents of a buffer and not attempt to capture it. NF: The global variables which allow you to customize the behaviour are now space separated instead of comma separated. This provides greater flexibility but will require you to modify your vimrc (if you have customized it). (Andy Wokula) BF: If using <C-O> from within insert mode, the yankring inserted characters into the buffer instead of capturing the changes, this was fixed by Andy Wokula (Agathoklis Hatzimanikas). BF: The yankring did not properly account for all the different forms of counts "5yy" worked but "y5y" did not (Edwin Shao).
1 parent b9f55ed commit 2a381c8

File tree

2 files changed

+72
-76
lines changed

2 files changed

+72
-76
lines changed

doc/yankring.txt

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

33
Author: David Fishburn August 9, 2008
4-
Version: 4.1
4+
Version: 5.0
55

66
For instructions on installing this file, type
77
:help add-local-help |add-local-help| inside Vim.
@@ -972,13 +972,26 @@ mapping: >
972972
==============================================================================
973973
7. History *yankring-history*
974974

975+
5.0: September 21, 2008:
976+
NF: The yankring can recognize certain Vim commands which do not
977+
change the contents of a buffer and not attempt to capture it.
978+
NF: The global variables which allow you to customize the behaviour
979+
are now space separated instead of comma separated. This
980+
provides greater flexibility but will require you to modify
981+
your vimrc (if you have customized it). (Andy Wokula)
982+
BF: If using <C-O> from within insert mode, the yankring inserted
983+
characters into the buffer instead of capturing the changes,
984+
this was fixed by Andy Wokula (Agathoklis Hatzimanikas).
985+
BF: The yankring did not properly account for all the different
986+
forms of counts "5yy" worked but "y5y" did not (Edwin Shao).
987+
975988
4.1: August 9, 2008:
976989
NF: The yankring now allows you to override which operators should
977990
be ignored (yankring_ignore_operator). By default this is
978991
set for the standard Vim operators which do not modify any
979992
registers (Examples: = and gu) (Andy Wokula).
980993
NF: The yankring did not map v_x (Matt Tolton).
981-
BF: The expression register (quote_=) was not accounted for correctly
994+
BF: The expression register (quote=) was not accounted for correctly
982995
(Agathoklis Hatzimanikas).
983996
BF: Using the v:operator variable must be escaped when used in
984997
a regular expression.

plugin/yankring.vim

Lines changed: 57 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
" yankring.vim - Yank / Delete Ring for Vim
22
" ---------------------------------------------------------------
3-
" Version: 4.1
3+
" Version: 5.0
44
" Authors: David Fishburn <[email protected]>
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
1919
endif
2020

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

2323
let s:yr_has_voperator = 0
2424
if 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
130130
endif
131131

132132
" Allow the user to specify what operator pending motions to map
133133
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`'
135138
endif
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'
140142
endif
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+
12881295
endfunction
12891296

12901297

12911298
" Create the default maps
12921299
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
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
13781375
function! 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

20432023
function! 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
20842064
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+
20852068

20862069
" Public commands
20872070
command! YRClear call s:YRClear()

0 commit comments

Comments
 (0)