1 Viper tutorial #2: Moving Through Files Efficiently
3 This lesson lasts 15-20 minutes. The material taught here is used in
4 tutorial #3: Cutting and Pasting. Lines which begin with >>> mark
5 exercises you should try. When you want to exit this tutorial type 'Z''Z'.
10 There are many ways to move from one word to another. Consider these:
12 'w' Move to the beginning of the next WORD
13 'e' Move to the END of the next word
14 'b' Move BACK to the beginning to the previous word
16 For 'w', 'e', and 'b', a word is delimited by any non-alphanumeric
17 character. The capitalized versions, 'W', 'E', and 'B', also move from word
18 to word. The difference is that for 'W', 'E', and 'B', a word is delimited
21 >>> Try out 'w', 'b', 'e', on the lines provided below.
22 >>> Next practice using 'B', 'W', 'b', 'E' on the lines provided below.
24 EX-PER-IMENT on these lines;test moving back &forth.
25 EX-PER-IMENT on these lines;test moving back &forth.
30 You can move immediately to any point on the current line.
32 '$' Move to the end of the line
33 '^' Move to the first non-white character on the line
35 '0' Move to the first column on the line (column zero)
36 #'|' Move to an exact column on the line (column #) e.g. 5| 12|
38 >>> Experiment with '$' and '^' on the line provided below. Notice
39 >>> that '^' moves to the first non-white character, not the beginning.
41 This is a PRACTICE LINE. There is white space at the front. END
43 '0' (zero) will always take you to the far left edge of the screen.
45 #'|' (number vertical-bar) is for moving to an explicit column on a line.
46 Just type any number 1-80 and press | . For example: 5| 20| 30|
47 Note that you can't move beyond the last column on a line.
52 Often you want to move to a specific letter or character on a line.
54 'f' char FIND the next occurrence of char on the line
55 't' char Move 'TIL the next occurrence of char on the line
57 'F' char FIND the previous occurrence of char on the line
58 'T' char Move 'TIL the previous occurrence of char on the line
60 ';' Repeat the last f, t, F, or T
61 ',' Reverse the last f, t, F, or T
63 'f' and 'F' land on the character. 't' and 'T' land next to the character.
64 'f' and 't' move forward, while 'F' and 'T' move backward.
66 If the specified character is not on the line, vi will beep.
68 >>> Move to the beginning of the line below, and try out these commands:
69 >>> 'f'e 'f'E ';' ';' ',' ',' 't'@ 'T'P 't'e 't'E ',' ';' ',' ';'
71 "PRACTICE line?" "Each and Every?" "Find thE char@cter and move to it.END
76 vi has a handy way to determine if (), {}, and [] pairs match up.
78 '%' Move to matching () or {} or []
80 >>> On the practice lines below, move your cursor over a (,),{,},[, or ].
83 [TRY THIS. ((Whether) the pairs match up is the question.) [One]
84 pair is incomplete]. Can you tell {which one? ]} END
89 You can move the cursor to the top, middle, or bottom of the vi window.
91 'H' Move to the HIGHEST position in the window
92 'M' Move to the MIDDLE position in the window
93 'L' Move to the LOWEST position in the window
95 >>> Try out these commands: type H then M and L and then M again.
100 You can mark positions in the file and return to them.
102 'm' char MARK this location and name it char
103 ''' char (quote character) return to line named char
104 '''''' (quote quote) return from last movement
106 char can be any lower case letter, a-z. A mark persists until you:
107 1) use the same char to mark another location
108 or 2) delete the marked line
110 >>> Move to this line and type ma to mark it a
111 >>> Move to this line and type mb to mark it b
112 >>> Move to this line and type mz to mark it z
113 >>> Type 'a to return to line a
114 >>> Type 'b to return to line b
115 >>> Type 'z to return to line z
117 Certain commands can move you large distances. These commands cause
118 your last position to be remembered in the special mark named ' (quote).
119 To move to this special mark, just type '' (quote quote).
121 >>> Try this: 'b to return to line b, and then '' to return here.
127 'G' GO to the last line in the file
128 #'G' GO to line #. (e.g., 3G , 5G , 124G )
130 Read these directions carefully:
131 >>> Type '1''G' to go to the top of the file, and then '''''' (quote quote)
133 >>> Now try 'G' to go to the end of the file, and then '''''' to return here.
138 It is often convenient to move through files jumping from one block of
139 text to the next. To do this use braces and parentheses:
141 '{' (left brace) Move to the beginning of a paragraph
142 '}' (right brace) Move to the end of a paragraph
144 '(' (left paren) Move to the beginning of a sentence
145 ')' (right paren) Move to the beginning of the next sentence
147 >>> Experiment with '}' and '{' on the two paragraphs provided below.
148 >>> Note that paragraphs are separated by a blank line.
150 EXPERIMENT on this first paragraph. The quick brown fox jumped
151 over the seven lazy dogs. The fox must have been very large to
152 jump over seven dogs!
154 EXPERIMENT on this second paragraph. The quick brown dog
155 jumped over the seven lazy foxes. The dog didn't have to be nearly
156 as large, since foxes aren't too big.
158 >>> Try out ')' and '(' on the two paragraphs provided above.
159 >>> Notice that sentences are separated by two blank spaces.
161 C programmers find it useful to move by sections, since sections may be
162 delimited by a left brace in the first column. By placing the opening
163 brace of a C subroutine in the first column, you can move to the top of
164 the next subroutine, using '[''[' and ']'']' .
166 '[''[' Move to the beginning of a section
167 ']'']' Move to the end of a section
169 Note that if vi does not find a left brace at the far left, it will
170 move to the top or bottom of the file.
172 >>> Now try ']'']' then ']'']' and '[''[' on the subroutines provided below:
181 printf( "Hello world\n" );
187 This enables you to jump to the next occurrence of a string in a file.
188 To initially find the string use:
190 '/'string Find string looking forward
191 '?'string Find string looking backward
193 To find additional occurrences of the string type:
195 'n' Repeat last / or ? command
196 'N' Reverse last / or ? command
198 vi may search past the bottom of the file and then start again at the top.
199 (Or, vi may search past the top and then start again at the bottom.)
201 >>> You are going to search for a string, find the next three
202 >>> occurrences. Then flip directions and find the string until you
203 >>> return to this location. To do this:
204 >>> Type '/''t''h''e' then press RETURN.
205 >>> Type 'n' three times.
206 >>> Type 'N' until you return to this location.
208 * EMACS-NOTICE: Emacs has very powerful SEARCH-COMMANDS which you may
209 want to use in parallell to those above. One of the first you want
210 to try is probably C-s (ISEARCH-FORWARD).
216 'w' Move to the beginning of the next WORD
217 'e' Move to the END of the next word
218 'b' Move BACK to the beginning to the previous word
220 '$' Move to the end of the line
221 '^' Move to the first non-white character on the line
223 '0' Move to the first column on the line (column zero)
224 #'|' Move to an exact column on the line (column #) e.g. 5| 12|
226 'f' char FIND the next occurrence of char on the line
227 't' char Move 'TIL the next occurrence of char on the line
229 'F' char FIND the previous occurrence of char on the line
230 'T' char Move 'TIL the previous occurrence of char on the line
232 ';' Repeat the last f, t, F, or T
233 ',' Reverse the last f, t, F, or T
235 '%' Show matching () or {} or []
237 'H' Move to the HIGHEST position in the window
238 'M' Move to the MIDDLE position in the window
239 'L' Move to the LOWEST position in the window
241 'm' char MARK this location and name it char
242 ''' char (quote character) return to line named char
243 '''''' (quote quote) return from last movement
245 'G' GO to the last line in the file
246 #'G' GO to line #. (e.g., 3G , 5G , 175G )
248 '{' (left brace) Move to the beginning of a paragraph
249 '}' (right brace) Move to the end of a paragraph
251 '(' (left paren) Move to the beginning of a sentence
252 ')' (right paren) Move to the beginning of the next sentence
254 '[''[' Move to the beginning of a section
255 ']'']' Move to the end of a section
257 '/'string Find string looking forward
258 '?'string Find string looking backward
260 'n' Repeat last / or ? command
261 'N' Reverse last / or ? command
263 You should now be able to move around files very efficiently. These
264 commands are especially useful if you are using vi over a slow modem.
265 Practice the material in this lesson for a few days and then take
266 either the third vi tutorial to learn how to copy, cut, and paste, or
267 the forth vi tutorial to learn additional insertion techniques.
269 Copyright (c) 1992 Jill Kliger and Wesley Craig. All Rights Reserved.