]> git.rkrishnan.org Git - .emacs.d.git/blob - emacs/nxhtml/etc/viper-tut/3cutpaste
6d531d92b31b8e50a460ca0bdf323e650f2faf81
[.emacs.d.git] / emacs / nxhtml / etc / viper-tut / 3cutpaste
1 Viper tutorial #3: Copying, Cutting, and Pasting
2
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.
6
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.
10
11
12 CUTTING TEXT
13 ------------
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:
16
17     'd'movement DELETE to where the movement command specifies
18
19 Consider the following examples:
20
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)
26
27 >>>  Experiment with  'd''w'  'd''$'  'd'')'  'd''t'e  'd''d'  on the paragraph provided below:
28
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
33
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).
38
39
40 PASTING TEXT
41 ------------
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.
45
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
48
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
55
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
60
61 >>>  Try this sequence of commands at the beginning of a word:
62 >>>     'd''w'  'w'  'P'
63
64 The fastest way to swap two letters is to type:  'x''p'
65
66 >>>  Use  xp  to correct the misspelled words below:
67
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.
71
72
73 NUMBERING
74 ---------
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:
78
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.
84
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
89
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.
93
94 Numbering also works for movement commands.
95
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.
98
99 When you type  '4''w'  THINK "4 words", when you type  d4w  think "delete 4
100 words".  In general, we can write
101
102     #movement   repeat movement # times
103     d#movement  DELETE to where the  #movement  command specifies
104
105
106 COPYING TEXT
107 ------------
108 The YANK command works just like the DELETE command, except  'y'  is used
109 instead of  'd'  .
110
111     'y'movement YANK to where the movement command specifies
112
113 YANK and DELETE are identical except that YANK only copies the specified
114 text into the buffer.
115
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
120
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
125
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.
129
130 Here are some examples which show the similarity between  y  and  d .
131
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
136         'y''y'  YANK a line
137
138 Here are some more examples using commands from tutorial #2.
139
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)
144
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.
147
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
152
153
154 NUMBERED BUFFERS
155 ----------------
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,
161
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
167
168 Note that buffer #1 is the same as the un-named buffer.  Here's how to
169 paste from the numbered buffers:
170
171         "#P     (upper p) PUT contents of buffer # before the cursor
172         "#p     (lower p) PUT contents of buffer # after the cursor
173
174 For example:
175
176         "1p     PUT buffer 1 after the cursor
177         "7p     PUT buffer 7 after the cursor
178
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
185
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.
188
189
190 NAMED BUFFERS
191 -------------
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.
195
196     '"'aDELETE  DELETE text into buffer a
197     "aYANK      YANK text into buffer a
198     "aPUT       PUT text from buffer a
199
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:
202
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
208
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>  )
212
213 >>>  Delete this START line into buffer a  by typing  "add
214 >>>  Paste buffer a  by typing  "ap
215
216 >>>  Delete this INTERMEDIATE line into buffer b  by typing  "bdd
217 >>>  Paste buffer b  by typing  "bp
218
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
222
223
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.
230
231     :w<RETURN>  WRITE contents of the file (without quitting)
232                 (type a colon, type w , then press the RETURN key)
233
234 >>>  Try  :w  now.  Note the message at the bottom of the screen.
235
236
237 PASTING BETWEEN FILES
238 ---------------------
239
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 ;-)
243
244 This is an extremely useful procedure in vi.  Only one new command is
245 required for pasting between files, the EDIT command
246
247     :e filename<RETURN>    Begin EDITing the file called "filename"
248
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.
251
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)
255
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.
259
260     2) EDIT "3temp" without quitting vi.        :e 3temp (press RETURN)
261
262     3) YANK 6 lines from "3temp".               "ay6y
263
264     4) Return to "3cutpaste".                   :e 3cutpaste (press RETURN)
265
266     5) PUT from buffer a                        "ap
267
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.
270
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,
274 >>>  "3cutpaste".
275
276 You can use this 5-step procedure on any two files, with any cutting or
277 copying action (here, y6y is the example).
278
279
280 SUMMARY
281 -------
282
283     #movement   repeat movement # times
284                 * EMACS-NOTICE: You may also use 'r' or 'R' in Viper.
285
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' )
289
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' )
293
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
296
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' )
300
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'  )
307
308     :w<RETURN>  WRITE contents of the file (without quitting)
309                 (type a colon, type w , then press the RETURN key)
310
311     :e filename<RETURN>    Begin EDITing the file called "filename"
312
313
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.
317
318 Copyright (c) 1992 Jill Kliger and Wesley Craig.  All Rights Reserved.