Permalink
Browse files

Version 12.0

NF: Added support for the clipboard option "unnamedplus" which was added after 7.3 (Hong Xu).

NF: When displaying the YankRing using YRShow, a new command "R" has been added to display all of Vim's registers [0-9a-z].

BF: YRMapsDelete did not remove the normal mode @ map, which interfers with recorded macros (Philippe Vaucher ).
  • Loading branch information...
1 parent 5a37961 commit 280ca1b471bd3a0d2347735e8fcbd03a53f2c6ad @dfishburn dfishburn committed with vim-scripts Sep 17, 2011
Showing with 140 additions and 85 deletions.
  1. +2 −0 README
  2. +10 −2 doc/yankring.txt
  3. +128 −83 plugin/yankring.vim
View
2 README
@@ -46,6 +46,8 @@ The GUI significantly simplifies your interaction with the yankring for basic fu
Here is a small section from the tutorial (using maps) so you have some idea of how you interact with the plugin gaining access to previous yanks. Using the GUI for basic operations is self explanatory.
+:h yankring-tutorial
+
---- Partial Tutorial ----
To understand how to use the yankring, the following example should demonstrate the various features.
View
12 doc/yankring.txt
@@ -1,7 +1,7 @@
*yankring.txt* For Vim version 7.0.
-Author: David Fishburn August 29, 2009
-Version: 11.0
+Author: David Fishburn September 16, 2011
+Version: 12.0
For instructions on installing this file, type
:help add-local-help |add-local-help| inside Vim.
@@ -1170,6 +1170,14 @@ mapping: >
==============================================================================
7. History *yankring-history*
+ 12.0: September 16, 2011
+ NF: Added support for the clipboard option "unnamedplus" which was
+ added after 7.3 (Hong Xu).
+ NF: When displaying the YankRing using YRShow, a new command "R"
+ has been added to display all of Vim's registers [0-9a-z].
+ BF: YRMapsDelete did not remove the normal mode @ map, which
+ interfers with recorded macros (Philippe Vaucher ).
+
11.0: August 09, 2010
NF: Documented the global variables to customize the location
of the YankRing menu.
View
211 plugin/yankring.vim
@@ -1,8 +1,8 @@
" yankring.vim - Yank / Delete Ring for Vim
" ---------------------------------------------------------------
-" Version: 11.0
+" Version: 12.0
" Authors: David Fishburn <dfishburn.vim@gmail.com>
-" Last Modified: 2010 Aug 09
+" Last Modified: 2011 Jun 14
" Script: http://www.vim.org/scripts/script.php?script_id=1234
" Based On: Mocked up version by Yegappan Lakshmanan
" http://groups.yahoo.com/group/vim/post?act=reply&messageNum=34406
@@ -18,7 +18,7 @@ if v:version < 700
finish
endif
-let loaded_yankring = 110
+let loaded_yankring = 120
let s:yr_has_voperator = 0
if v:version > 701 || ( v:version == 701 && has("patch205") )
@@ -328,6 +328,11 @@ function! s:YRShow(...)
let toggle = matchstr(a:1, '\d\+')
endif
+ let show_registers = 0
+ if a:0 > 1 && a:2 ==# 'R'
+ let show_registers = 1
+ endif
+
if toggle == 1
if bufwinnr(s:yr_buffer_id) > -1
" If the YankRing window is already open close it
@@ -356,9 +361,9 @@ function! s:YRShow(...)
" show the contents (or when it is refreshed).
if g:yankring_paste_check_default_buffer == 1
let save_reg = 0
- let register = ((&clipboard=='unnamed')?'+':'"')
+ let register = ((&clipboard=~'unnamed')?'+':'"')
- if &clipboard == 'unnamed' && getreg('+') != s:yr_prev_clipboard
+ if &clipboard =~ 'unnamed' && getreg('+') != s:yr_prev_clipboard
let save_reg = 1
endif
if register == '"' && getreg('"') != s:yr_prev_reg_unnamed
@@ -376,14 +381,23 @@ function! s:YRShow(...)
" List is shown in order of replacement
" assuming using previous yanks
let output = "--- YankRing ---\n"
- let output = output . "Elem Content\n"
+ let output = output . (show_registers == 1 ? 'Reg ' : 'Elem')." Content\n"
- call s:YRHistoryRead()
- let disp_item_nr = 1
- for elem in s:yr_history_list
- let output = output . s:YRDisplayElem(disp_item_nr, elem) . "\n"
- let disp_item_nr += 1
- endfor
+ if show_registers == 1
+ for reg_name in map( range(char2nr('0'), char2nr('9')) +
+ \ (range(char2nr('a'), char2nr('z')))
+ \, 'nr2char(v:val)'
+ \ )
+ let output = output . s:YRDisplayElem(reg_name, getreg(reg_name).',') . "\n"
+ endfor
+ else
+ call s:YRHistoryRead()
+ let disp_item_nr = 1
+ for elem in s:yr_history_list
+ let output = output . s:YRDisplayElem(disp_item_nr, elem) . "\n"
+ let disp_item_nr += 1
+ endfor
+ endif
if g:yankring_window_use_separate == 1
call s:YRWindowOpen(output)
@@ -443,7 +457,7 @@ function! s:YRGetElem(...)
return -1
endif
- let default_buffer = ((&clipboard=='unnamed')?'+':'"')
+ let default_buffer = ((&clipboard=~'unnamed')?'+':'"')
let direction = 'p'
if a:0 > 1
@@ -488,7 +502,7 @@ function! s:YRGetElem(...)
return -1
endif
- let default_buffer = ((&clipboard=='unnamed')?'+':'"')
+ let default_buffer = ((&clipboard=~'unnamed')?'+':'"')
call setreg(default_buffer
\ , s:YRGetValElemNbr((elem), 'v')
\ , s:YRGetValElemNbr((elem), 't')
@@ -701,7 +715,7 @@ function! s:YRRegister()
" so test for this condition and return the
" default register
let user_register = ((v:register=='')?('"'):(v:register))
- if &clipboard == 'unnamed' && user_register == '"'
+ if &clipboard =~ 'unnamed' && user_register == '"'
let user_register = '+'
endif
return user_register
@@ -723,7 +737,7 @@ function! s:YRPush(...)
" If we are pushing something on to the yankring, add it to
" the default buffer as well so the next item pasted will
" be the item pushed
- let default_buffer = ((&clipboard=='unnamed')?'+':'"')
+ let default_buffer = ((&clipboard=~'unnamed')?'+':'"')
call setreg(default_buffer, getreg(user_register),
\ getregtype(user_register))
@@ -786,7 +800,7 @@ function! YRRecord(...)
return ""
endif
- let register = ((&clipboard=='unnamed')?'+':register)
+ let register = ((&clipboard=~'unnamed')?'+':register)
" let s:yr_prev_changenr = changenr()
if register == '"'
@@ -809,14 +823,16 @@ function! YRRecord(...)
let s:yr_prev_clipboard = @+
endif
- " If the yankring window is open, refresh it
- call s:YRWindowUpdate()
-
" Manage the numbered registers
if g:yankring_manage_numbered_reg == 1
- call s:YRSetNumberedReg()
+ " Allow the user to define an autocmd to dynamically
+ " setup their connection information.
+ silent! doautocmd User YRSetNumberedReg
endif
+ " If the yankring window is open, refresh it
+ call s:YRWindowUpdate()
+
return ""
endfunction
@@ -832,7 +848,7 @@ function! YRRecord3()
return ""
endif
- let register = ((&clipboard=='unnamed')?'+':register)
+ let register = ((&clipboard=~'unnamed')?'+':register)
if register == '"'
" If the change has occurred via an omap, we must delay
@@ -858,14 +874,16 @@ function! YRRecord3()
let s:yr_prev_clipboard = @+
endif
- " If the yankring window is open, refresh it
- call s:YRWindowUpdate()
-
" Manage the numbered registers
if g:yankring_manage_numbered_reg == 1
- call s:YRSetNumberedReg()
+ " Allow the user to define an autocmd to dynamically
+ " setup their connection information.
+ silent! doautocmd User YRSetNumberedReg
endif
+ " If the yankring window is open, refresh it
+ call s:YRWindowUpdate()
+
return ""
endfunction
@@ -1017,19 +1035,27 @@ endfunction
" Manages the Vim's numbered registers
function! s:YRSetNumberedReg()
- let i = 1
+ let i = 0
while i <= 10
if i > s:yr_count
break
endif
- call setreg( (i-1)
- \ , s:YRGetValElemNbr((i-1),'v')
- \ , s:YRGetValElemNbr((i-1),'t')
+ call setreg( (i)
+ \ , s:YRGetValElemNbr((i),'v')
+ \ , s:YRGetValElemNbr((i),'t')
\ )
let i += 1
endwhile
+
+ " There are a few actions that Vim automatically takes
+ " when modifying the numbered registers.
+ " Modifying register 1 - changes the named register.
+ " It is impossible to set register 2 to a value, since Vim will change it.
+
+ " This will at least preserve the default register
+ let @" = @0
endfunction
@@ -1133,7 +1159,7 @@ endfunction
function! s:YRYankRange(do_delete_selection, ...) range
let user_register = s:YRRegister()
- let default_buffer = ((&clipboard=='unnamed')?'+':'"')
+ let default_buffer = ((&clipboard=~'unnamed')?'+':'"')
" Default command mode to normal mode 'n'
let cmd_mode = 'n'
@@ -1190,7 +1216,7 @@ function! s:YRPaste(replace_last_paste_selection, nextvalue, direction, ...)
let user_register = s:YRRegister()
- let default_buffer = ((&clipboard == 'unnamed')?'+':'"')
+ let default_buffer = ((&clipboard =~ 'unnamed')?'+':'"')
let v_count = v:count
" Default command mode to normal mode 'n'
@@ -1361,7 +1387,7 @@ function! YRMapsExpression(sid, motion, ...)
" echomsg "YRMapsE:".localtime()
" echomsg "YRMapsE 1:".cmds.":".v:operator.":".s:yr_maps_created_zap
- if (a:motion =~ '\.' && s:yr_remove_omap_dot == 1) || a:motion =~ '@'
+ if (a:motion =~ '\.' && s:yr_remove_omap_dot == 1) || a:motion =~ '@'
" If we are repeating a series of commands we must
" unmap the _zap_ keys so that the user is not
" prompted when a command is replayed.
@@ -1412,48 +1438,55 @@ function! YRMapsExpression(sid, motion, ...)
let cmds .= a:sid. "yrrecord"
endif
endif
+
+ " This will not work since we are already executing an expression
+ " if a:motion =~ '@'
+ " let cmds = 'normal! ' . cmds
+ " endif
" echomsg "YRMapsE 5:".a:motion.":'".cmds."':".s:yr_maps_created_zap
return cmds
endfunction
-" Handle any the @
-function! s:YRMapsMacro(bang, ...) range
- " If we are repeating a series of commands we must
- " unmap the _zap_ keys so that the user is not
- " prompted when a command is replayed.
- " These maps must be re-instated in YRRecord3()
- " after the action of the replay is completed.
- call s:YRMapsDelete('remove_only_zap_keys')
-
- " let zapto = (a:0==0 ? "" : s:YRGetChar())
- let zapto = s:YRGetChar()
-
- if zapto == "\<C-C>"
- " Abort if the user hits Control C
- call s:YRWarningMsg( "YR:Aborting command:".v:operator.a:motion )
- return ""
- endif
-
- let v_count = v:count
- " If no count was specified it will have a value of 0
- " so set it to at least 1
- let v_count = ((v_count > 0)?(v_count):'')
-
- let range = ''
- if a:firstline != a:lastline
- let rannge = a:firstline.','.a:lastline
- endif
-
- let cmd = range."normal! ".v_count.'@'.zapto
- " DEBUG
- " echomsg cmd
- exec cmd
-
- call s:YRMapsCreate('add_only_zap_keys')
-endfunction
+" Handle macros (@).
+" This routine is not used, YRMapsExpression is used to
+" handle the @ symbol.
+" function! s:YRMapsMacro(bang, ...) range
+" " If we are repeating a series of commands we must
+" " unmap the _zap_ keys so that the user is not
+" " prompted when a command is replayed.
+" " These maps must be re-instated in YRRecord3()
+" " after the action of the replay is completed.
+" call s:YRMapsDelete('remove_only_zap_keys')
+"
+" " let zapto = (a:0==0 ? "" : s:YRGetChar())
+" let zapto = s:YRGetChar()
+"
+" if zapto == "\<C-C>"
+" " Abort if the user hits Control C
+" call s:YRWarningMsg( "YR:Aborting command:".v:operator.a:motion )
+" return ""
+" endif
+"
+" let v_count = v:count
+" " If no count was specified it will have a value of 0
+" " so set it to at least 1
+" let v_count = ((v_count > 0)?(v_count):'')
+"
+" let range = ''
+" if a:firstline != a:lastline
+" let rannge = a:firstline.','.a:lastline
+" endif
+"
+" let cmd = range."normal! ".v_count.'@'.zapto
+" " DEBUG
+" " echomsg cmd
+" exec cmd
+"
+" call s:YRMapsCreate('add_only_zap_keys')
+" endfunction
" Create the default maps
@@ -1602,47 +1635,49 @@ function! s:YRMapsDelete(...)
endtry
endfor
- if g:yankring_map_dot == 1
- exec "nunmap ."
+ if g:yankring_map_dot == 1
+ silent! exec "nunmap ."
endif
if g:yankring_v_key != ''
- exec 'vunmap '.g:yankring_v_key
+ silent! exec 'vunmap '.g:yankring_v_key
endif
if g:yankring_del_v_key != ''
for v_map in split(g:yankring_del_v_key)
if strlen(v_map) > 0
try
- exec 'vunmap '.v_map
+ silent! exec 'vunmap '.v_map
catch
endtry
endif
endfor
endif
if g:yankring_paste_n_bkey != ''
- exec 'nunmap '.g:yankring_paste_n_bkey
+ silent! exec 'nunmap '.g:yankring_paste_n_bkey
if g:yankring_paste_using_g == 1
- exec 'nunmap g'.g:yankring_paste_n_bkey
+ silent! exec 'nunmap g'.g:yankring_paste_n_bkey
endif
endif
if g:yankring_paste_n_akey != ''
- exec 'nunmap '.g:yankring_paste_n_akey
+ silent! exec 'nunmap '.g:yankring_paste_n_akey
if g:yankring_paste_using_g == 1
- exec 'nunmap g'.g:yankring_paste_n_akey
+ silent! exec 'nunmap g'.g:yankring_paste_n_akey
endif
endif
if g:yankring_paste_v_bkey != ''
- exec 'vunmap '.g:yankring_paste_v_bkey
+ silent! exec 'vunmap '.g:yankring_paste_v_bkey
endif
if g:yankring_paste_v_akey != ''
- exec 'vunmap '.g:yankring_paste_v_akey
+ silent! exec 'vunmap '.g:yankring_paste_v_akey
endif
if g:yankring_replace_n_pkey != ''
- exec 'nunmap '.g:yankring_replace_n_pkey
+ silent! exec 'nunmap '.g:yankring_replace_n_pkey
endif
if g:yankring_replace_n_nkey != ''
- exec 'nunmap '.g:yankring_replace_n_nkey
+ silent! exec 'nunmap '.g:yankring_replace_n_nkey
endif
+ silent! exec 'nunmap @'
+
let g:yankring_enabled = 0
let s:yr_maps_created = 0
endfunction
@@ -1910,7 +1945,7 @@ function! s:YRWindowStatus(show_help)
let msg = 'AutoClose='.g:yankring_window_auto_close.
\ ';ClipboardMonitor='.g:yankring_clipboard_monitor.
- \ ';Cmds:<enter>,[g]p,[g]P,d,r,s,a,c,u,q,<space>;Help=?'.
+ \ ';Cmds:<enter>,[g]p,[g]P,d,r,s,a,c,u,R,q,<space>;Help=?'.
\ (s:yr_search==""?"":';SearchRegEx='.s:yr_search)
if s:yr_has_voperator == 0
@@ -1927,7 +1962,8 @@ function! s:YRWindowStatus(show_help)
\ '" [g]P : [g][P]aste selection'."\n".
\ '" r : [p]aste selection in reverse order'."\n".
\ '" s : [s]earch the yankring for text'."\n".
- \ '" u : [u]pdate display'."\n".
+ \ '" u : [u]pdate display show YankRing'."\n".
+ \ '" R : [R]egisters display'."\n".
\ '" a : toggle [a]utoclose setting'."\n".
\ '" c : toggle [c]lipboard monitor setting'."\n".
\ '" q : [q]uit / close the yankring window'."\n".
@@ -2115,6 +2151,7 @@ function! s:YRWindowOpen(results)
nnoremap <buffer> <silent> ? :call <SID>YRWindowAction ('?' ,'n')<CR>
nnoremap <buffer> <silent> u :call <SID>YRWindowAction ('u' ,'n')<CR>
nnoremap <buffer> <silent> q :call <SID>YRWindowAction ('q' ,'n')<CR>
+ nnoremap <buffer> <silent> R :call <SID>YRWindowAction ('R' ,'n')<CR>
nnoremap <buffer> <silent> <space> \|:silent exec 'vertical resize '.
\ (
\ g:yankring_window_use_horiz!=1 && winwidth('.') > g:yankring_window_width
@@ -2182,7 +2219,7 @@ function! s:YRWindowActionN(op, cmd_mode)
endfunction
function! s:YRWindowAction(op, cmd_mode) range
- let default_buffer = ((&clipboard=='unnamed')?'+':'"')
+ let default_buffer = ((&clipboard=~'unnamed')?'+':'"')
let opcode = a:op
let lines = []
let v_count = v:count
@@ -2251,6 +2288,12 @@ function! s:YRWindowAction(op, cmd_mode) range
call s:YRShow(0)
return
+ elseif opcode ==# 'R'
+ " Switch back to the original buffer
+ exec s:yr_buffer_last_winnr . "wincmd w"
+
+ call s:YRShow(0, 'R')
+ return
elseif opcode ==# 'a'
let l:curr_line = line(".")
" Toggle the auto close setting
@@ -2430,6 +2473,8 @@ augroup YankRing
autocmd WinLeave * :call <SID>YRWinLeave()
autocmd FocusGained * :if has('clipboard') | call <SID>YRFocusGained() | endif
autocmd InsertLeave * :call <SID>YRInsertLeave()
+ autocmd User YRSetNumberedReg :call <SID>YRSetNumberedReg()
+ " autocmd User YRSetNumberedReg :let i = 0 | while i <= 10 | if i > s:yr_count | break | endif | call setreg( (i), s:YRGetValElemNbr((i),'v'), s:YRGetValElemNbr((i),'t') ) | let i += 1 | endwhile
augroup END

0 comments on commit 280ca1b

Please sign in to comment.