1
1
" yankring.vim - Yank / Delete Ring for Vim
2
2
" ---------------------------------------------------------------
3
- " Version: 16 .0
3
+ " Version: 17 .0
4
4
" Author: David Fishburn <dfishburn dot vim at gmail dot com>
5
5
" Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
6
- " Last Modified: 2013 Jan 20
6
+ " Last Modified: 2013 Apr 28
7
7
" Script: http://www.vim.org/scripts/script.php?script_id=1234
8
8
" Based On: Mocked up version by Yegappan Lakshmanan
9
9
" http://groups.yahoo.com/group/vim/post?act=reply&messageNum=34406
@@ -19,7 +19,7 @@ if v:version < 700
19
19
finish
20
20
endif
21
21
22
- let loaded_yankring = 160
22
+ let loaded_yankring = 170
23
23
24
24
" Turn on support for line continuations when creating the script
25
25
let s: cpo_save = &cpo
33
33
if ! exists (' g:yankring_history_dir' )
34
34
let g: yankring_history_dir = expand (' $HOME' )
35
35
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
37
43
endif
38
44
39
45
if ! exists (' g:yankring_history_file' )
@@ -138,6 +144,11 @@ if !exists('g:yankring_ignore_duplicate')
138
144
let g: yankring_ignore_duplicate = 1
139
145
endif
140
146
147
+ " Determine whether to record inserted data
148
+ if ! exists (' g:yankring_record_insert' )
149
+ let g: yankring_record_insert = 0
150
+ endif
151
+
141
152
" Vim automatically manages the numbered registers:
142
153
" 0 - last yanked text
143
154
" 1-9 - last deleted items
@@ -264,16 +275,18 @@ let s:yr_history_v1_nl_pat = '\%(\\\)\@<!@@@'
264
275
let s: yr_history_v2_nl = " \2 " " Use double quotes for a special character
265
276
let s: yr_history_v2_nl_pat = " \2 "
266
277
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
277
290
278
291
279
292
" Vim window size is changed by the yankring plugin or not
@@ -752,7 +765,7 @@ function! s:YRInit(...)
752
765
" reset prior to issuing the YRReplace
753
766
let s: yr_prev_vis_mode = 0
754
767
755
- if a: 0 == 0 && g: yankring_persist == 0
768
+ if a: 0 == 0 && g: yankring_persist != 1
756
769
" The user wants the yankring reset each time Vim is started
757
770
call s: YRClear ()
758
771
endif
@@ -1994,6 +2007,7 @@ function! s:YRMRUAdd( mru_list, element, element_type )
1994
2007
call remove ({a: mru_list }, found)
1995
2008
endif
1996
2009
call insert ({a: mru_list }, elem, 0 )
2010
+ let s: yr_count = len ({a: mru_list })
1997
2011
call s: YRHistorySave ()
1998
2012
endif
1999
2013
@@ -2003,6 +2017,7 @@ endfunction
2003
2017
function ! s: YRMRUDel ( mru_list, elem_nbr )
2004
2018
if a: elem_nbr >= 0 && a: elem_nbr < s: yr_count
2005
2019
call remove ({a: mru_list }, a: elem_nbr )
2020
+ let s: yr_count = len ({a: mru_list })
2006
2021
call s: YRHistorySave ()
2007
2022
endif
2008
2023
@@ -2011,6 +2026,11 @@ endfunction
2011
2026
2012
2027
function ! s: YRHistoryDelete ()
2013
2028
let s: yr_history_list = []
2029
+ let s: yr_count = 0
2030
+
2031
+ if g: yankring_persist != 1
2032
+ return
2033
+ endif
2014
2034
let yr_filename = s: yr_history_file_ {s: yr_history_version }
2015
2035
2016
2036
if filereadable (yr_filename)
@@ -2027,6 +2047,9 @@ function! s:YRHistoryDelete()
2027
2047
endfunction
2028
2048
2029
2049
function ! s: YRHistoryRead ()
2050
+ if g: yankring_persist != 1
2051
+ return
2052
+ endif
2030
2053
let refresh_needed = 1
2031
2054
let yr_history_list = []
2032
2055
let yr_filename = s: yr_history_file_ {s: yr_history_version }
@@ -2060,22 +2083,25 @@ function! s:YRHistoryRead()
2060
2083
2061
2084
let s: yr_history_list = yr_history_list
2062
2085
call s: YRHistorySave ()
2063
-
2064
2086
endfunction
2065
2087
2066
2088
function ! s: YRHistorySave ()
2067
- let yr_filename = s: yr_history_file_ {s: yr_history_version }
2068
2089
2069
2090
if len (s: yr_history_list ) > g: yankring_max_history
2070
2091
" 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
2072
2098
endif
2073
2099
2100
+ let yr_filename = s: yr_history_file_ {s: yr_history_version }
2074
2101
let rc = writefile (s: yr_history_list , yr_filename)
2075
2102
2076
2103
if rc == 0
2077
2104
let s: yr_history_last_upd = getftime (yr_filename)
2078
- let s: yr_count = len (s: yr_history_list )
2079
2105
else
2080
2106
call s: YRErrorMsg (
2081
2107
\ ' YRHistorySave: Unable to save yankring history file: ' .
@@ -2144,7 +2170,8 @@ function! s:YRWindowStatus(show_help)
2144
2170
2145
2171
let msg = ' AutoClose=' .g: yankring_window_auto_close .
2146
2172
\ ' ;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=?' .
2148
2175
\ (s: yr_search== " " ?" " :' ;SearchRegEx=' .s: yr_search )
2149
2176
2150
2177
if s: yr_has_voperator == 0
@@ -2167,6 +2194,7 @@ function! s:YRWindowStatus(show_help)
2167
2194
\ ' " R : [R]egisters display' ." \n " .
2168
2195
\ ' " a : toggle [a]utoclose setting' ." \n " .
2169
2196
\ ' " c : toggle [c]lipboard monitor setting' ." \n " .
2197
+ \ ' " i : toggle [i]nsert recording' ." \n " .
2170
2198
\ ' " q : [q]uit / close the yankring window' ." \n " .
2171
2199
\ ' " ? : Remove help text' ." \n " .
2172
2200
\ ' " <space> : toggles the width of the window' ." \n " .
@@ -2365,6 +2393,7 @@ function! s:YRWindowOpen(results)
2365
2393
nnoremap <buffer> <silent> s :call <SID> YRWindowAction ('s' , 'n')<CR>
2366
2394
nnoremap <buffer> <silent> a :call <SID> YRWindowAction ('a' , 'n')<CR>
2367
2395
nnoremap <buffer> <silent> c :call <SID> YRWindowAction ('c' , 'n')<CR>
2396
+ nnoremap <buffer> <silent> i :call <SID> YRWindowAction ('i' , 'n')<CR>
2368
2397
nnoremap <buffer> <silent> ? :call <SID> YRWindowAction ('?' , 'n')<CR>
2369
2398
nnoremap <buffer> <silent> u :call <SID> YRWindowAction ('u' , 'n')<CR>
2370
2399
nnoremap <buffer> <silent> q :call <SID> YRWindowAction ('q' , 'n')<CR>
@@ -2540,6 +2569,15 @@ function! s:YRWindowAction(op, cmd_mode) range
2540
2569
call s: YRWindowStatus (0 )
2541
2570
call cursor (l: curr_line ,0 )
2542
2571
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
2543
2581
elseif opcode == # ' ?'
2544
2582
" Display the status line / help
2545
2583
call s: YRWindowStatus (1 )
@@ -2732,6 +2770,24 @@ function! s:YRInsertLeave()
2732
2770
call s: YRMapsCreate (' add_only_zap_keys' )
2733
2771
endif
2734
2772
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
+
2735
2791
endfunction
2736
2792
2737
2793
" 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
2804
2860
exec ' noremenu <script> ' .menuPriority.' ' .menuRoot.' .YankRing\ Window :YRShow<CR>'
2805
2861
exec ' noremenu <script> ' .menuPriority.' ' .menuRoot.' .YankRing\ Search :YRSearch<CR>'
2806
2862
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>'
2808
2864
exec ' noremenu <script> ' .menuPriority.' ' .menuRoot.' .Clear :YRClear<CR>'
2809
2865
exec ' noremenu <script> ' .menuPriority.' ' .menuRoot.' .Toggle :YRToggle<CR>'
2810
2866
exec ' noremenu <script> ' .menuPriority.' ' .menuRoot.' .Check\ Clipboard :YRCheckClipboard<CR>'
0 commit comments