Permalink
Newer
Older
100644 171 lines (143 sloc) 6.86 KB
2
<title>Elvis-2.2_1 Cut Buffers</title>
4
5
<h1>11. CUT BUFFERS</h1>
6
When Elvis deletes text, it stores that text in a cut buffer.
7
This happens in both visual mode and EX mode.
8
There are 36 cut buffers:
9
26 named buffers ("a through "z),
10
9 anonymous buffers ("1 through "9),
11
and 1 extra cut buffer (".).
12
There is no practical limit to how much text a cut buffer can hold.
13
14
<h2>11.1 Putting text into a Cut Buffer</h2>
15
In visual mode, text is copied into a cut buffer when you use the
16
<a href="elvisvi.html#d">d,</a>
17
<a href="elvisvi.html#y">y,</a>
18
<a href="elvisvi.html#c">c,</a>
19
<a href="elvisvi.html#C">C,</a>
20
<a href="elvisvi.html#s">s,</a> or
21
<a href="elvisvi.html#x">x</a> commands.
22
There are also a few others.
23
24
<p>By default, the text goes into the "1 buffer.
25
The text that used to be in "1 gets shifted into "2,
26
"2 gets shifted into "3, and so on.
27
The text that used to be in "9 is lost.
28
This way, the last 9 things you deleted are still accessible.
29
30
<p>You can also put the text into a named buffer -- "a through "z.
31
To do this, you should type the buffer's name
32
(two keystrokes: a double-quote and a lowercase letter)
33
before the command that will cut the text.
34
When you do this, "1 through "9 are not affected by the cut.
35
36
<p>You can append text to one of the named buffers.
37
To do this, type the buffer's name in uppercase
38
(a double-quote and an uppercase letter)
39
before the d/y/c/C/s/x command.
40
41
<p>The ". buffer is special.
42
It isn't affected by the d/y/c/C/s/x command.
43
Instead, it stores the text that you typed in
44
the last time you were in input mode.
45
It is used to implement the <a href="elvisvi.html#stop">.</a> visual command,
46
and ^A in input mode.
47
48
<p>In EX mode,
49
the <a href="elvisex.html#delete">:delete,</a>
50
<a href="elvisex.html#change">:change,</a> and
51
<a href="elvisex.html#yank">:yank</a> commands all copy text into a cut buffer.
52
Like the visual commands, these EX commands normally use the "1 buffer,
53
but you can use one of the named buffers by giving its name after the command.
54
For example...
58
... will copy lines 20 through 30 into cut buffer "a.
59
60
<p>You can't directly put text into the ". buffer, or the "2 through "9 buffers.
61
62
<h2>11.2 Pasting from a Cut Buffer</h2>
63
There are two main styles of pasting:
64
line-mode and character-mode.
65
If a cut buffer contains whole lines (from a command like "dd")
66
then line-mode pasting is used;
67
if it contains partial lines (from a command like "dw")
68
then character-mode pasting is used.
69
The EX commands always cut whole lines.
70
71
<p>Elvis also supports a limited form of rectangular cut and paste.
72
This is handy, for example, when you want to swap two columns in a table.
73
The only way to put a rectangular area into a cut buffer is to select it
74
via the visual <a href="elvisvi.html#^V">^V</a> command, and then yank or delete
75
it with a <a href="elvisvi.html#y">y</a> or <a href="elvisvi.html#d">d</a>
76
command, respectively.
77
When a cut buffer has been filled this way, it will be pasted using
78
rectangle-mode pasting.
79
80
<p>Character-mode pasting causes the text to be inserted into the line that
81
the cursor is on.
82
83
<p>Line-mode pasting inserts the text on a new line above or below the line
84
that the cursor is on.
85
It doesn't affect the cursor's line at all.
86
87
<p>In visual mode, the
88
<a href="elvisvi.html#p">p</a> and
89
<a href="elvisvi.html#P">P</a>
90
commands insert text from a cut buffer.
91
Uppercase P will insert it before the cursor,
92
and lowercase p will insert it after the cursor.
93
Normally, these commands will paste from the "1 buffer, but you can
94
specify any other buffer to paste from.
95
Just type its name (a double-quote and another character)
96
before you type the P or p.
97
98
<p>In EX mode, the <a href="elvisex.html#put">:put</a> command pastes text
99
after a given line.
100
To paste from a buffer other that "1,
101
enter its name after the command.
102
103
<h2>11.3 Macros</h2>
104
The contents of a named cut buffer can be executed as a series of
105
ex/vi commands.
106
107
<p>To put the instructions into the cut buffer, you must first insert
108
them into the file, and then delete them into a named cut buffer.
109
110
<p>To execute a cut buffer's contents as EX commands,
111
you should give the EX command <a href="elvisex.html#AT">:@</a> and the name
112
of the buffer.
113
For example, <code>:@z</code> will execute "z as a series of EX commands.
114
115
<p>To execute a cut buffer's contents as visual commands,
116
you should give the visual command <a href="elvisvi.html#at">@</a>
117
and the letter of the buffer's name.
118
The visual <kbd>@</kbd> command is different from
119
the EX <code>:@</code> command.
120
They interpret the cut buffer's contents differently.
121
122
<p>The visual <kbd>@</kbd> command can be rather finicky.
123
Each character in the buffer is interpreted as a keystroke.
124
If you load the instructions into the cut buffer via a <kbd>"zdd</kbd> command,
125
then the newline character at the end of the line will be executed just
126
like any other character, so the cursor would be moved down 1 line.
127
If you don't want the cursor to move down 1 line at the end of each
128
<kbd>@z</kbd> command, then you should load the cut buffer by saying
129
<kbd>0"zD</kbd> instead.
131
<p>One way to store keystrokes into a buffer for use with
132
the visual <kbd>@</kbd> command is via the
133
<a href="elvisvi.html#recbegin">[key</a> and
134
<a href="elvisvi.html#recend">]key</a> commands.
135
They record keystrokes into a cut buffer as you type them.
137
<h2>11.4 The Effect of Switching Files</h2>
138
Elvis 2.x retains the contents of all cut buffers when you switch files,
139
e.g. via a <a href="elvisex.html#next">:next</a> or
140
<a href="elvisex.html#edit">:edit</a> command.
141
This differs from the traditional behavior of vi.
142
143
<p>In the real vi and in Elvis 1.X, the anonymous buffers ("1 through "9)
144
were clobbered and the named buffers ("a through "z) were left intact.
145
This made sense then, but since Elvis 2.x allows you to edit several files
146
at the same time, the rules changed.
147
148
<h2>11.5 Cut &amp; Paste Between Applications</h2>
149
There is a special cut buffer named "^ (doublequote-caret) which accesses
150
the GUI's cut&amp;paste feature. Each time you yank text into the "^
151
cut buffer, it is copied to the GUI's clipboard. Each time you paste
152
text from the "^ cut buffer, Elvis reads from the GUI's clipboard.
153
154
<p>Not all GUIs have clipboards. For example, the plain old termcap
155
interface doesn't have one. The "^ cut buffer still exists, but it
156
resides inside Elvis, just like any other cut buffer.
157
(Exception: The Windows version of the termcap interface has been
158
patched to access the Windows clipboard.)
159
160
<p>Elvis' X11 interface does use X's clipboard. Clicking the middle
161
mouse button causes the clipboard's contents to be inserted at the cursor
162
position. When you select text via the mouse, the text is immediately
163
copied to the clipboard. Text that you select via keyboard commands
164
is <em>not</em> automatically copied because Elvis has no way of knowing
165
when you're through selecting it.
166
167
<p>The Win32 version of Elvis has the usual Cut/Copy/Paste toolbar buttons
168
and menu items.
169
170
</body></html>