Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Version 14.0

NF: The YankRing window supports 1-9 to choose to paste those items for quicker access to the top 9 items.
NF: The YankRing now maps the @ key to run macros.  Not all actions performed during the macro are recorded by the YankRing as a number of items had to be unmapped to support the replay of actions which can prompt the user for input (i.e. t and f) (Asis Hallab).
BF: When flipping between applications the system clipboard was not added to the YankRing in all cases.
BF: The YankRing could report E121: Undefined variable: g:yankring_manual_clipboard_check (Thilo Six).
BF: The YankRing could report: E132: Function call depth is higher than 'maxfuncdepth'.  When executing a YRClear or YRPop or when flipping between applications (Marcin Szamotulski).
BF: Strange behaviour when opening the YankRing with :e [YankRing] instead of :YRShow (Marcin Szamotulski).
  • Loading branch information...
commit 8ebc225b364887c0557ab47ab2ca752a70123bee 1 parent e42cac0
@dfishburn dfishburn authored committed
Showing with 379 additions and 318 deletions.
  1. +1 −1  README
  2. +61 −38 doc/yankring.txt
  3. +317 −279 plugin/yankring.vim
View
2  README
@@ -6,7 +6,7 @@ Vim does not provide any mechanism to reference previous yanked, deleted or chan
The YankRing plugin allows the user to configure the number of yanked, deleted and changed text. A split window can be used to choose which element(s) from the yankring you wish to paste. Alternately after text has been pasted (using p), it can be replaced with a previous value from the yankring with a single key stroke.
-The captured text is stored in a file (location configurable) and is instantly available (also configurable) to any other instance of Vim also running on the same machine.
+The captured text is stored in a file (location configurable) and is instantly available (also configurable) to any other instance of Vim also running on the same machine. This can especially be useful on *nix machines when you are sshed in running Vim in multiple terminals.
Storing the capture text in a file allows the text to be shared easily between multiple instances of Vim running in X, Windows, SSH or Screen.
View
99 doc/yankring.txt
@@ -1,7 +1,7 @@
*yankring.txt* For Vim version 7.0.
-Author: David Fishburn February 5, 2011
-Version: 13.0
+Author: David Fishburn April 1, 2011
+Version: 14.0
For instructions on installing this file, type
:help add-local-help |add-local-help| inside Vim.
@@ -21,23 +21,23 @@ Homepage: http://vim.sourceforge.net/script.php?script_id=1234
3.4 Customizing Menus..................: |yankring-custom-menus|
4. Using the YankRing Window..............: |yankring-window|
5. Commands...............................: |yankring-commands|
- 5.1 YRToggle..........................: |YRToggle|
- 5.2 YRClear...........................: |YRClear|
- 5.3 YRShow............................: |YRShow|
- 5.5 YRGetElem.........................: |YRGetElem|
- 5.6 YRGetMultiple.....................: |YRGetMultiple|
- 5.7 YRPush............................: |YRPush|
- 5.8 YRPop.............................: |YRPop|
- 5.9 YRYankCount.......................: |YRYankCount|
- 5.10 YRYankRange.......................: |YRYankRange|
- 5.11 YRDeleteRange.....................: |YRDeleteRange|
- 5.12 YRPaste...........................: |YRPaste|
- 5.13 YRReplace.........................: |YRReplace|
- 5.14 YRMapsCreate......................: |YRMapsCreate|
- 5.15 YRMapsDelete......................: |YRMapsDelete|
- 5.16 YRSearch..........................: |YRSearch|
- 5.17 YRCheckClipboard..................: |YRCheckClipboard|
- 5.18 YRRunAfterMaps....................: |YRRunAfterMaps|
+ 5.1 YRToggle..........................: |:YRToggle|
+ 5.2 YRClear...........................: |:YRClear|
+ 5.3 YRShow............................: |:YRShow|
+ 5.5 YRGetElem.........................: |:YRGetElem|
+ 5.6 YRGetMultiple.....................: |:YRGetMultiple|
+ 5.7 YRPush............................: |:YRPush|
+ 5.8 YRPop.............................: |:YRPop|
+ 5.9 YRYankCount.......................: |:YRYankCount|
+ 5.10 YRYankRange.......................: |:YRYankRange|
+ 5.11 YRDeleteRange.....................: |:YRDeleteRange|
+ 5.12 YRPaste...........................: |:YRPaste|
+ 5.13 YRReplace.........................: |:YRReplace|
+ 5.14 YRMapsCreate......................: |:YRMapsCreate|
+ 5.15 YRMapsDelete......................: |:YRMapsDelete|
+ 5.16 YRSearch..........................: |:YRSearch|
+ 5.17 YRCheckClipboard..................: |:YRCheckClipboard|
+ 5.18 YRRunAfterMaps....................: |:YRRunAfterMaps|
6. Tutorial...............................: |yankring-tutorial|
6.1 YRShow............................: |YRShow-example|
6.2 YRReplace.........................: |YRReplace-example|
@@ -540,7 +540,7 @@ convience you can map a key, <F11>, to this command: >
Status line~
The first line in the YankRing window is the status line. >
- AutoClose=1;ClipboardMonitor=1;Cmds:p,P,d,r,s,a,c,u,q,<enter>,<space>;Help=?
+ AutoClose=1;ClipboardMonitor=1;Cmds:[g]p,[g]P,1-9,d,r,s,a,c,u,q,<enter>,<space>;Help=?
<
Help=?, pressing [?] will toggle the display of available commands the
yankring window supports. Pressing [?] again will remove the additional
@@ -572,10 +572,11 @@ in the YankRing window.
<CR> Just like "p".
<Enter> Just like "p".
<2-LeftMouse> Just like "p". Normal mode only.
+ 1-9 Short cut to paste the n'th number from the YankRing.
d Removes the element from the yankring. In visual mode all
elements selected will be removed.
r Just like "p", but in visual mode if many lines are selected
- it will paste these in reverse order.
+ it will paste these items in reverse order.
s Prompts you for a regex to search the YankRing and display
only matching items.
a Toggles the g:yankring_window_auto_close setting.
@@ -597,7 +598,7 @@ through maps against a buffer, instead of commands. This makes it much easier
to use.
-5.1 YRToggle *YRToggle*
+5.1 YRToggle :*YRToggle*
Allows you to enable and disable the YankRing quickly. This
command will remove the default maps and recreate them.
@@ -607,12 +608,12 @@ to use.
:YRToggle 0 " Disables it
<
-5.2 YRClear *YRClear*
+5.2 YRClear :*YRClear*
Clears all elements from the yankring.
See also |YRClear-example|.
-5.3 YRShow *YRShow*
+5.3 YRShow :*YRShow*
Similar to |:register|, will display all the entries in the yankring.
The element at the top will be the next element pasted from the
yankring.
@@ -629,7 +630,7 @@ to use.
5 one^@
<
-5.5 YRGetElem *YRGetElem*
+5.5 YRGetElem :*YRGetElem*
This command has two modes. If no parameters are provided, it
becomes interactive. It uses YRShow to display the list and
allows you to choose which element to paste. If a parameter
@@ -649,7 +650,7 @@ to use.
:YRGetElem 0 " Error, invalid choice is reported
-5.6 YRGetMultiple *YRGetMultiple*
+5.6 YRGetMultiple :*YRGetMultiple*
Will paste many elements from the YankRing in one command.
If the number specified is 1 or less, it is assumed you want
just the current element pasted. If the number specified is
@@ -668,7 +669,7 @@ to use.
:YRGetMultiple 0 " Will paste element 1
-5.7 YRPush *YRPush*
+5.7 YRPush :*YRPush*
Allows the user to "push" additional entries into the yankring.
If you yanked text via a key mapping which does not use the
YankRing (or there is text on the clipboard) you can use this
@@ -682,7 +683,7 @@ to use.
< See also |YRPush-example|.
-5.8 YRPop *YRPop*
+5.8 YRPop :*YRPop*
Allows you to pop any elements from the yankring. If no parameters
are provided, the 1st element is removed from the yankring. The
command optionally takes a second parameter to specify how many
@@ -697,7 +698,7 @@ to use.
< See also |YRPop-example|.
-5.9 YRYankCount *YRYankCount*
+5.9 YRYankCount :*YRYankCount*
This command has the most mappings created for it. If you are
in normal mode and you are not specifying a range, this command
will add the text to the yankring.
@@ -739,7 +740,7 @@ to use.
See also |yankring-tutorial|.
-5.10 YRYankRange *YRYankRange*
+5.10 YRYankRange :*YRYankRange*
This command by default is only called in visual mode. All
visual modes (|characterwise-visual|, |linewise-visual|,
|blockwise-visual|) are supported. Any visually selected text
@@ -761,12 +762,12 @@ to use.
< See also |YRYankRange-example|.
-5.11 YRDeleteRange *YRDeleteRange*
+5.11 YRDeleteRange :*YRDeleteRange*
This command is identical to YRYankRange, except the range is
also deleted.
-5.12 YRPaste *YRPaste*
+5.12 YRPaste :*YRPaste*
This command will paste elements from the yankring. By default it has
been mapped to p and P to match Vim's native key strokes. The text
pasted is exactly what was yanked, including newline characters and
@@ -783,7 +784,7 @@ to use.
See also |yankring-tutorial|.
-5.13 YRReplace *YRReplace*
+5.13 YRReplace :*YRReplace*
The purpose of the YankRing is to gain access to previously yanked
(or deleted) elements. This command will replace the previous
paste with a different entry from the yankring.
@@ -812,18 +813,18 @@ to use.
let g:yankring_replace_n_nkey = '<Char-174>'
endif
-5.14 YRMapsCreate *YRMapsCreate*
+5.14 YRMapsCreate :*YRMapsCreate*
This public function is responsible for creating the maps which
enable the yankring. This function is called by the YRToggle
command.
-5.15 YRMapsDelete *YRMapsDelete*
+5.15 YRMapsDelete :*YRMapsDelete*
This public function removes the YankRing maps and disables
the yankring. This function is called by the YRToggle command.
-5.16 YRSearch *YRSearch*
+5.16 YRSearch :*YRSearch*
This command is similar to |YRGetElem|. The command takes
one parameter which is a regular expression. Similar to
YRGetElem, it will display all items in the YankRing that match
@@ -831,14 +832,14 @@ to use.
prompt you to enter which match you wish pasted.
See also |YRSearch-example|.
-5.17 YRCheckClipboard *YRCheckClipboard*
+5.17 YRCheckClipboard :*YRCheckClipboard*
Normally the GUI Vims will automatically (via autocmds)
check for changes to the system clipboard and add any new
changes to the YankRing. Most console Vim's do not fire
the required autocmds. This command will perform the check
manually.
-5.18 YRRunAfterMaps *YRRunAfterMaps*
+5.18 YRRunAfterMaps :*YRRunAfterMaps*
See the following section |yankring-custom-maps|.
@@ -1055,6 +1056,10 @@ mapping: >
Using the YankRing window can be much faster if you do not want to cycle
through the YankRing using <C-P> and <C-N> to find the element.
+ As a short cut, when using the YankRing window, you can press the numbers
+ 1-9 to paste that item directly and close the YankRing window. This can
+ be faster than navigating to the correct line number and pressing 'p'.
+
*multiple-items-example*
There are times when you need to move through a buffer capturing many
different lines (or snippets of code) and eventually want to switch
@@ -1215,6 +1220,24 @@ mapping: >
==============================================================================
7. History *yankring-history*
+ 14.0: April 1, 2012
+ NF: The YankRing window supports 1-9 to choose to paste those
+ items for quicker access to the top 9 items.
+ NF: The YankRing now maps the @ key to run macros. Not all actions
+ performed during the macro are recorded by the YankRing
+ as a number of items had to be unmapped to support the replay
+ of actions which can prompt the user for input (i.e. t and f)
+ (Asis Hallab).
+ BF: When flipping between applications the system clipboard
+ was not added to the YankRing in all cases.
+ BF: The YankRing could report E121: Undefined variable:
+ g:yankring_manual_clipboard_check (Thilo Six).
+ BF: The YankRing could report: E132: Function call depth is higher
+ than 'maxfuncdepth'. When executing a YRClear or YRPop or
+ when flipping between applications (Marcin Szamotulski).
+ BF: Strange behaviour when opening the YankRing with
+ :e [YankRing] instead of :YRShow (Marcin Szamotulski).
+
13.0: February 5, 2012
NF: [p, ]p, [P, ]P are now supported within the YankRing
window (Alexandre Provencio).
View
596 plugin/yankring.vim
@@ -1,9 +1,9 @@
" yankring.vim - Yank / Delete Ring for Vim
" ---------------------------------------------------------------
-" Version: 13.0
+" Version: 14.0
" Author: David Fishburn <dfishburn dot vim at gmail dot com>
" Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
-" Last Modified: 2012 Feb 24
+" Last Modified: 2012 Mar 23
" 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
@@ -19,7 +19,7 @@ if v:version < 700
finish
endif
-let loaded_yankring = 130
+let loaded_yankring = 140
" Turn on support for line continuations when creating the script
let s:cpo_save = &cpo
@@ -47,7 +47,7 @@ elseif g:yankring_max_history < 0
let g:yankring_max_history = 100
endif
-" Specify the minimum length of 1 entry
+" Specify the minimum length of 1 entry
if !exists('g:yankring_min_element_length')
let g:yankring_min_element_length = 1
endif
@@ -99,7 +99,7 @@ if !exists('g:yankring_window_height')
let g:yankring_window_height = 8
endif
-" When displaying the buffer, how many lines should it be
+" When displaying the buffer, how many columns should it be
if !exists('g:yankring_window_width')
let g:yankring_window_width = 30
endif
@@ -128,7 +128,7 @@ endif
" The default is based on cpoptions: |cpo-y|
" y A yank command can be redone with ".".
if !exists('g:yankring_dot_repeat_yank')
- let g:yankring_dot_repeat_yank = (&cpoptions=~'y'?1:0)
+ let g:yankring_dot_repeat_yank = (s:cpo_save=~'y'?1:0)
endif
" Only adds unique items to the yankring.
@@ -141,7 +141,7 @@ endif
" Vim automatically manages the numbered registers:
" 0 - last yanked text
" 1-9 - last deleted items
-" If this option is turned on, the yankring will manage the
+" If this option is turned on, the yankring will manage the
" values in them.
if !exists('g:yankring_manage_numbered_reg')
let g:yankring_manage_numbered_reg = 0
@@ -168,7 +168,7 @@ if !exists('g:yankring_o_keys')
endif
if !exists('g:yankring_zap_keys')
- let g:yankring_zap_keys = 'f F t T / ? @'
+ let g:yankring_zap_keys = 'f F t T / ?'
endif
" Allow the user to specify what operator pending motions to map
@@ -228,12 +228,13 @@ if !exists('g:yankring_clipboard_monitor')
endif
if !exists('g:yankring_manual_clipboard_check')
- if g:yankring_clipboard_monitor == 1
- if has("gui_running")
- " FocusGained event will take care of
+ let g:yankring_manual_clipboard_check = 0
+ if g:yankring_clipboard_monitor == 1
+ if has("gui_running")
+ " FocusGained event will take care of
" monitoring the clipboard.
let g:yankring_manual_clipboard_check = 0
- else
+ else
" If the GUI is not running and the user wants to monitor the
" clipboard, we need to manually check for clipboard entries as
" the FocusGained event does not fire in console mode.
@@ -259,12 +260,12 @@ let s:yr_history_v1_nl_pat = '\%(\\\)\@<!@@@'
let s:yr_history_v2_nl = "\2" " Use double quotes for a special character
let s:yr_history_v2_nl_pat = "\2"
let s:yr_history_last_upd = 0
-let s:yr_history_file_v1 =
+let s:yr_history_file_v1 =
\ g:yankring_history_dir.'/'.
\ g:yankring_history_file.
\ (g:yankring_share_between_instances==1?'':'_'.v:servername).
\ '.txt'
-let s:yr_history_file_v2 =
+let s:yr_history_file_v2 =
\ g:yankring_history_dir.'/'.
\ g:yankring_history_file.
\ (g:yankring_share_between_instances==1?'':'_'.v:servername).
@@ -277,7 +278,7 @@ let s:yr_maps_created = 0
let s:yr_maps_created_zap = 0
let s:yr_last_motion = ''
-" Enables or disables the yankring
+" Enables or disables the yankring
function! s:YRToggle(...)
" Default the current state to toggle
let new_state = ((g:yankring_enabled == 1) ? 0 : 1)
@@ -286,9 +287,9 @@ function! s:YRToggle(...)
if a:0 > 0
let new_state = ((a:1 == 1) ? 1 : 0)
endif
-
+
" YRToggle accepts an integer value to specify the state
- if new_state == g:yankring_enabled
+ if new_state == g:yankring_enabled
return
elseif new_state == 1
call s:YRMapsCreate()
@@ -298,16 +299,15 @@ function! s:YRToggle(...)
call s:YRWarningMsg('YR: The YankRing is now disabled')
endif
endfunction
-
-" Enables or disables the yankring
-function! s:YRDisplayElem(disp_nbr, script_var)
+" Enables or disables the yankring
+function! s:YRDisplayElem(disp_nbr, script_var)
if g:yankring_max_display == 0
if g:yankring_window_use_separate == 1
let max_display = 500
else
- let max_display = g:yankring_window_width +
- \ g:yankring_window_increment -
+ let max_display = g:yankring_window_width +
+ \ g:yankring_window_increment -
\ 12
endif
else
@@ -340,22 +340,30 @@ function! s:YRDisplayElem(disp_nbr, script_var)
return ""
endfunction
-
-" Enables or disables the yankring
-function! s:YRShow(...)
+" Enables or disables the yankring
+function! s:YRShow(...)
+ " Prevent recursion
+ if exists('s:yankring_showing') && s:yankring_showing == 1
+ " call s:YRWarningMsg('YR: YRShow aborting for recursion')
+ return
+ endif
+
if g:yankring_enabled == 0
call s:YRWarningMsg('YR: The YankRing is disabled, use YRToggle to re-enable')
return
endif
- " If the GUI is not running, we need to manually check for clipboard
+ " Prevent recursion
+ let s:yankring_showing = 1
+
+ " If the GUI is not running, we need to manually check for clipboard
" entries as the FocusGained event does not fire in console mode.
if g:yankring_manual_clipboard_check == 1
call s:YRCheckClipboard()
endif
- " If no parameter was provided assume the user wants to
+ " If no parameter was provided assume the user wants to
" toggle the display.
let toggle = 1
if a:0 > 0
@@ -380,6 +388,9 @@ function! s:YRShow(...)
exec s:yr_buffer_last_winnr . "wincmd w"
endif
+ " Prevent recursion
+ let s:yankring_showing = 0
+
return
endif
endif
@@ -390,17 +401,17 @@ function! s:YRShow(...)
" always run the search again.
let s:yr_search = ""
- " It is possible for registers to be changed outside of the
+ " It is possible for registers to be changed outside of the
" maps of the YankRing. Perform this quick check when we
" show the contents (or when it is refreshed).
- if g:yankring_paste_check_default_buffer == 1
+ if g:yankring_paste_check_default_buffer == 1
let save_reg = 0
let register = ((&clipboard=~'\<unnamed\>')?'*':((&clipboard=~'\<unnamedplus\>' && has('unnamedplus'))?'+':'"'))
- if &clipboard =~ '\<unnamed\>' && getreg('*') != s:yr_prev_clipboard
+ if &clipboard =~ '\<unnamed\>' && getreg('*') != s:yr_prev_clipboard_star
let save_reg = 1
endif
- if has('unnamedplus') && &clipboard =~ '\<unnamedplus\>' && getreg('+') != s:yr_prev_clipboard
+ if has('unnamedplus') && &clipboard =~ '\<unnamedplus\>' && getreg('+') != s:yr_prev_clipboard_plus
let save_reg = 1
endif
if register == '"' && getreg('"') != s:yr_prev_reg_unnamed
@@ -409,7 +420,7 @@ function! s:YRShow(...)
if save_reg == 1
" The user has performed a yank / delete operation
- " outside of the yankring maps. Add this
+ " outside of the yankring maps. Add this
" value to the yankring.
call YRRecord(register)
endif
@@ -423,7 +434,7 @@ function! s:YRShow(...)
if show_registers == 1
for reg_name in map( range(char2nr('0'), char2nr('9')) +
\ (range(char2nr('a'), char2nr('z')))
- \, 'nr2char(v:val)'
+ \, 'nr2char(v:val)'
\ )
let output = output . s:YRDisplayElem(reg_name, getreg(reg_name).',') . "\n"
endfor
@@ -438,13 +449,16 @@ function! s:YRShow(...)
if g:yankring_window_use_separate == 1
call s:YRWindowOpen(output)
- else
+ else
echo output
endif
+
+ " Prevent recursion
+ let s:yankring_showing = 0
endfunction
-" Used in omaps if a following character is required
+" Used in omaps if a following character is required
" like with motions (f,t)
function! s:YRGetChar()
let msg = "YR:Enter character:"
@@ -458,7 +472,7 @@ function! s:YRGetChar()
endfunction
-" Used in omaps if a following string is required
+" Used in omaps if a following string is required
" like with motions (/,?)
" function! s:YRGetSearch()
" " let msg = "YR:Enter string:"
@@ -483,12 +497,12 @@ endfunction
" " endwhile
" return str
" endfunction
-
+
" Paste a certain item from the yankring
" If no parameter is provided, this function becomes interactive. It will
" display the list (using YRShow) and allow the user to choose an element.
-function! s:YRGetElem(...)
+function! s:YRGetElem(...)
if g:yankring_manual_clipboard_check == 1
call s:YRCheckClipboard()
endif
@@ -555,10 +569,10 @@ function! s:YRGetElem(...)
call s:YRSetPrevOP('p', '', default_buffer, 'n')
endfunction
-
+
" Starting the top of the ring it will paste x items from it
-function! s:YRGetMultiple(reverse_order, ...)
+function! s:YRGetMultiple(reverse_order, ...)
if g:yankring_manual_clipboard_check == 1
call s:YRCheckClipboard()
endif
@@ -605,12 +619,12 @@ function! s:YRGetMultiple(reverse_order, ...)
endwhile
endif
endfunction
-
+
" Given a regular expression, check each element within
" the yankring, display only the matching items and prompt
" the user for which item to paste
-function! s:YRSearch(...)
+function! s:YRSearch(...)
if s:yr_count == 0
call s:YRWarningMsg('YR: yankring is empty')
return
@@ -689,7 +703,7 @@ function! s:YRSearch(...)
endif
endfunction
-
+
" Resets the common script variables for managing the ring.
function! s:YRReset()
@@ -697,7 +711,7 @@ function! s:YRReset()
" Update the history file
call s:YRHistorySave()
endfunction
-
+
" Clears the yankring by simply setting the # of items in it to 0.
" There is no need physically unlet each variable.
@@ -714,11 +728,12 @@ function! s:YRInit(...)
let s:yr_prev_op_mode = 'n'
let s:yr_prev_count = ''
let s:yr_prev_reg = ''
- let s:yr_prev_reg_unnamed = ''
+ let s:yr_prev_reg_unnamed = getreg('"')
let s:yr_prev_reg_small = ''
let s:yr_prev_reg_insert = ''
let s:yr_prev_reg_expres = ''
- let s:yr_prev_clipboard = ''
+ let s:yr_prev_clipboard_star = ''
+ let s:yr_prev_clipboard_plus = ''
let s:yr_prev_vis_lstart = 0
let s:yr_prev_vis_lend = 0
let s:yr_prev_vis_cstart = 0
@@ -737,7 +752,7 @@ function! s:YRInit(...)
call s:YRHistoryRead()
endfunction
-
+
" Clears the yankring by simply setting the # of items in it to 0.
function! s:YRClear()
@@ -747,13 +762,13 @@ function! s:YRClear()
" If the yankring window is open, refresh it
call s:YRWindowUpdate()
endfunction
-
+
" Determine which register the user wants to use
" For example the 'a' register: "ayy
function! s:YRRegister()
" v:register can be blank in some (unknown) cases
- " so test for this condition and return the
+ " so test for this condition and return the
" default register
let user_register = ((v:register=='')?('"'):(v:register))
if &clipboard =~ '\<unnamed\>' && user_register == '"'
@@ -769,7 +784,7 @@ endfunction
" Allows you to push a new item on the yankring. Useful if something
" is in the clipboard and you want to add it to the yankring.
" Or if you yank something that is not mapped.
-function! s:YRPush(...)
+function! s:YRPush(...)
let user_register = s:YRRegister()
if a:0 > 0
@@ -782,7 +797,7 @@ function! s:YRPush(...)
" the default buffer as well so the next item pasted will
" be the item pushed
let default_buffer = ((&clipboard=~'\<unnamed\>')?'*':((&clipboard=~'\<unnamedplus\>' && has('unnamedplus'))?'+':'"'))
- call setreg(default_buffer, getreg(user_register),
+ call setreg(default_buffer, getreg(user_register),
\ getregtype(user_register))
call s:YRSetPrevOP('', '', '', 'n')
@@ -792,7 +807,7 @@ endfunction
" Allows you to pop off any element from the yankring.
" If no parameters are provided the first element is removed.
-" If a vcount is provided, that many elements are removed
+" If a vcount is provided, that many elements are removed
" from the top.
function! s:YRPop(...)
if s:yr_count == 0
@@ -801,12 +816,12 @@ function! s:YRPop(...)
endif
let v_count = 1
- if a:0 > 1
+ if a:0 > 1
let v_count = a:2
endif
- " If the user provided a parameter, remove that element
- " from the yankring.
+ " If the user provided a parameter, remove that element
+ " from the yankring.
" If no parameter was provided assume the first element.
let elem_index = 0
if a:0 > 0
@@ -814,10 +829,10 @@ function! s:YRPop(...)
let elem_index = matchstr(a:1, '\d\+')
let elem_index = elem_index - 1
endif
-
+
" If the user entered a count, then remove that many
" elements from the ring.
- while v_count > 0
+ while v_count > 0
call s:YRMRUDel('s:yr_history_list', elem_index)
let v_count = v_count - 1
endwhile
@@ -828,7 +843,7 @@ endfunction
" Adds this value to the yankring.
-function! YRRecord(...)
+function! YRRecord(...)
let register = '"'
if a:0 > 0
@@ -850,7 +865,7 @@ function! YRRecord(...)
if register == '"'
" If the change has occurred via an omap, we must delay
" the capture of the default register until this event
- " since register updates are not reflected until the
+ " since register updates are not reflected until the
" omap function completes
let s:yr_prev_reg_unnamed = getreg('"')
let s:yr_prev_reg_small = getreg('-')
@@ -860,16 +875,12 @@ function! YRRecord(...)
" This will also account for duplicates.
call s:YRMRUAdd( 's:yr_history_list'
\ , getreg(register)
- \ , getregtype(register)
+ \ , getregtype(register)
\ )
if g:yankring_clipboard_monitor == 1
- if register == '+'
- let s:yr_prev_clipboard = getreg('+')
- endif
- if register == '*'
- let s:yr_prev_clipboard = getreg('*')
- endif
+ let s:yr_prev_clipboard_plus = getreg('+')
+ let s:yr_prev_clipboard_star = getreg('*')
endif
" Manage the numbered registers
@@ -884,7 +895,7 @@ function! YRRecord(...)
" Reset the past paste entry to the top of the ring.
" When the user hits replace last entry it should
- " start from the top (not from the last previous
+ " start from the top (not from the last previous
" replace) after capturing a new value in the YankRing.
let s:yr_last_paste_idx = 1
@@ -893,69 +904,66 @@ endfunction
" Adds this value to the yankring.
-function! YRRecord3(...)
+function! YRRecord3(...)
let register = '"'
- " if a:0 > 0
- " " If no yank command has been supplied, assume it is
- " " a full line yank
- " let motion = ((a:1 == '') ? motion : a:1)
- " echomsg "YRRecord3 motion:".motion
- " endif
+ if a:0 > 0 && a:1 != ''
+ let register = a:1
+ else
+ " v:register can be blank in some (unknown) cases
+ " if v:register == '' || v:register == '_'
+ if v:register == '_'
+ " Black hole register, ignore recording the operation
+ return ""
+ endif
- " v:register can be blank in some (unknown) cases
- " if v:register == '' || v:register == '_'
- if v:register == '_'
- " Black hole register, ignore recording the operation
- return ""
- endif
+ let register = s:YRRegister()
+
+ if &clipboard =~ '\<unnamed\>' && register == '*'
+ " unnamed A variant of "unnamed" flag which uses the clipboard
+ " register '*' (|quote|) for all operations except yank.
+ " Yank shall copy the text into register '*' when "unnamed"
+ " is included.
+ "
+ let register = '*'
+
+ " The + and * registers are not modified by yank operations.
+ " We do not know what operation triggered this event so do a
+ " simple check if the register values have changed.
+ " If not, check it against the " register. Use which ever
+ " one has changed.
+ if s:yr_prev_clipboard_star == '' || getreg(register) == s:yr_prev_clipboard_star
+ if getreg('"') != getreg(register)
+ let register = '"'
+ endif
+ endif
+ endif
- let register = s:YRRegister()
-
- if &clipboard =~ '\<unnamed\>' && register == '*'
- " unnamed A variant of "unnamed" flag which uses the clipboard
- " register '*' (|quote|) for all operations except yank.
- " Yank shall copy the text into register '*' when "unnamed"
- " is included.
- "
- let register = '*'
-
- " The + and * registers are not modified by yank operations.
- " We do not know what operation triggered this event so do a
- " simple check if the register values have changed.
- " If not, check it against the " register. Use which ever
- " one has changed.
- if s:yr_prev_clipboard == '' || getreg(register) == s:yr_prev_clipboard
- if getreg('"') != getreg(register)
- let register = '"'
- endif
- endif
- endif
-
- if has('unnamedplus') && &clipboard =~ '\<unnamedplus\>' && register == '+'
- " unnamedplus A variant of "unnamed" flag which uses the clipboard
- " register '+' (|quoteplus|) instead of register '*' for all
- " operations except yank. Yank shall copy the text into
- " register '+' and also into '*' when "unnamed" is included.
- "
- let register = '+'
-
- " The + and * registers are not modified by yank operations.
- " We do not know what operation triggered this event so do a
- " simple check if the register values have changed.
- " If not, check it against the " register. Use which ever
- " one has changed.
- if s:yr_prev_clipboard == '' || getreg(register) == s:yr_prev_clipboard
- if getreg('"') != getreg(register)
- let register = '"'
- endif
- endif
+ if has('unnamedplus') && &clipboard =~ '\<unnamedplus\>' && register == '+'
+ " unnamedplus A variant of "unnamed" flag which uses the clipboard
+ " register '+' (|quoteplus|) instead of register '*' for all
+ " operations except yank. Yank shall copy the text into
+ " register '+' and also into '*' when "unnamed" is included.
+ "
+ let register = '+'
+
+ " The + and * registers are not modified by yank operations.
+ " We do not know what operation triggered this event so do a
+ " simple check if the register values have changed.
+ " If not, check it against the " register. Use which ever
+ " one has changed.
+ if s:yr_prev_clipboard_plus == '' || getreg(register) == s:yr_prev_clipboard_plus
+ if getreg('"') != getreg(register)
+ let register = '"'
+ endif
+ endif
+ endif
endif
if register == '"'
" If the change has occurred via an omap, we must delay
" the capture of the default register until this event
- " since register updates are not reflected until the
+ " since register updates are not reflected until the
" omap function completes
let s:yr_prev_reg_unnamed = getreg('"')
let s:yr_prev_reg_small = getreg('-')
@@ -969,16 +977,12 @@ function! YRRecord3(...)
" This will also account for duplicates.
call s:YRMRUAdd( 's:yr_history_list'
\ , getreg(register)
- \ , getregtype(register)
+ \ , getregtype(register)
\ )
if g:yankring_clipboard_monitor == 1
- if register == '+'
- let s:yr_prev_clipboard = getreg('+')
- endif
- if register == '*'
- let s:yr_prev_clipboard = getreg('*')
- endif
+ let s:yr_prev_clipboard_plus = getreg('+')
+ let s:yr_prev_clipboard_star = getreg('*')
endif
" Manage the numbered registers
@@ -993,7 +997,7 @@ function! YRRecord3(...)
" Reset the past paste entry to the top of the ring.
" When the user hits replace last entry it should
- " start from the top (not from the last previous
+ " start from the top (not from the last previous
" replace) after capturing a new value in the YankRing.
let s:yr_last_paste_idx = 1
@@ -1002,7 +1006,7 @@ endfunction
" Record the operation for the dot operator
-function! s:YRSetPrevOP(op_code, count, reg, mode)
+function! s:YRSetPrevOP(op_code, count, reg, mode)
let s:yr_prev_op_code = a:op_code
let s:yr_prev_op_mode = a:mode
let s:yr_prev_count = a:count
@@ -1045,7 +1049,7 @@ endfunction
" Adds this value to the yankring.
-function! s:YRDoRepeat()
+function! s:YRDoRepeat()
let dorepeat = 0
if s:yr_has_voperator == 1
@@ -1075,7 +1079,7 @@ function! s:YRDoRepeat()
\ s:yr_prev_chg_lstart == line("'[") &&
\ s:yr_prev_chg_lend == line("']") &&
\ s:yr_prev_chg_cstart == col("'[") &&
- \ s:yr_prev_chg_cend == col("']")
+ \ s:yr_prev_chg_cend == col("']")
let dorepeat = 1
endif
else
@@ -1102,7 +1106,7 @@ function! s:YRDoRepeat()
" if s:yr_prev_chg_lstart == line("'[") &&
" \ s:yr_prev_chg_lend == line("']") &&
" \ s:yr_prev_chg_cstart == col("'[") &&
- " \ s:yr_prev_chg_cend == col("']")
+ " \ s:yr_prev_chg_cend == col("']")
" let dorepeat = 1
" endif
elseif dorepeat == 1 && s:yr_prev_op_mode == 'o'
@@ -1112,7 +1116,7 @@ function! s:YRDoRepeat()
" if s:yr_prev_chg_lstart == line("'[") &&
" \ s:yr_prev_chg_lend == line("']") &&
" \ s:yr_prev_chg_cstart == col("'[") &&
- " \ s:yr_prev_chg_cend == col("']")
+ " \ s:yr_prev_chg_cend == col("']")
" let dorepeat = 1
" endif
endif
@@ -1124,7 +1128,7 @@ function! s:YRDoRepeat()
" " If the previous op was a change, do not use the yankring
" " to repeat it.
" " changenr() is buffer specific, so anytime you move to
- " " a different buffer you will definitely perform a
+ " " a different buffer you will definitely perform a
" " standard "."
" " Any previous op that was a change, must be replaced using "."
" " since we do not want the user prompted to enter text again.
@@ -1146,7 +1150,7 @@ endfunction
" Manages the Vim's numbered registers
-function! s:YRSetNumberedReg()
+function! s:YRSetNumberedReg()
let i = 0
@@ -1175,7 +1179,7 @@ endfunction
" This internal function will add and subtract values from a starting
" point and return the correct element number. It takes into account
" the circular nature of the yankring.
-function! s:YRGetNextElem(start, iter)
+function! s:YRGetNextElem(start, iter)
let needed_elem = a:start + a:iter
@@ -1211,7 +1215,7 @@ endfunction
" Supports this for example - 5"ayy
"
" This is a legacy function now since the release of Vim 7.2
-" and the use of omaps with YankRing 5.0 and above.
+" and the use of omaps with YankRing 5.0 and above.
" If Vim 7.1 has patch205, then the new omaps and the v:operator
" variable is used instead.
function! s:YRYankCount(...) range
@@ -1257,12 +1261,12 @@ function! s:YRYankCount(...) range
" Black hole register, ignore recording the operation
return
endif
-
+
call s:YRSetPrevOP(op_code, v_count, user_register, 'n')
call YRRecord(user_register)
endfunction
-
+
" Handles ranges. There are visual ranges and command line ranges.
" Visual ranges are easy, since we pass through and let Vim deal
@@ -1282,8 +1286,8 @@ function! s:YRYankRange(do_delete_selection, ...) range
let cmd_mode = ((a:1 == 'v') ? 'v' : 'n')
endif
- if cmd_mode == 'v'
- " We are yanking either an entire line, or a range
+ if cmd_mode == 'v'
+ " We are yanking either an entire line, or a range
exec "normal! gv".
\ (user_register==default_buffer?'':'"'.user_register).
\ 'y'
@@ -1307,21 +1311,21 @@ function! s:YRYankRange(do_delete_selection, ...) range
" Black hole register, ignore
return
endif
-
+
call s:YRSetPrevOP('', '', user_register, 'n')
call YRRecord(user_register)
endfunction
-
+
" Paste from either the yankring or from a specified register
-" Optionally a count can be provided, so paste the same value 10 times
-function! s:YRPaste(replace_last_paste_selection, nextvalue, direction, ...)
+" Optionally a count can be provided, so paste the same value 10 times
+function! s:YRPaste(replace_last_paste_selection, nextvalue, direction, ...)
if g:yankring_manual_clipboard_check == 1
call s:YRCheckClipboard()
endif
" Disabling the yankring removes the default maps.
- " But there are some maps the user can create on their own, and
+ " But there are some maps the user can create on their own, and
" these would most likely call this function. So place an extra
" check and display a message.
if g:yankring_enabled == 0
@@ -1330,7 +1334,7 @@ function! s:YRPaste(replace_last_paste_selection, nextvalue, direction, ...)
\ )
return
endif
-
+
let user_register = s:YRRegister()
let default_buffer = ((&clipboard=~'\<unnamed\>')?'*':((&clipboard=~'\<unnamedplus\>' && has('unnamedplus'))?'+':'"'))
let v_count = v:count
@@ -1343,7 +1347,7 @@ function! s:YRPaste(replace_last_paste_selection, nextvalue, direction, ...)
let cmd_mode = ((a:1 == 'v') ? 'v' : 'n')
endif
- " User has decided to bypass the yankring and specify a specific
+ " User has decided to bypass the yankring and specify a specific
" register
if user_register != default_buffer
if a:replace_last_paste_selection == 1
@@ -1386,15 +1390,15 @@ function! s:YRPaste(replace_last_paste_selection, nextvalue, direction, ...)
" The user could have:
" let @" = 'test string'
" would not be in the yankring as no mapping triggered this action.
- if a:replace_last_paste_selection != 1
+ if a:replace_last_paste_selection != 1
" Only check the default buffer is the user wants us to.
- " This was necessary prior to version 4.0 since we did not
+ " This was necessary prior to version 4.0 since we did not
" capture as many items as 4.0 and above does. (A. Budden)
- if g:yankring_paste_check_default_buffer == 1
+ if g:yankring_paste_check_default_buffer == 1
if ( default_buffer == '"' && getreg(default_buffer) != s:yr_prev_reg_unnamed )
" There are only a couple of scenarios where this would happen
" 1. set clipboard = unnamed[plus]
- " The user performs an action which changes the
+ " The user performs an action which changes the
" unnamed register (i.e. x - delete character)
" 2. Any type of direct manipulation of the registers
" let @" = 'something'
@@ -1404,21 +1408,30 @@ function! s:YRPaste(replace_last_paste_selection, nextvalue, direction, ...)
endif
" The user has performed a yank / delete operation
- " outside of the yankring maps. First, add this
+ " outside of the yankring maps. First, add this
" value to the yankring.
call YRRecord(default_buffer)
- elseif ( default_buffer != '"' &&
+ elseif ( default_buffer == '+' &&
\ len(getreg(default_buffer)) != 0 &&
- \ getreg(default_buffer) != s:yr_prev_clipboard
+ \ getreg(default_buffer) != s:yr_prev_clipboard_plus
\ )
" The user has performed a yank / delete operation
- " outside of the yankring maps. First, add this
+ " outside of the yankring maps. First, add this
+ " value to the yankring.
+ call YRRecord(default_buffer)
+ elseif ( default_buffer == '*' &&
+ \ len(getreg(default_buffer)) != 0 &&
+ \ getreg(default_buffer) != s:yr_prev_clipboard_star
+ \ )
+
+ " The user has performed a yank / delete operation
+ " outside of the yankring maps. First, add this
" value to the yankring.
call YRRecord(default_buffer)
endif
endif
-
+
exec "normal! ".
\ ((cmd_mode=='n') ? "" : "gv").
\ ((v_count > 0)?(v_count):'').
@@ -1430,8 +1443,8 @@ function! s:YRPaste(replace_last_paste_selection, nextvalue, direction, ...)
endif
" if s:yr_count > 0 || (
- " \ default_buffer != '"' &&
- " \ len(getreg(default_buffer)) == 0
+ " \ default_buffer != '"' &&
+ " \ len(getreg(default_buffer)) == 0
" \ )
" " Nothing to paste
" return
@@ -1451,7 +1464,7 @@ function! s:YRPaste(replace_last_paste_selection, nextvalue, direction, ...)
return
endif
- " If a count was provided (ie 5<C-P>), multiply the
+ " If a count was provided (ie 5<C-P>), multiply the
" nextvalue accordingly and position the next paste index
" let which_elem = a:nextvalue * ((v_count > 0)?(v_count):1) * -1
let which_elem = matchstr(a:nextvalue, '-\?\d\+') * ((v_count > 0)?(v_count):1) * -1
@@ -1470,7 +1483,7 @@ function! s:YRPaste(replace_last_paste_selection, nextvalue, direction, ...)
exec "normal! u"
" Check if the visual selection should be reselected
" Next paste the correct item from the ring
- " This is done as separate statements since it appeared that if
+ " This is done as separate statements since it appeared that if
" there was nothing to undo, the paste never happened.
exec "normal! ".
\ ((s:yr_prev_vis_mode==0) ? "" : "gv").
@@ -1505,7 +1518,7 @@ function! s:YRPaste(replace_last_paste_selection, nextvalue, direction, ...)
let s:yr_prev_vis_mode = ((cmd_mode=='n') ? 0 : 1)
endif
endfunction
-
+
" Handle any omaps
function! YRMapsExpression(sid, motion, ...)
@@ -1547,9 +1560,9 @@ function! YRMapsExpression(sid, motion, ...)
" There are a variety of commands which do not change the
" registers, so these operators should be ignored when
" determining which operations to record
- " Simple example is '=' which simply formats the
+ " Simple example is '=' which simply formats the
" the selected text.
- if ' \('.escape(join(split(g:yankring_ignore_operator), '\|'), '/.*~$^[]' ).'\) ' !~ escape(v:operator, '/.*~$^[]')
+ if ' \('.escape(join(split(g:yankring_ignore_operator), '\|'), '/.*~$^[]' ).'\) ' !~ escape(v:operator, '/.*~$^[]')
" Check if we are performing an action that will
" take us into insert mode
if '[cCsS]' !~ escape(v:operator, '/.*~$^[]') && a:motion !~ '@'
@@ -1565,64 +1578,65 @@ 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
- " YRRecord3() will use this value to determine what operation
- " the user just initiated.
+ " YRRecord3() will use this value to determine what operation
+ " the user just initiated.
let s:yr_last_motion = cmds
" echomsg "YRMapsE 5:".a:motion.":'".cmds."':".s:yr_maps_created_zap
return cmds
-
+
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
-
+function! s:YRMapsMacro(bang, ...)
+ " 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 macro" )
+ 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
+ let cmd = "normal! ".v_count.'@'.zapto
+ " DEBUG
+ " echomsg cmd
+ exec cmd
+
+ call s:YRMapsCreate('add_only_zap_keys')
+endfunction
+
" Create the default maps
function! s:YRMapsCreate(...)
- " 7.1.patch205 introduces the v:operator function which was
+ " 7.1.patch205 introduces the v:operator function which was
" essential to gain the omap support.
if s:yr_has_voperator == 1
let s:yr_remove_omap_dot = 1
@@ -1636,7 +1650,8 @@ function! s:YRMapsCreate(...)
endfor
endif
- silent! nmap <expr> @ YRMapsExpression("<SID>", "@", "1")
+ " silent! nmap <expr> @ YRMapsExpression("<SID>", "@", "1")
+ silent! nmap @ :<C-U>YRMapsMacro<CR>
let s:yr_maps_created_zap = 1
@@ -1719,12 +1734,12 @@ function! s:YRMapsCreate(...)
let g:yankring_enabled = 1
let s:yr_maps_created = 1
- if exists('*YRRunAfterMaps')
+ if exists('*YRRunAfterMaps')
" This will allow you to override the default maps if necessary
call YRRunAfterMaps()
endif
endfunction
-
+
" Create the default maps
function! s:YRMapsDelete(...)
@@ -1732,6 +1747,7 @@ function! s:YRMapsDelete(...)
let o_maps = split(g:yankring_zap_keys)
for key in o_maps
try
+ " Why not remove the @ map?
if key != '@'
silent! exec 'ounmap' key
endif
@@ -1766,7 +1782,7 @@ function! s:YRMapsDelete(...)
endtry
endfor
- if g:yankring_map_dot == 1
+ if g:yankring_map_dot == 1
silent! exec "nunmap ."
endif
if g:yankring_v_key != ''
@@ -1807,7 +1823,7 @@ function! s:YRMapsDelete(...)
silent! exec 'nunmap '.g:yankring_replace_n_nkey
endif
- silent! exec 'nunmap @'
+ " silent! exec 'nunmap @'
let g:yankring_enabled = 0
let s:yr_maps_created = 0
@@ -1826,7 +1842,7 @@ function! s:YRGetValElemNbr( position, type )
let elem = matchstr(elem, '^.*\ze,.*$')
if s:yr_history_version == 'v1'
" Match three @@@ in a row as long as it is not
- " preceeded by a @@@
+ " preceeded by a @@@
" v1
let elem = substitute(elem, s:yr_history_v1_nl_pat, "\n", 'g')
let elem = substitute(elem, '\\@', '@', 'g')
@@ -1918,7 +1934,7 @@ function! s:YRMRUAdd( mru_list, element, element_type )
let found = s:YRMRUHas(a:mru_list, elem)
- " Special case for efficiency, if it is first item in the
+ " Special case for efficiency, if it is first item in the
" List, do nothing
if found != 0
if found != -1
@@ -1933,7 +1949,7 @@ function! s:YRMRUAdd( mru_list, element, element_type )
endfunction
function! s:YRMRUDel( mru_list, elem_nbr )
- if a:elem_nbr >= 0 && a:elem_nbr < s:yr_count
+ if a:elem_nbr >= 0 && a:elem_nbr < s:yr_count
call remove({a:mru_list}, a:elem_nbr)
call s:YRHistorySave()
endif
@@ -1956,7 +1972,7 @@ function! s:YRHistoryDelete()
endif
return 0
-endfunction
+endfunction
function! s:YRHistoryRead()
let refresh_needed = 1
@@ -1993,7 +2009,7 @@ function! s:YRHistoryRead()
let s:yr_history_list = yr_history_list
call s:YRHistorySave()
-endfunction
+endfunction
function! s:YRHistorySave()
let yr_filename = s:yr_history_file_{s:yr_history_version}
@@ -2014,7 +2030,7 @@ function! s:YRHistorySave()
\ yr_filename
\ )
endif
-endfunction
+endfunction
function! s:YRHistoryUpgrade(version)
if a:version == 'v1'
@@ -2038,7 +2054,7 @@ function! s:YRHistoryUpgrade(version)
\ )
endif
endif
-endfunction
+endfunction
" YRWindowUpdate
" Checks if the yankring window is already open.
@@ -2069,14 +2085,14 @@ function! s:YRWindowStatus(show_help)
return ""
endif
" Switch to the yankring buffer
- if orig_win_bufnr != yr_win_bufnr
+ if orig_win_bufnr != yr_win_bufnr
" If the buffer is visible, switch to it
exec yr_win_bufnr . "wincmd w"
endif
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,R,q,<space>;Help=?'.
+ \ ';Cmds:<enter>,[g]p,[g]P,1-9,d,r,s,a,c,u,R,q,<space>;Help=?'.
\ (s:yr_search==""?"":';SearchRegEx='.s:yr_search)
if s:yr_has_voperator == 0
@@ -2086,11 +2102,13 @@ function! s:YRWindowStatus(show_help)
" Toggle help by checking the first line of the buffer
if a:show_help == 1 && getline(1) !~ 'selection'
let full_help = 1
- let msg =
+ let msg =
\ '" <enter> : [p]aste selection'."\n".
\ '" double-click : [p]aste selection'."\n".
\ '" [g]p : [g][p]aste selection'."\n".
\ '" [g]P : [g][P]aste selection'."\n".
+ \ '" 1-9 : Paste # entry from the YankRing (shortcut for speed)'."\n".
+ \ '" d : [d]elete item from the YankRing'."\n".
\ '" r : [p]aste selection in reverse order'."\n".
\ '" s : [s]earch the yankring for text'."\n".
\ '" u : [u]pdate display show YankRing'."\n".
@@ -2101,8 +2119,9 @@ function! s:YRWindowStatus(show_help)
\ '" ? : Remove help text'."\n".
\ '" <space> : toggles the width of the window'."\n".
\ '" Visual mode is supported for above commands'."\n".
+ \ '" YankRing Version: '.g:loaded_yankring."\n".
\ msg
- endif
+ endif
let saveMod = &modifiable
@@ -2126,7 +2145,7 @@ function! s:YRWindowStatus(show_help)
let &modifiable = saveMod
- if orig_win_bufnr != s:yr_buffer_id
+ if orig_win_bufnr != s:yr_buffer_id
exec orig_win_bufnr . "wincmd w"
endif
endfunction
@@ -2136,9 +2155,11 @@ endfunction
function! s:YRWindowOpen(results)
" Setup the cpoptions properly for the maps to work
+ " and to not set the alternate buffer
let old_cpoptions = &cpoptions
set cpoptions&vim
- setlocal cpoptions-=a,A
+ set cpoptions-=a
+ set cpoptions-=A
" Save the current buffer number. The yankring will switch back to
" this buffer when an action is taken.
@@ -2184,19 +2205,19 @@ function! s:YRWindowOpen(results)
endif
" Special consideration was involved with these sequence
- " of commands.
+ " of commands.
" First, split the current buffer.
" Second, edit a new file.
" Third record the buffer number.
" If a different sequence is followed when the yankring
" buffer is closed, Vim's alternate buffer is the yanking
- " instead of the original buffer before the yankring
+ " instead of the original buffer before the yankring
" was shown.
let cmd_mod = ''
if v:version >= 700
let cmd_mod = 'keepalt '
endif
- exec 'silent! ' . cmd_mod . location . ' ' . win_size . 'split '
+ exec 'silent! ' . cmd_mod . location . ' ' . win_size . 'split '
" Using :e and hide prevents the alternate buffer
" from being changed.
@@ -2227,6 +2248,7 @@ function! s:YRWindowOpen(results)
setlocal nonumber
setlocal nobuflisted
setlocal noreadonly
+ setlocal nospell
setlocal modifiable
" set up syntax highlighting
@@ -2291,6 +2313,15 @@ function! s:YRWindowOpen(results)
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> 1 :call <SID>YRWindowAction ('q' ,'n')<CR>:call <SID>YRGetElem(1)<CR>
+ nnoremap <buffer> <silent> 2 :call <SID>YRWindowAction ('q' ,'n')<CR>:call <SID>YRGetElem(2)<CR>
+ nnoremap <buffer> <silent> 3 :call <SID>YRWindowAction ('q' ,'n')<CR>:call <SID>YRGetElem(3)<CR>
+ nnoremap <buffer> <silent> 4 :call <SID>YRWindowAction ('q' ,'n')<CR>:call <SID>YRGetElem(4)<CR>
+ nnoremap <buffer> <silent> 5 :call <SID>YRWindowAction ('q' ,'n')<CR>:call <SID>YRGetElem(5)<CR>
+ nnoremap <buffer> <silent> 6 :call <SID>YRWindowAction ('q' ,'n')<CR>:call <SID>YRGetElem(6)<CR>
+ nnoremap <buffer> <silent> 7 :call <SID>YRWindowAction ('q' ,'n')<CR>:call <SID>YRGetElem(7)<CR>
+ nnoremap <buffer> <silent> 8 :call <SID>YRWindowAction ('q' ,'n')<CR>:call <SID>YRGetElem(8)<CR>
+ nnoremap <buffer> <silent> 9 :call <SID>YRWindowAction ('q' ,'n')<CR>:call <SID>YRGetElem(9)<CR>
nnoremap <buffer> <silent> <space> \|:silent exec 'vertical resize '.
\ (
\ g:yankring_window_use_horiz!=1 && winwidth('.') > g:yankring_window_width
@@ -2301,7 +2332,7 @@ function! s:YRWindowOpen(results)
" Erase it's contents to the blackhole
silent! exec '%delete _'
- " Display the status line / help
+ " Display the status line / help
call s:YRWindowStatus(0)
exec 'normal! G'
@@ -2315,7 +2346,7 @@ function! s:YRWindowOpen(results)
" Move the cursor to the first line with an element
exec 0
- call search('^\d','W')
+ call search('^\d','W')
setlocal nomodifiable
"
@@ -2324,7 +2355,7 @@ function! s:YRWindowOpen(results)
endfunction
-function! s:YRWindowActionN(op, cmd_mode)
+function! s:YRWindowActionN(op, cmd_mode)
let v_count = v:count
" If no count was specified it will have a value of 0
" so set it to at least 1
@@ -2343,18 +2374,18 @@ function! s:YRWindowActionN(op, cmd_mode)
endif
return
endif
-
+
call s:YRWindowAction(a:op, a:cmd_mode)
let v_count = v_count - 1
if g:yankring_window_auto_close == 1 && v_count == 0 && a:op != 'd'
- " If autoclose is set close the window unless
+ " If autoclose is set close the window unless
" you are removing items from the YankRing
exec 'bdelete '.s:yr_buffer_id
- return ""
+ return ""
endif
- return ""
+ return ""
endfunction
function! s:YRWindowAction(op, cmd_mode) range
@@ -2382,17 +2413,17 @@ function! s:YRWindowAction(op, cmd_mode) range
" so set it to at least 1
let v_count = ((v_count > 0)?(v_count):1)
- if '[dr]' =~ opcode
+ if '[dr]' =~ opcode
" Reverse the order of the lines to act on
let begin = lastline
- while begin >= firstline
+ while begin >= firstline
call add(lines, getline(begin))
let begin = begin - 1
endwhile
else
" Process the selected items in order
let begin = firstline
- while begin <= lastline
+ while begin <= lastline
call add(lines, getline(begin))
let begin = begin + 1
endwhile
@@ -2418,48 +2449,48 @@ function! s:YRWindowAction(op, cmd_mode) range
elseif opcode ==# 's'
" Switch back to the original buffer
exec s:yr_buffer_last_winnr . "wincmd w"
-
+
call s:YRSearch()
return
elseif opcode ==# 'u'
" Switch back to the original buffer
exec s:yr_buffer_last_winnr . "wincmd w"
-
+
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
- let g:yankring_window_auto_close =
+ let g:yankring_window_auto_close =
\ (g:yankring_window_auto_close == 1?0:1)
- " Display the status line / help
+ " Display the status line / help
call s:YRWindowStatus(0)
call cursor(l:curr_line,0)
return
elseif opcode ==# 'c'
let l:curr_line = line(".")
" Toggle the clipboard monitor setting
- let g:yankring_clipboard_monitor =
+ let g:yankring_clipboard_monitor =
\ (g:yankring_clipboard_monitor == 1?0:1)
- " Display the status line / help
+ " Display the status line / help
call s:YRWindowStatus(0)
call cursor(l:curr_line,0)
return
elseif opcode ==# '?'
- " Display the status line / help
+ " Display the status line / help
call s:YRWindowStatus(1)
return
endif
" Switch back to the original buffer
exec s:yr_buffer_last_winnr . "wincmd w"
-
+
" Intentional case insensitive comparision
if opcode =~? 'p'
let cmd = 'YRGetElem '
@@ -2475,7 +2506,7 @@ function! s:YRWindowAction(op, cmd_mode) range
" Only execute this code if we are operating on elements
" within the yankring
- if '[auq?]' !~# opcode
+ if '[auq?]' !~# opcode
while v_count > 0
" let iter = 0
" let index = 0
@@ -2499,37 +2530,44 @@ function! s:YRWindowAction(op, cmd_mode) range
if opcode ==# 'd'
call s:YRShow(0)
+ " Return the user to their last known position, assuming
+ " it is still available after the delete
+ if firstline < line("$")
+ call cursor(firstline,0)
+ else
+ call cursor(line("$"),0)
+ endif
return ""
endif
if g:yankring_window_auto_close == 1 && cmd_mode == 'v'
exec 'bdelete '.s:yr_buffer_id
- return ""
+ return ""
endif
endif
- return ""
+ return ""
endfunction
-
+
function! s:YRWarningMsg(msg)
echohl WarningMsg
- echomsg a:msg
+ echomsg a:msg
echohl None
endfunction
-
+
function! s:YRErrorMsg(msg)
echohl ErrorMsg
- echomsg a:msg
+ echomsg a:msg
echohl None
endfunction
-
+
function! s:YRWinLeave()
" Track which window we are last in. We will use this information
- " to determine where we need to paste any contents, or which
+ " to determine where we need to paste any contents, or which
" buffer to return to.
-
+
if s:yr_buffer_id < 0
" The yankring window has never been activated
return
@@ -2549,7 +2587,7 @@ function! s:YRWinLeave()
" let s:yr_buffer_last = -1
endif
endfunction
-
+
function! s:YRFocusGained()
" FocusGained is not available in general by console vim.
" There are some terminal windows which support it though.
@@ -2563,23 +2601,23 @@ function! s:YRFocusGained()
"
" Simple test, create the following autocmd and gain and loose focus in
" the terminal:
- " autocmd FocusLost * echomsg "focus lost"
- " autocmd FocusGained * echomsg "focus gained"
+ " autocmd FocusLost * echomsg "focus lost"
+ " autocmd FocusGained * echomsg "focus gained"
call s:YRCheckClipboard()
" If the yankring window is open, refresh it
call s:YRWindowUpdate()
endfunction
-
+
function! s:YRCheckClipboard()
if g:yankring_clipboard_monitor == 1
" If the clipboard has changed record it inside the yankring
- " echomsg "YRCheckClipboard[".len(@*)."][".@*.']['.s:yr_prev_clipboard.']'
+ " echomsg "YRCheckClipboard[".len(@*)."][".@*.']['.s:yr_prev_clipboard_star.']'
if has('unnamedplus') && &clipboard =~ '\<unnamedplus\>'
- if len(@+) > 0 && @+ != s:yr_prev_clipboard
- let elem = s:YRMRUElemFormat(
+ if len(@+) > 0 && @+ != s:yr_prev_clipboard_plus
+ let elem = s:YRMRUElemFormat(
\ getreg('+')
- \ , getregtype('+')
+ \ , getregtype('+')
\ )
let found = s:YRMRUHas('s:yr_history_list', elem)
@@ -2588,13 +2626,13 @@ function! s:YRCheckClipboard()
if found == -1
call YRRecord3("+")
endif
- let s:yr_prev_clipboard = @+
+ let s:yr_prev_clipboard_plus = @+
endif
else
- if len(@*) > 0 && @* != s:yr_prev_clipboard
- let elem = s:YRMRUElemFormat(
+ if len(@*) > 0 && @* != s:yr_prev_clipboard_star
+ let elem = s:YRMRUElemFormat(
\ getreg('*')
- \ , getregtype('*')
+ \ , getregtype('*')
\ )
let found = s:YRMRUHas('s:yr_history_list', elem)
@@ -2603,7 +2641,7 @@ function! s:YRCheckClipboard()
if found == -1
call YRRecord3("*")
endif
- let s:yr_prev_clipboard = @*
+ let s:yr_prev_clipboard_star = @*
endif
endif
endif
@@ -2611,33 +2649,33 @@ endfunction
function! s:YRInsertLeave()
" The YankRing uses omaps to execute the prescribed motion
- " and then appends to the motion a call to a YankRing
+ " and then appends to the motion a call to a YankRing
" function to record the contents of the changed register.
"
" We cannot append a function call to the end of a motion
" that results in Insert mode. For example, any command
" like 'cw' enters insert mode. Appending a function call
- " after the w, simply writes out the call as if the user
+ " after the w, simply writes out the call as if the user
" typed it.
"
- " Using the InsertLeave event, allows us to capture the
+ " Using the InsertLeave event, allows us to capture the
" contents of any changed register after it completes.
-
+
call YRRecord(s:YRRegister())
" When performing a change (not a yank or delete)
" it is not possible to call <SID>yrrecord at the end
- " of the command (or it's contents will be inserted
+ " of the command (or it's contents will be inserted
" into the buffer instead of executed).
" So, when using ".", we have to remove the _zap_
- " keys and then re-add them back again after we
+ " keys and then re-add them back again after we
" record the updates.
if s:yr_remove_omap_dot == 1
call s:YRMapsCreate('add_only_zap_keys')
endif
endfunction
-
+
" Deleting autocommands first is a good idea especially if we want to reload
" the script without restarting vim.
" Call YRFocusGained to check if the clipboard has been updated
@@ -2676,9 +2714,9 @@ command! -nargs=? YRToggle call s:YRToggle(<args>)
command! -nargs=? YRCheckClipboard call s:YRCheckClipboard(<args>)
command! -count -register -nargs=* YRYankCount call s:YRYankCount(<args>)
command! -range -bang -nargs=? YRYankRange <line1>,<line2>call s:YRYankRange(<bang>0, <args>)
-" command! -range -bang -nargs=0 YRMapsMacro <line1>,<line2>call s:YRMapsMacro(<bang>0, <args>)
+command! -count=1 -bang -nargs=0 YRMapsMacro call s:YRMapsMacro(<bang>0, <args>)
-" Menus
+" Menus
" 0: Turns the menu off.
if has("menu") && g:yankring_default_menu_mode != 0
if g:yankring_default_menu_mode == 1
@@ -2689,7 +2727,7 @@ if has("menu") && g:yankring_default_menu_mode != 0
" 2: Turns the 'Yankring 'menu on with <alt>-y as the shortcut.
let menuRoot = '&YankRing'
let menuPriority = ''
- elseif g:yankring_default_menu_mode == 3
+ elseif g:yankring_default_menu_mode == 3
" 3: Turns the 'Plugin -> YankRing' menu on with <alt>-y as the shortcut.
let menuRoot = exists("g:yankring_menu_root") ? g:yankring_menu_root : '&Plugin.&YankRing'
let menuPriority = exists("g:yankring_menu_priority") ? yankring_menu_priority : ''
Please sign in to comment.
Something went wrong with that request. Please try again.