Skip to content

Commit a884f3a

Browse files
dfishburnvim-scripts
authored andcommitted
Version 17.0
NF: The yankring_history_dir option can now take a comma separated list. First valid directory found will be used (Alex Bel). NF: YankRing can now monitor inserted text and place it in the ring. This is disabled by default, but can be enabled either through the YankRing window or via your .vimrc using the new option: g:yankring_record_insert = 1 (Alexandre Viau). BF: When g:yankring_persist = 0, the YankRing was still reading and writing to the yankring file (Vladimir Marek). BF: The YankRing menu entry, "Replace with Next", was performing the "Replace with Previous" action (Thilo Six).
1 parent 0c74d5b commit a884f3a

File tree

2 files changed

+111
-32
lines changed

2 files changed

+111
-32
lines changed

doc/yankring.txt

Lines changed: 34 additions & 11 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 Jnauary 20, 2013
4-
Version: 16.0
4+
Version: 17.0
55

66
For instructions on installing this file, type
77
:help add-local-help |add-local-help| inside Vim.
@@ -183,12 +183,20 @@ your |.vimrc|.
183183
action is performed and the buffer window is closed, returning you to
184184
the original buffer. This option can be toggled from within the
185185
YankRing buffer by pressing [a]. The YankRing buffer status line
186-
visually indicates where auto close is enabled or disabled. There are
186+
visually indicates when auto close is enabled or disabled. There are
187187
many times where you need to paste (or delete) many items from the
188188
yankring. Pressing [a], disables auto close, allows you to paste many
189189
items, and finally you can press [a] to re-enable auto close, followed
190190
by [q] to quit the buffer window. >
191191
let g:yankring_window_auto_close = 1
192+
yankring_record_insert
193+
< Default: 0
194+
If you want text you insert to be recorded in the YankRing you can
195+
enable this feature two ways. From within the YankRing window you can
196+
press [i]. The YankRing buffer status line visually indicates when
197+
recording inserts is enabled or disabled. To enable this option
198+
at Vim startup, put the following in your .vimrc: >
199+
let g:yankring_record_insert = 1
192200
yankring_window_use_horiz
193201
< Default: 1
194202
When the YankRing window is opened, it uses a horizontal split at the
@@ -246,6 +254,9 @@ your |.vimrc|.
246254
< Default: $HOME
247255
The YankRing stores the text in a file. This global variable
248256
allows you to customize where the file(s) will be stored.
257+
This can be a comma separated list, which is useful if your
258+
.vimrc is shared across different machines. If multipe directories
259+
are specified, the first valid directory will be used.
249260
You can put the following in your |vimrc| >
250261
let g:yankring_history_dir = '$VIM'
251262
yankring_history_file
@@ -306,7 +317,7 @@ your |.vimrc|.
306317
"3": Turns the 'Plugin -> YankRing' menu on with <alt>-y as
307318
the shortcut.
308319
This option defaults to a value of 3 and can be changed
309-
by adding the following to your vimrc: >
320+
by adding the following to your .vimrc: >
310321
:let g:yankring_default_menu_mode = 3
311322
yankring_menu_root
312323
< - Can be used in conjuction with g:yankring_default_menu_mode = 3 but
@@ -518,7 +529,7 @@ YRYankCount tells Vim to execute y$ instead.
518529

519530
3.4 Customizing Menus *yankring-custom-menus*
520531

521-
There are several global variables which can be created in your vimrc to
532+
There are several global variables which can be created in your .vimrc to
522533
allow you to customize where and what is displayed for the YankRing menu.
523534
Simply look up the following global variables: >
524535
yankring_default_menu_mode
@@ -1220,6 +1231,18 @@ mapping: >
12201231
==============================================================================
12211232
7. History *yankring-history*
12221233

1234+
17.0: April 28, 2013
1235+
NF: The yankring_history_dir option can now take a comma separated
1236+
list. First valid directory found will be used (Alex Bel).
1237+
NF: YankRing can now monitor inserted text and place it in the ring.
1238+
This is disabled by default, but can be enabled either through
1239+
the YankRing window or via your .vimrc using the new option:
1240+
g:yankring_record_insert = 1 (Alexandre Viau).
1241+
BF: When g:yankring_persist = 0, the YankRing was still reading
1242+
and writing to the yankring file (Vladimir Marek).
1243+
BF: The YankRing menu entry, "Replace with Next", was performing
1244+
the "Replace with Previous" action (Thilo Six).
1245+
12231246
16.0: January 20, 2013
12241247
BF: YankRing could report "YR: A register cannot be specified in
12251248
replace mode" when using clipboard = unnamed or unnamedplus.
@@ -1444,7 +1467,7 @@ mapping: >
14441467
NF: The global variables which allow you to customize the behaviour
14451468
are now space separated instead of comma separated. This
14461469
provides greater flexibility but will require you to modify
1447-
your vimrc (if you have customized it). (Andy Wokula)
1470+
your .vimrc (if you have customized it). (Andy Wokula)
14481471
BF: If using <C-O> from within insert mode, the YankRing inserted
14491472
characters into the buffer instead of capturing the changes,
14501473
this was fixed by Andy Wokula (Agathoklis Hatzimanikas).
@@ -1483,11 +1506,11 @@ mapping: >
14831506
NF: The YankRing window always opened bottom horizontal. Now it
14841507
can be opened top or bottom and horizontal or vertically.
14851508
This can be controlled via variables in your .vimrc.
1486-
BF: The YankRing has an option to persist between instances
1487-
of Vim by storing the values in global variables within
1488-
the viminfo. This has led to some unusual ordering of
1489-
items in the ring from conflicts between instances.
1490-
This option has been turned off by default.
1509+
BF: The YankRing has an option to persist between instances of Vim by
1510+
storing the values in global variables within the viminfo. This
1511+
has led to some unusual ordering of items in the ring from
1512+
conflicts between instances. This option has been turned off by
1513+
default.
14911514
BF: Their was an issue with yanking using y$.
14921515

14931516
3.1: September 10, 2007:
@@ -1532,7 +1555,7 @@ mapping: >
15321555
are a number of maps that allow you to interact with the
15331556
contents. The window can be positioned vertically or
15341557
horizontally as well as being sized all through options
1535-
specified in your vimrc.
1558+
specified in your .vimrc.
15361559
NF: YRPop can now delete any items from the yankring, rather
15371560
that just from the top.
15381561
NF: YRSetTop has been removed, it is no longer required as the

plugin/yankring.vim

Lines changed: 77 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
" yankring.vim - Yank / Delete Ring for Vim
22
" ---------------------------------------------------------------
3-
" Version: 16.0
3+
" Version: 17.0
44
" Author: David Fishburn <dfishburn dot vim at gmail dot com>
55
" Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
6-
" Last Modified: 2013 Jan 20
6+
" Last Modified: 2013 Apr 28
77
" Script: http://www.vim.org/scripts/script.php?script_id=1234
88
" Based On: Mocked up version by Yegappan Lakshmanan
99
" http://groups.yahoo.com/group/vim/post?act=reply&messageNum=34406
@@ -19,7 +19,7 @@ if v:version < 700
1919
finish
2020
endif
2121

22-
let loaded_yankring = 160
22+
let loaded_yankring = 170
2323

2424
" Turn on support for line continuations when creating the script
2525
let s:cpo_save = &cpo
@@ -33,7 +33,13 @@ endif
3333
if !exists('g:yankring_history_dir')
3434
let g:yankring_history_dir = expand('$HOME')
3535
else
36-
let g:yankring_history_dir = expand(g:yankring_history_dir)
36+
" let g:yankring_history_dir = expand(g:yankring_history_dir)
37+
for dir in split(g:yankring_history_dir, ",")
38+
if isdirectory(expand(dir))
39+
let g:yankring_history_dir = expand(dir)
40+
break
41+
endif
42+
endfor
3743
endif
3844

3945
if !exists('g:yankring_history_file')
@@ -138,6 +144,11 @@ if !exists('g:yankring_ignore_duplicate')
138144
let g:yankring_ignore_duplicate = 1
139145
endif
140146

147+
" Determine whether to record inserted data
148+
if !exists('g:yankring_record_insert')
149+
let g:yankring_record_insert = 0
150+
endif
151+
141152
" Vim automatically manages the numbered registers:
142153
" 0 - last yanked text
143154
" 1-9 - last deleted items
@@ -264,16 +275,18 @@ let s:yr_history_v1_nl_pat = '\%(\\\)\@<!@@@'
264275
let s:yr_history_v2_nl = "\2" " Use double quotes for a special character
265276
let s:yr_history_v2_nl_pat = "\2"
266277
let s:yr_history_last_upd = 0
267-
let s:yr_history_file_v1 =
268-
\ g:yankring_history_dir.'/'.
269-
\ g:yankring_history_file.
270-
\ (g:yankring_share_between_instances==1?'':'_'.v:servername).
271-
\ '.txt'
272-
let s:yr_history_file_v2 =
273-
\ g:yankring_history_dir.'/'.
274-
\ g:yankring_history_file.
275-
\ (g:yankring_share_between_instances==1?'':'_'.v:servername).
276-
\ '_v2.txt'
278+
if g:yankring_persist == 1
279+
let s:yr_history_file_v1 =
280+
\ g:yankring_history_dir.'/'.
281+
\ g:yankring_history_file.
282+
\ (g:yankring_share_between_instances==1?'':'_'.v:servername).
283+
\ '.txt'
284+
let s:yr_history_file_v2 =
285+
\ g:yankring_history_dir.'/'.
286+
\ g:yankring_history_file.
287+
\ (g:yankring_share_between_instances==1?'':'_'.v:servername).
288+
\ '_v2.txt'
289+
endif
277290

278291

279292
" Vim window size is changed by the yankring plugin or not
@@ -752,7 +765,7 @@ function! s:YRInit(...)
752765
" reset prior to issuing the YRReplace
753766
let s:yr_prev_vis_mode = 0
754767

755-
if a:0 == 0 && g:yankring_persist == 0
768+
if a:0 == 0 && g:yankring_persist != 1
756769
" The user wants the yankring reset each time Vim is started
757770
call s:YRClear()
758771
endif
@@ -1994,6 +2007,7 @@ function! s:YRMRUAdd( mru_list, element, element_type )
19942007
call remove({a:mru_list}, found)
19952008
endif
19962009
call insert({a:mru_list}, elem, 0)
2010+
let s:yr_count = len({a:mru_list})
19972011
call s:YRHistorySave()
19982012
endif
19992013

@@ -2003,6 +2017,7 @@ endfunction
20032017
function! s:YRMRUDel( mru_list, elem_nbr )
20042018
if a:elem_nbr >= 0 && a:elem_nbr < s:yr_count
20052019
call remove({a:mru_list}, a:elem_nbr)
2020+
let s:yr_count = len({a:mru_list})
20062021
call s:YRHistorySave()
20072022
endif
20082023

@@ -2011,6 +2026,11 @@ endfunction
20112026

20122027
function! s:YRHistoryDelete()
20132028
let s:yr_history_list = []
2029+
let s:yr_count = 0
2030+
2031+
if g:yankring_persist != 1
2032+
return
2033+
endif
20142034
let yr_filename = s:yr_history_file_{s:yr_history_version}
20152035

20162036
if filereadable(yr_filename)
@@ -2027,6 +2047,9 @@ function! s:YRHistoryDelete()
20272047
endfunction
20282048

20292049
function! s:YRHistoryRead()
2050+
if g:yankring_persist != 1
2051+
return
2052+
endif
20302053
let refresh_needed = 1
20312054
let yr_history_list = []
20322055
let yr_filename = s:yr_history_file_{s:yr_history_version}
@@ -2060,22 +2083,25 @@ function! s:YRHistoryRead()
20602083

20612084
let s:yr_history_list = yr_history_list
20622085
call s:YRHistorySave()
2063-
20642086
endfunction
20652087

20662088
function! s:YRHistorySave()
2067-
let yr_filename = s:yr_history_file_{s:yr_history_version}
20682089

20692090
if len(s:yr_history_list) > g:yankring_max_history
20702091
" Remove items which exceed the max # specified
2071-
call remove(s:yr_history_list, g:yankring_max_history)
2092+
call remove(s:yr_history_list, g:yankring_max_history, (len(s:yr_history_list)-1))
2093+
let s:yr_count = len(s:yr_history_list)
2094+
endif
2095+
2096+
if g:yankring_persist != 1
2097+
return
20722098
endif
20732099

2100+
let yr_filename = s:yr_history_file_{s:yr_history_version}
20742101
let rc = writefile(s:yr_history_list, yr_filename)
20752102

20762103
if rc == 0
20772104
let s:yr_history_last_upd = getftime(yr_filename)
2078-
let s:yr_count = len(s:yr_history_list)
20792105
else
20802106
call s:YRErrorMsg(
20812107
\ 'YRHistorySave: Unable to save yankring history file: '.
@@ -2144,7 +2170,8 @@ function! s:YRWindowStatus(show_help)
21442170

21452171
let msg = 'AutoClose='.g:yankring_window_auto_close.
21462172
\ ';ClipboardMonitor='.g:yankring_clipboard_monitor.
2147-
\ ';Cmds:<enter>,[g]p,[g]P,1-9,d,r,s,a,c,u,R,q,<space>;Help=?'.
2173+
\ ';Inserts='.g:yankring_record_insert.
2174+
\ ';Cmds:<enter>,[g]p,[g]P,1-9,d,r,s,a,c,i,u,R,q,<space>;Help=?'.
21482175
\ (s:yr_search==""?"":';SearchRegEx='.s:yr_search)
21492176

21502177
if s:yr_has_voperator == 0
@@ -2167,6 +2194,7 @@ function! s:YRWindowStatus(show_help)
21672194
\ '" R : [R]egisters display'."\n".
21682195
\ '" a : toggle [a]utoclose setting'."\n".
21692196
\ '" c : toggle [c]lipboard monitor setting'."\n".
2197+
\ '" i : toggle [i]nsert recording'."\n".
21702198
\ '" q : [q]uit / close the yankring window'."\n".
21712199
\ '" ? : Remove help text'."\n".
21722200
\ '" <space> : toggles the width of the window'."\n".
@@ -2365,6 +2393,7 @@ function! s:YRWindowOpen(results)
23652393
nnoremap <buffer> <silent> s :call <SID>YRWindowAction ('s' , 'n')<CR>
23662394
nnoremap <buffer> <silent> a :call <SID>YRWindowAction ('a' , 'n')<CR>
23672395
nnoremap <buffer> <silent> c :call <SID>YRWindowAction ('c' , 'n')<CR>
2396+
nnoremap <buffer> <silent> i :call <SID>YRWindowAction ('i' , 'n')<CR>
23682397
nnoremap <buffer> <silent> ? :call <SID>YRWindowAction ('?' , 'n')<CR>
23692398
nnoremap <buffer> <silent> u :call <SID>YRWindowAction ('u' , 'n')<CR>
23702399
nnoremap <buffer> <silent> q :call <SID>YRWindowAction ('q' , 'n')<CR>
@@ -2540,6 +2569,15 @@ function! s:YRWindowAction(op, cmd_mode) range
25402569
call s:YRWindowStatus(0)
25412570
call cursor(l:curr_line,0)
25422571
return
2572+
elseif opcode ==# 'i'
2573+
let l:curr_line = line(".")
2574+
" Toggle the auto close setting
2575+
let g:yankring_record_insert =
2576+
\ (g:yankring_record_insert == 1?0:1)
2577+
" Display the status line / help
2578+
call s:YRWindowStatus(0)
2579+
call cursor(l:curr_line,0)
2580+
return
25432581
elseif opcode ==# '?'
25442582
" Display the status line / help
25452583
call s:YRWindowStatus(1)
@@ -2732,6 +2770,24 @@ function! s:YRInsertLeave()
27322770
call s:YRMapsCreate('add_only_zap_keys')
27332771
endif
27342772

2773+
" Check if we should record inserted text
2774+
if g:yankring_record_insert == 1
2775+
if !empty(@.) && @. != s:yr_prev_reg_insert
2776+
let elem = s:YRMRUElemFormat(
2777+
\ getreg('.')
2778+
\ , getregtype('.')
2779+
\ )
2780+
let found = s:YRMRUHas('s:yr_history_list', elem)
2781+
2782+
" Only add the item to the "top" of the ring if it is
2783+
" not in the ring already.
2784+
if found == -1
2785+
call YRRecord3(".")
2786+
endif
2787+
let s:yr_prev_reg_insert = @.
2788+
endif
2789+
endif
2790+
27352791
endfunction
27362792

27372793
" Deleting autocommands first is a good idea especially if we want to reload
@@ -2804,7 +2860,7 @@ if has("menu") && g:yankring_default_menu_mode != 0
28042860
exec 'noremenu <script> '.menuPriority.' '.menuRoot.'.YankRing\ Window :YRShow<CR>'
28052861
exec 'noremenu <script> '.menuPriority.' '.menuRoot.'.YankRing\ Search :YRSearch<CR>'
28062862
exec 'noremenu <script> '.menuPriority.' '.menuRoot.'.Replace\ with\ Previous<TAB>'.leader.g:yankring_replace_n_pkey.' :YRReplace -1, ''P''<CR>'
2807-
exec 'noremenu <script> '.menuPriority.' '.menuRoot.'.Replace\ with\ Next<TAB>'.leader.g:yankring_replace_n_pkey.' :YRReplace 1, ''P''<CR>'
2863+
exec 'noremenu <script> '.menuPriority.' '.menuRoot.'.Replace\ with\ Next<TAB>'.leader.g:yankring_replace_n_nkey.' :YRReplace 1, ''P''<CR>'
28082864
exec 'noremenu <script> '.menuPriority.' '.menuRoot.'.Clear :YRClear<CR>'
28092865
exec 'noremenu <script> '.menuPriority.' '.menuRoot.'.Toggle :YRToggle<CR>'
28102866
exec 'noremenu <script> '.menuPriority.' '.menuRoot.'.Check\ Clipboard :YRCheckClipboard<CR>'

0 commit comments

Comments
 (0)