]> git.rkrishnan.org Git - .emacs.d.git/blob - emacs/nxhtml/etc/viper-tut/2moving
remove toolbar and menubar
[.emacs.d.git] / emacs / nxhtml / etc / viper-tut / 2moving
1 Viper tutorial #2: Moving Through Files Efficiently
2
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'.
6
7
8 WORDS
9 -----
10 There are many ways to move from one word to another. Consider these:
11
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
15
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
19 by any blank space.
20
21 >>>  Try out  'w', 'b', 'e',  on the lines provided below.
22 >>>  Next practice using  'B', 'W', 'b', 'E'  on the lines provided below.
23
24     EX-PER-IMENT on these lines;test moving back &forth.
25     EX-PER-IMENT on these lines;test moving back &forth.
26
27
28 ON THE LINE
29 -----------
30 You can move immediately to any point on the current line.
31
32         '$'       Move to the end of the line
33         '^'       Move to the first non-white character on the line
34
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|
37
38 >>>  Experiment with  '$'  and  '^'  on the line provided below.  Notice
39 >>>  that  '^'  moves to the first non-white character, not the beginning.
40
41     This is a PRACTICE LINE.  There is white space at the front.  END
42
43 '0' (zero) will always take you to the far left edge of the screen.
44
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.
48
49
50 FINDING CHARACTERS
51 ------------------
52 Often you want to move to a specific letter or character on a line.
53
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
56
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
59
60         ';'       Repeat the last  f, t, F, or T
61         ','       Reverse the last  f, t, F, or T
62
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.
65
66 If the specified character is not on the line, vi will beep.
67
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  ','  ';'  ','  ';'
70
71     "PRACTICE line?" "Each and Every?" "Find thE char@cter and move to it.END
72
73
74 MATCHING
75 --------
76 vi has a handy way to determine if (), {}, and [] pairs match up.
77
78         '%'       Move to matching () or {} or []
79
80 >>>  On the practice lines below, move your cursor over a (,),{,},[, or ].
81 >>>  Then type  '%'  .
82
83     [TRY THIS.  ((Whether) the pairs match up is the question.)  [One]
84     pair is incomplete].  Can you tell {which one? ]} END
85
86
87 WINDOW POSITIONS
88 ----------------
89 You can move the cursor to the top, middle, or bottom of the vi window.
90
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
94
95 >>>  Try out these commands:  type  H  then  M  and  L  and then  M  again.
96
97
98 MARKING LOCATIONS
99 -----------------
100 You can mark positions in the file and return to them.
101
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
105
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
109
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
116
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).
120
121 >>>  Try this:  'b  to return to line b, and then  ''  to return here.
122
123
124 GO TO A LINE
125 ------------
126
127          'G'      GO to the last line in the file
128         #'G'      GO to line #.  (e.g., 3G , 5G , 124G )
129
130 Read these directions carefully:
131 >>>  Type  '1''G'  to go to the top of the file, and then  ''''''  (quote quote)
132 >>>  to return here.
133 >>>  Now try  'G'  to go to the end of the file, and then  ''''''  to return here.
134
135
136 BLOCKS OF TEXT
137 --------------
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:
140
141         '{'       (left brace) Move to the beginning of a paragraph
142         '}'       (right brace) Move to the end of a paragraph
143
144         '('       (left paren) Move to the beginning of a sentence
145         ')'       (right paren) Move to the beginning of the next sentence
146
147 >>>  Experiment with  '}'  and  '{'  on the two paragraphs provided below.
148 >>>  Note that paragraphs are separated by a blank line.
149
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!
153
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.
157
158 >>>  Try out  ')'  and  '('  on the two paragraphs provided above.
159 >>>  Notice that sentences are separated by two blank spaces.
160
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  ']'']' .
165
166         '[''['      Move to the beginning of a section
167         ']'']'      Move to the end of a section
168
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.
171
172 >>>  Now try  ']'']'  then  ']'']'  and  '[''['  on the subroutines provided below:
173
174 main()
175 {
176     helloworld();
177 }
178
179 helloworld()
180 {
181     printf( "Hello world\n" );
182 }
183
184
185 SEARCHING
186 ---------
187 This enables you to jump to the next occurrence of a string in a file.
188 To initially find the string use:
189
190     '/'string      Find string looking forward
191     '?'string      Find string looking backward
192
193 To find additional occurrences of the string type:
194
195         'n'        Repeat last / or ? command
196         'N'        Reverse last / or ? command
197
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.)
200
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.
207
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).
211
212
213 SUMMARY
214 -------
215
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
219
220         '$'       Move to the end of the line
221         '^'       Move to the first non-white character on the line
222
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|
225
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
228
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
231
232         ';'       Repeat the last  f, t, F, or T
233         ','       Reverse the last  f, t, F, or T
234
235         '%'       Show matching () or {} or []
236
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
240
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
244
245          'G'      GO to the last line in the file
246         #'G'      GO to line #.  (e.g., 3G , 5G , 175G )
247
248         '{'       (left brace) Move to the beginning of a paragraph
249         '}'       (right brace) Move to the end of a paragraph
250
251         '('       (left paren) Move to the beginning of a sentence
252         ')'       (right paren) Move to the beginning of the next sentence
253
254         '[''['      Move to the beginning of a section
255         ']'']'      Move to the end of a section
256
257     '/'string      Find string looking forward
258     '?'string      Find string looking backward
259
260         'n'        Repeat last / or ? command
261         'N'        Reverse last / or ? command
262
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.
268
269 Copyright (c) 1992 Jill Kliger and Wesley Craig.  All Rights Reserved.