]> git.rkrishnan.org Git - .emacs.d.git/blob - emacs/nxhtml/etc/viper-tut/5tricks
submodulized .emacs.d setup
[.emacs.d.git] / emacs / nxhtml / etc / viper-tut / 5tricks
1 Viper tutorial #5: Tricks and Timesavers
2
3 This lesson lasts 10-15 minutes.  You should have a strong
4 understanding of tutorials #1-3 before working through these timesaving
5 techniques.  Lines which begin with  >>>  mark exercises you should
6 try.  When you want to exit this tutorial type  'Z''Z' .
7
8
9 CASE CONVERSION
10 ---------------
11 When you want to change an upper-case character to a lower-case
12 character (or lower-case to upper-case) there is a single command which
13 does both:
14
15         '~'     (tilde) Convert case of current character
16
17 >>>  Move the cursor to be OVER the first character in the example
18 >>>  line below.  Press  '~'  until you have changed the case of the
19 >>>  entire line.  (  '~'  will advance to the right automatically).
20
21         bOB WENT TO pARIS, fRANCE, TO SEE THE #1 CYCLING EVENT.  end.
22
23 Note that  '~'  only affects alphabetic characters.
24
25
26 UNDOING
27 -------
28 * EMACS-NOTICE: Uppercase U does the same thing as lowercase u in
29   Viper so this part of the tutorial which was about U has been
30   removed.
31
32
33 REPEAT LAST COMMAND
34 -------------------
35 Often you want to make the same change at multiple locations in the
36 file.  To help accomplish this, vi remembers your previous action.
37
38         '.'       (dot) repeat last change
39
40 >>> Go through the example below changing "FISH" to "TOAD":
41 >>>     Go to the "F" in the first instance of "FISH"
42 >>>     To change the word:  type  'c''w'  then type  TOAD  then press ESC
43 >>>     Move the cursor to "F" in the second occurence of "FISH"
44 >>>     Type  '.'  (dot)
45 >>>     Move the cursor to "F" in the final occurence of "FISH"
46 >>>     Type  '.'  (dot)
47 >>>     Now move the cursor to each occurence of "CROW";  Type  '.'  (dot)
48
49         EXAMPLE:  The FISH fed the cat.  The CROW fed the cat.  Example
50         text is FISH to make interesting.  The man fed the CROW.  The
51         worm fed the FISH.  Example text is hard to make CROW.  END.
52
53 >>> Go through the example above deleting all occurences of "TOAD":
54 >>>     Move to the beginning of the EXAMPLE paragraph above.
55 >>>     Type  '/''T''O''A''D'  and press RETURN (recall tutorial #2)
56 >>>     Delete the word by typing  'd''w'
57 >>>     Type  'n'  to move to the next occurence of "TOAD"
58 >>>     Type  '.'  (dot) to repeat the  dw  command
59 >>>     Use  'n''.'  to delete the remaining "TOAD"s
60
61 Note that  '.'  only repeats changes, not cursor movements.
62
63 * EMACS-NOTICE: In Emacs  '.'  also repeat undo and redo.
64
65 * EMACS-NOTICE: Emacs KEYBOARD-MACROS are very powerful for repeating
66   whole sequences of keyboard commands.
67
68
69 WINDOW ACTIONS
70 --------------
71 You are already familiar with the  C-u  (depress the control key and
72 type u) and C-d  commands from tutorial #1.
73
74         C-d     Move DOWN one half-screen
75         C-u     Move UP one half-screen
76
77 There are several related commands:
78
79         C-f     Move FORWARD one full-screen
80         C-b     Move BACKWARD one full-screen
81
82         C-e     Move the window down one line without moving cursor
83         C-y     Move the window up one line without moving cursor
84
85 The  C-e  and  C-y  commands may seem obscure; however, notice that on
86 the keyboard,  e and  y  are close to  d  and  u  respectively.  This
87 should help you remember that  C-e  moves DOWN, and  C-y  moves UP.
88
89 Recall the  'H'  'M'  'L'  (HIGH MIDDLE LOW) window commands from Tutorial 2.
90 Consider a scenario where you want to yank from the current line to a
91 line near the top of the window.  You could use  C-e  and  C-y  to
92 position the text in the window before you use the  yH  command.
93
94 The  'z'  command also moves the window without moving your cursor:
95
96     'z'<RETURN>   Position the current line to top of window
97         'z''.'      Position the current line to middle of window
98         'z''-'      Position the current line to bottom of window
99
100 >>>     Move to this line.  Type  'z'  and press RETURN.  Notice that
101 >>>     this text and the cursor have moved to the top of the window.
102 >>>     Try  'z''-'  and  'z''.'  also.
103
104
105 FILE AND DISPLAY CONTROL
106 ------------------------
107
108 * EMACS-NOTICE: In vi C-g shows the status of the current file, but
109   C-g in Emacs in most situation stops what Emacs is doing. To get
110   information about the current file you can use C-c C-g instead when
111   Viper is in vi state.
112
113 * EMACS-NOTICE: In vi C-l refreshes the screen, but C-l in Emacs calls
114   the command recenter.
115
116
117 SUSPENDING VI
118 -------------
119 * EMACS-NOTICE: In vi C-z suspends vi. However in Viper C-z is by
120   default the VIPER-TOGGLE-KEY. To suspend or iconify Emacs use C-x
121   C-z.
122
123
124 BANG COMMAND
125 ------------
126 * EMACS-NOTICE: Emacs has builtin commands to sort etc.
127
128 The exclamation point,  '!'  (aka BANG), command allows you to feed text
129 to any Unix command.  The output of the Unix command replaces the
130 original text.  Here is a useful Unix command to use from within vi:
131
132         !}fmt   Format the paragraph, joining and filling lines to
133                 produce output lines of up to 72 characters
134
135 >>>  Move to the example paragraph below. Type  !}fmt  and press
136 >>>  RETURN.  Notice the paragraph will be reformatted such that
137 >>>  the lines are of approximately equal length.
138
139         EXAMPLE:
140         So we grow together,
141         Like to a double cherry, seeming parted,
142         But yet an union in partition;
143         Two lovely berries moulded on one stem;
144         So, with two seeming bodies, but one heart;
145         END.
146
147 Another useful command is:
148
149        !}sort   Sort lines of a paragraph alphabetically
150
151 >>>  Move to the example text below. Type  !}sort  and press RETURN.
152
153         OBERON          king of the fairies.
154         PUCK            or Robin Goodfellow.
155         HERMIA          daughter to Egeus, in love with Lysander.
156         HELENA          in love with Demetrius.
157         LYSANDER        in love with Hermia.
158         DEMETRIUS       in love with Hermia.
159
160 Remember, any Unix command may be used this way.
161
162
163 SHIFTING TEXT
164 -------------
165 It is possible to shift large blocks of text right and left with the '>'
166 and  '<'  commands.
167
168    '>'movement    Shift right to where the movement command specifies
169    '<'movement    Shift left to where the movement command specifies
170
171 These commands work like the  'd'  command.  For example:
172
173         '>''}'      Shift right to the end of the paragraph
174         '<''}'      Shift left to the end of the paragraph
175         '>''>'      Shift the current line right
176         '<''<'      Shift the current line left
177
178 >>>  Move the cursor to the first line of the paragraph below.
179 >>>  Type  '>''>'  and  '<''<'  to shift the line back and forth.  Next
180 >>>  try  '>''}'  to shift the paragraph to the right, then  '<''}'  to shift
181 >>>  it left, then type  '.'  until all four lines start at the left edge.
182
183         THIS IS THE FIRST LINE OF EXAMPLE TEXT
184             IS
185     EXAMPLE
186                 TEXT END
187
188
189 SUMMARY
190 -------
191
192         '~'       (tilde) Convert case of current character
193
194         'U'       * EMACS-NOTICE: Same as lowercase u undo in Viper.
195
196         '.'       (dot) repeat last change
197
198         C-d      Move DOWN one half-screen
199                 (depress the control key and type d)
200
201         C-u      Move UP one half-screen
202                 (depress the control key and type u)
203
204         C-f     Move FORWARD one full-screen
205         C-b     Move BACKWARD one full-screen
206
207         C-e     Move the window down one line without moving cursor
208         C-y     Move the window up one line without moving cursor
209
210     'z'<RETURN>   Position the current line to top of window
211         'z''.'      Position the current line to middle of window
212         'z''-'      Position the current line to bottom of window
213
214     C-c C-g     Show status of current file
215         C-l     Recenter
216
217         '!'}fmt   Format the paragraph, joining and filling lines to
218                 produce output lines of up to 72 characters
219
220        '!'}sort   Sort lines of a paragraph alphabetically
221
222    '>'movement    Shift right to where the movement command specifies
223    '<'movement    Shift left to where the movement command specifies
224
225
226 These commands should significantly speed up your editing. Have a nice
227 day.  Tutorial 6 contains even more nifty commands.
228
229 Copyright (c) 1992 Jill Kliger and Wesley Craig.  All Rights Reserved.