1 Viper tutorial #5: Tricks and Timesavers
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' .
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
15 '~' (tilde) Convert case of current character
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).
21 bOB WENT TO pARIS, fRANCE, TO SEE THE #1 CYCLING EVENT. end.
23 Note that '~' only affects alphabetic characters.
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
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.
38 '.' (dot) repeat last change
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"
45 >>> Move the cursor to "F" in the final occurence of "FISH"
47 >>> Now move the cursor to each occurence of "CROW"; Type '.' (dot)
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.
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
61 Note that '.' only repeats changes, not cursor movements.
63 * EMACS-NOTICE: In Emacs '.' also repeat undo and redo.
65 * EMACS-NOTICE: Emacs KEYBOARD-MACROS are very powerful for repeating
66 whole sequences of keyboard commands.
71 You are already familiar with the C-u (depress the control key and
72 type u) and C-d commands from tutorial #1.
74 C-d Move DOWN one half-screen
75 C-u Move UP one half-screen
77 There are several related commands:
79 C-f Move FORWARD one full-screen
80 C-b Move BACKWARD one full-screen
82 C-e Move the window down one line without moving cursor
83 C-y Move the window up one line without moving cursor
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.
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.
94 The 'z' command also moves the window without moving your cursor:
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
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.
105 FILE AND DISPLAY CONTROL
106 ------------------------
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.
113 * EMACS-NOTICE: In vi C-l refreshes the screen, but C-l in Emacs calls
114 the command recenter.
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
126 * EMACS-NOTICE: Emacs has builtin commands to sort etc.
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:
132 !}fmt Format the paragraph, joining and filling lines to
133 produce output lines of up to 72 characters
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.
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;
147 Another useful command is:
149 !}sort Sort lines of a paragraph alphabetically
151 >>> Move to the example text below. Type !}sort and press RETURN.
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.
160 Remember, any Unix command may be used this way.
165 It is possible to shift large blocks of text right and left with the '>'
168 '>'movement Shift right to where the movement command specifies
169 '<'movement Shift left to where the movement command specifies
171 These commands work like the 'd' command. For example:
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
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.
183 THIS IS THE FIRST LINE OF EXAMPLE TEXT
192 '~' (tilde) Convert case of current character
194 'U' * EMACS-NOTICE: Same as lowercase u undo in Viper.
196 '.' (dot) repeat last change
198 C-d Move DOWN one half-screen
199 (depress the control key and type d)
201 C-u Move UP one half-screen
202 (depress the control key and type u)
204 C-f Move FORWARD one full-screen
205 C-b Move BACKWARD one full-screen
207 C-e Move the window down one line without moving cursor
208 C-y Move the window up one line without moving cursor
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
214 C-c C-g Show status of current file
217 '!'}fmt Format the paragraph, joining and filling lines to
218 produce output lines of up to 72 characters
220 '!'}sort Sort lines of a paragraph alphabetically
222 '>'movement Shift right to where the movement command specifies
223 '<'movement Shift left to where the movement command specifies
226 These commands should significantly speed up your editing. Have a nice
227 day. Tutorial 6 contains even more nifty commands.
229 Copyright (c) 1992 Jill Kliger and Wesley Craig. All Rights Reserved.