Skip to content

Commit 2cf30ed

Browse files
dfishburnvim-scripts
authored andcommitted
Version 1.4
NF: YRToggle has been updated. If you toggle the yankring off (disable) the maps it creates are removed. Calling YRToggle again will recreate the maps. This truly disables the yankring, where the previous version attempted to do this via code. BF: Using the '.' operator was not corrected replaying operations that did not move text in some way (g~t_) changed the case of the text but a '.' did not replay it. BF: When replacing previously pasted text the yankring did not respect what key was used to paste the text originally. All replaced items were pasted using 'p', even if you had originally pasted the text with 'P'.
0 parents  commit 2cf30ed

File tree

3 files changed

+1770
-0
lines changed

3 files changed

+1770
-0
lines changed

README

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
This is a mirror of http://www.vim.org/scripts/script.php?script_id=1234
2+
3+
Vim already maintains a list of numbered registers containing the last 9 deletes. These previous deletes can be referenced using [register]p, so "1p will paste the last delete, "2p the 2nd last delete. For more information see |quote_number|.
4+
5+
Vim does not provide any mechanism to reference previous yanked, deleted or changed text. In Emacs this feature is called the "kill ring".
6+
7+
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.
8+
9+
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.
10+
11+
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.
12+
13+
A tutorial is included to take you through the various features of the plugin. After you have installed the plugin just run:
14+
:h yankring.txt
15+
:h yankring-tutorial
16+
17+
The yankring can be interacted with in two ways: a GUI or via maps.
18+
19+
The yankring supports all of Vim motions and text-objects. There are very few new keystrokes the user must learn. One keystroke to open the yankring to choose which item to paste is all that is required. It has been designed work seamlessly with Vim
20+
21+
All the mappings and behaviours are configurable via global variables you can optionally specify in your vimrc.
22+
23+
The plugin can be toggled on and off, and supports:
24+
Ranges
25+
Registers
26+
Counts
27+
All visual modes (characterwise, linewise and blockwise)
28+
All motions
29+
All text-objects
30+
31+
Examples:
32+
yy - Adds the current line to the yankring.
33+
dd - Adds the current line to the yankring and deletes it.
34+
5yw - Adds 5 words to the yankring.
35+
"ade - Deletes the word, and puts it into both the yankring and the "a register.
36+
cw - Changes the word and stores the previous value in the yankring.
37+
10"zyy - Places 10 lines into both the yankring and the "z register.
38+
:1,4YRYankRange - Similar to 1,4y
39+
:3,$YRDeleteRange - Similar to 3,$d
40+
41+
If you wish to paste previous values from the yankring and do not want to use the GUI, there are only two additional maps you must learn (these are configurable via your vimrc if needed). The purpose of the yankring is to gain access to previously yanked (or deleted) elements. The YRReplace command will replace the previously pasted text with a different entry from the yankring. By default, I choose <C-P> (P for previous) to replace the text last pasted while moving backwards through your previous text from the yankring and <C-N> (N for next) to replace the previous paste while moving forward through the yankring.
42+
43+
A separate buffer window to allow you to easily interact with the contents of the yankring. The window is similar to many other plugins: TagList, SelectBuf and so on. You can use the mouse or standard Vim keys (p, gp, P, ...). Visual mode is used to support counts, pasting multiple times and reversing the order of pasted elements.
44+
45+
The GUI significantly simplifies your interaction with the yankring for basic functions. But often it useful to take advantage of the more powerful features of the yankring.
46+
47+
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.
48+
49+
---- Partial Tutorial ----
50+
To understand how to use the yankring, the following example should demonstrate the various features.
51+
52+
Assume we have this buffer:
53+
one
54+
two
55+
three
56+
four
57+
five
58+
59+
Now yank (yy) each line separately starting at line 1. Display the
60+
contents of the yankring.
61+
:YRShow
62+
--- YankRing ---
63+
Elem Content
64+
5 five^@
65+
4 four^@
66+
3 three^@
67+
2 two^@
68+
1 one^@
69+
Since we yanked the text starting at line 1 and finishing at line 5, the most current yankring element is the last one, the contents of line 5.
70+
"five^@" is displayed, the "^@" is a newline character (since we issued a "yy").
71+
72+
Now, go to the end of the file and press p. The resulting buffer appears as:
73+
one
74+
two
75+
three
76+
four
77+
five
78+
five
79+
Now press <C-P> to move backwards through the yankring, this results in:
80+
one
81+
two
82+
three
83+
four
84+
five
85+
four
86+
Now press 2<C-P>. This would be the same as pressing <C-P> two times in a row. This results in:
87+
one
88+
two
89+
three
90+
four
91+
five
92+
two
93+
Now press <C-N> to move forwards through the yankring, this results in:
94+
one
95+
two
96+
three
97+
four
98+
five
99+
three
100+
101+
You can create a map to display a buffer displaying the yankring's contents:
102+
nnoremap <silent> <F11> :YRShow<CR>
103+
104+
YRShow creates a new split buffer (you can configure where it should be and it's size)
105+
:YRShow
106+
AutoClose=1;Cmds:<enter>,[g]p,[p]P,d,r,a,u,q,<space>;Help=?
107+
--- YankRing ---
108+
Elem Content
109+
3 three^@
110+
2 two^@
111+
1 one^@
112+
5 five^@
113+
4 four^@
114+
You can simply hit "p", <enter>, double click on an item and it will be pasted into your document. The window will automatically close (by default) after you have made a choice. The element will be pasted into the correct buffer if you have multiple split windows.
115+
116+
You can paste multiple items using visual mode.
117+
You can also remove items from the yankring.
118+
119+
---- Partial Tutorial ----
120+
121+
Concentrating on the last line of the buffer you could see how we were able to replace our pasted text with lines yanked previously. This is a feature Vim only has for deletes, and is limited to 9. This plugin enables the same features for both yanks, deletes and changes, the size of the history is configurable.
122+
123+
124+
125+

0 commit comments

Comments
 (0)