1 Viper tutorial #3: Copying, Cutting, and Pasting
3 This lesson lasts 15-20 minutes. This tutorial assumes full knowledge
4 of tutorial #1, and familiarity with tutorial #2. Lines which begin
5 with >>> mark exercises you should try.
7 When you want to exit this tutorial type 'Z''Z' to exit and save your
8 changes. Or type :q!<RETURN> to exit without saving changes.
9 Remember that typing u will UNDO your last change.
14 The delete command can be combined with any of the movement commands
15 taught throughout tutorial #2. The resulting command is of the form:
17 'd'movement DELETE to where the movement command specifies
19 Consider the following examples:
21 'd''w' DELETE to the beginning of the next WORD
22 'd''$' DELETE to the end of the line
23 'd'')' DELETE to the beginning of the next sentence
24 'd''t'e DELETE 'TIL the next e
25 'd''d' DELETE a line (dd is a special case of the d command)
27 >>> Experiment with 'd''w' 'd''$' 'd'')' 'd''t'e 'd''d' on the paragraph provided below:
29 PRACTICE here. Now is the time for all good users to learn the
30 editor. The quick brown fox jumped over the seven lazy fish. Now
31 is the time for all good users to learn the editor. The quick
32 brown computer jumped over the seven lazy users. END PRACTICE
34 * EMACS-NOTICE: In Viper you can also use 'r' and 'R' for Emacs region and
35 Viper line extended region. This is very convenient together with
36 CUA-MODE where the region is visible (it is usually called the
37 selected text or something similar in other applications).
42 When text is deleted it is put into a buffer which contains the most
43 recently deleted text. To paste the contents of this buffer elsewhere
44 in the file use the p or P command.
46 'P' (upper p) PUT the contents of the buffer before the cursor
47 'p' (lower p) PUT the contents of the buffer after the cursor
49 >>> Try this sequence of commands on the practice lines below:
50 >>> 'd''d' to delete one line
51 >>> 'j' to move down a line
52 >>> 'p' (lower p) to PUT the deleted text after the cursor
53 >>> '}' to move to the end of the paragraph
54 >>> 'P' (upper p) to PUT the deleted text before the cursor
56 PRACTICE line. Cut and Paste this line to the bottom of the
57 paragraph. Here is some filler, feel free to cut and paste the
58 text in this practice region. Remember that u undoes the last
59 action. END OF PRACTICE
61 >>> Try this sequence of commands at the beginning of a word:
64 The fastest way to swap two letters is to type: 'x''p'
66 >>> Use xp to correct the misspelled words below:
68 PRACTICE. Thier weird quiet recieved an inconvenient shriek.
69 Thier belief is that to recieve grief from nieghbors outwieghs
70 all else. Biege skies lead to wierd science. END.
75 Consider cutting and pasting 3 words. Based on previous exercises you
76 would type 'd''w' , move to the new location, and type 'p' , and repeat
77 this procedure twice more. There is an easier way to do this:
79 >>> Using the practice lines below, try the following sequence of commands:
80 >>> Move to the beginning of the first sentence.
81 >>> Type 'd''3''w' to DELETE 3 WORDS.
82 >>> Type 'w' to move ahead one WORD.
83 >>> Type 'P' (upper p) to PUT the three words before the cursor.
85 PRACTICE Numbering vi commands is easy to do. Now is the time for
86 all good users to learn the editor. The quick brown fox jumped
87 over the seven lazy dogs. Numbering vi commands is easy to do.
88 Now is the time for all good users to learn the editor. END PRACTICE
90 >>> Type 'd''2''d' to DELETE 2 lines, using the practice paragraph above.
91 >>> Move to the top of the paragraph.
92 >>> Type 'p' (lower p) to PUT the two lines after of the cursor.
94 Numbering also works for movement commands.
96 >>> Now try '4''w' to move ahead 4 WORDs, on the lines provided above.
97 >>> Then use '3''b' to move BACK 3 words.
99 When you type '4''w' THINK "4 words", when you type d4w think "delete 4
100 words". In general, we can write
102 #movement repeat movement # times
103 d#movement DELETE to where the #movement command specifies
108 The YANK command works just like the DELETE command, except 'y' is used
111 'y'movement YANK to where the movement command specifies
113 YANK and DELETE are identical except that YANK only copies the specified
114 text into the buffer.
116 >>> Try this sequence of commands on the practice lines below:
117 >>> 'y''y' to YANK a line (yy is a special case of the y command)
118 >>> '3''j' to move down 3 lines
119 >>> 'p' (lower p) to PUT the yanked text after the cursor
121 PRACTICE line. Copy and Paste this line to the bottom of the
122 paragraph. Here is some filler, feel free to copy and paste the
123 text in this practice region. Remember that u undoes the last
124 action. END OF PRACTICE
126 Please note that copy, cutting, and pasting large blocks of text may
127 significantly alter the tutorial file. Remember that you can always get
128 a new copy of the tutorial file and that u UNDOes your last change.
130 Here are some examples which show the similarity between y and d .
132 'y''w' YANK to the beginning of the next WORD
133 'y''$' YANK to the end of the line
134 'y'')' YANK to the beginning of the next sentence
135 'y''t'e YANK 'TIL the next e
138 Here are some more examples using commands from tutorial #2.
140 'y''L' YANK from here to the lowest point of the window
141 'y''/'and YANK from here to the word "and"
142 'y''2''}' YANK 2 paragraphs
143 'y''''a YANK from here to the marked line "a" (mark line first)
145 >>> Experiment with 'y''w' 'y''t'e 'y''4''w' 'y''2''}' 'y''3''y' and 'y''$' on the paragraph
146 >>> provided below. Copy text AND use 'p' or 'P' to paste it.
148 PRACTICE line. Copy and Paste this line to the bottom of the
149 paragraph. Here is some filler, feel free to copy and paste
150 the text in this practice region. Remember that u undoes the
151 last action. END OF PRACTICE
156 In all of the previous pasting exercises you've used the "un-named"
157 buffer. The un-named buffer contains the text you most recently cut or
158 copied. When you make a new cut or copy, the old contents of the
159 un-named buffer are moved to one of the "numbered" buffers. The
160 buffers are numbered 1-9. Each time you cut or copy text,
162 vi saves your current cut or copy in a buffer #1
163 vi saves your 2nd to last cut or copy in a buffer #2
164 The cut or copy before that is saved in a buffer #3 ...
165 vi saves your 8th oldest cut or copy in a buffer #8
166 vi saves your 9th oldest cut or copy in a buffer #9
168 Note that buffer #1 is the same as the un-named buffer. Here's how to
169 paste from the numbered buffers:
171 "#P (upper p) PUT contents of buffer # before the cursor
172 "#p (lower p) PUT contents of buffer # after the cursor
176 "1p PUT buffer 1 after the cursor
177 "7p PUT buffer 7 after the cursor
179 >>> Delete this 1st line with dd
180 >>> Delete this 2nd line with dd
181 >>> Delete this 3rd block with d2d
182 >>> (2nd half of block 3)
183 >>> Delete this 4th block with dd
184 >>> Now type "1p "2p "3p "4p
186 If you are using vi and have made accidental deletions, just PUT the
187 contents of each numbered buffer to recover the deleted text.
192 vi maintains the un-named and numbered buffers automatically. You can
193 maintain your own buffers named a-z. That is, you can cut or copy text
194 into buffer x and later paste the text from buffer x.
196 '"'aDELETE DELETE text into buffer a
197 "aYANK YANK text into buffer a
198 "aPUT PUT text from buffer a
200 Note, don't actually type 'DELETE', 'YANK', or 'PUT'; type one of the
201 DELETE commands, YANK commands, or PUT commands. See the examples below:
203 "ad} DELETE paragraph into buffer a
204 "by3y YANK 3 lines into buffer b
205 "cy200G YANK to line 200 into buffer c
206 "dp PUT buffer d after the cursor
207 "zP PUT buffer z before the cursor
209 The contents of a named buffer are lost if:
210 1) you store new text in a buffer with the same name
211 or 2) you quit vi (using 'Z''Z' or :q!<RETURN> )
213 >>> Delete this START line into buffer a by typing "add
214 >>> Paste buffer a by typing "ap
216 >>> Delete this INTERMEDIATE line into buffer b by typing "bdd
217 >>> Paste buffer b by typing "bp
219 To put new material into buffer a
220 >>> Delete this FINAL line into buffer a by typing "add
221 >>> Paste buffer a by typing "ap
224 SAVING WITHOUT QUITTING
225 -----------------------
226 With ZZ you save changes and kill the current buffer. (In vi you also
227 exit with 'Z''Z'.) With :w you can save and not quit vi. It is a safe
228 practice to save changes to a file regularly. This reduces re-typing
229 in the event your computer crashes.
231 :w<RETURN> WRITE contents of the file (without quitting)
232 (type a colon, type w , then press the RETURN key)
234 >>> Try :w now. Note the message at the bottom of the screen.
237 PASTING BETWEEN FILES
238 ---------------------
240 * EMACS-NOTICE: In Emacs there are no problems editing several
241 files. You can however do it in the more complicated vi way below if
242 you really want to ;-)
244 This is an extremely useful procedure in vi. Only one new command is
245 required for pasting between files, the EDIT command
247 :e filename<RETURN> Begin EDITing the file called "filename"
249 The EDIT command allows you to edit another file without quitting vi.
250 This is useful since named buffers are lost when you quit vi.
252 Let's say you want to copy 6 lines from the file called "3temp" into
253 this file which is named "3cutpaste":
254 (Note that "3temp" has already been created for you)
256 1) WRITE "3cutpaste". vi will not allow :w (press RETURN)
257 you to edit another file without first
258 saving any changes you've made.
260 2) EDIT "3temp" without quitting vi. :e 3temp (press RETURN)
262 3) YANK 6 lines from "3temp". "ay6y
264 4) Return to "3cutpaste". :e 3cutpaste (press RETURN)
266 5) PUT from buffer a "ap
268 Note that the un-named and numbered buffers are lost when the EDIT
269 command is used. Only named buffers are preserved with EDIT.
271 >>> Follow the 5-step procedure outlined above. Don't be concerned
272 >>> with remembering all 5 steps, the instructions are repeated in
273 >>> "3temp". Paste the text from "3temp" near this line of this file,
276 You can use this 5-step procedure on any two files, with any cutting or
277 copying action (here, y6y is the example).
283 #movement repeat movement # times
284 * EMACS-NOTICE: You may also use 'r' or 'R' in Viper.
286 'd'movement DELETE to where "movement" command specifies
287 'd'#movement DELETE to where the #movement command specifies
288 (e.g. 'd''w' 'd''3''w' )
290 'y'movement YANK to where "movement" command specifies
291 'y'#movement YANK to where the #movement command specifies
292 (e.g. 'y''w' 'y''3''w' )
294 'P' (upper p) PUT the contents of the buffer before the cursor
295 'p' (lower p) PUT the contents of the buffer after the cursor
297 '"'#P (upper p) PUT contents of buffer # before the cursor
298 '"'#p (lower p) PUT contents of buffer # after the cursor
299 (e.g. '"''2''p' '"''7''P' )
301 '"'aDELETE DELETE text into buffer a
302 '"'aYANK YANK text into buffer a
303 '"'aPUT PUT text from named buffer a
304 (Note, don't actually type 'DELETE', 'YANK', or 'PUT';
305 type one of the DELETE commands, YANK commands, or PUT
306 commands, e.g. '"''a''d''}' '"''b''y''3''y' '"''c''y''2''0''0''G' '"''d''p' '"''z''P' )
308 :w<RETURN> WRITE contents of the file (without quitting)
309 (type a colon, type w , then press the RETURN key)
311 :e filename<RETURN> Begin EDITing the file called "filename"
314 You are now prepared to handle all cutting, copying and pasting tasks
315 which may arise. If you practice what you've learned you'll find editing
316 in vi to be fast and convenient.
318 Copyright (c) 1992 Jill Kliger and Wesley Craig. All Rights Reserved.