summaryrefslogtreecommitdiffstats
path: root/emacs.d/nxhtml/etc/viper-tut/2moving
blob: 8e4148eb1babff382c9affaf1eee77e5283ba604 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
Viper tutorial #2: Moving Through Files Efficiently

This lesson lasts 15-20 minutes.  The material taught here is used in
tutorial #3: Cutting and Pasting.  Lines which begin with  >>>  mark
exercises you should try.  When you want to exit this tutorial type 'Z''Z'.


WORDS
-----
There are many ways to move from one word to another. Consider these:

        'w'       Move to the beginning of the next WORD
        'e'       Move to the END of the next word
        'b'       Move BACK to the beginning to the previous word

For  'w', 'e', and 'b',  a word is delimited by any non-alphanumeric
character. The capitalized versions,  'W', 'E', and 'B',  also move from word
to word. The difference is that for  'W', 'E', and 'B',  a word is delimited
by any blank space.

>>>  Try out  'w', 'b', 'e',  on the lines provided below.
>>>  Next practice using  'B', 'W', 'b', 'E'  on the lines provided below.

    EX-PER-IMENT on these lines;test moving back &forth.
    EX-PER-IMENT on these lines;test moving back &forth.


ON THE LINE
-----------
You can move immediately to any point on the current line.

        '$'       Move to the end of the line
        '^'       Move to the first non-white character on the line

        '0'       Move to the first column on the line (column zero)
        #'|'      Move to an exact column on the line (column #) e.g.  5| 12|

>>>  Experiment with  '$'  and  '^'  on the line provided below.  Notice
>>>  that  '^'  moves to the first non-white character, not the beginning.

    This is a PRACTICE LINE.  There is white space at the front.  END

'0' (zero) will always take you to the far left edge of the screen.

#'|' (number vertical-bar) is for moving to an explicit column on a line.
Just type any number 1-80 and press  | . For example:  5|   20|   30|
Note that you can't move beyond the last column on a line.


FINDING CHARACTERS
------------------
Often you want to move to a specific letter or character on a line.

    'f' char      FIND the next occurrence of char on the line
    't' char      Move 'TIL the next occurrence of char on the line

    'F' char      FIND the previous occurrence of char on the line
    'T' char      Move 'TIL the previous occurrence of char on the line

        ';'       Repeat the last  f, t, F, or T
        ','       Reverse the last  f, t, F, or T

'f' and 'F' land on the character.  't' and 'T' land next to the character.
'f' and 't' move forward, while 'F' and 'T' move backward.

If the specified character is not on the line, vi will beep.

>>>  Move to the beginning of the line below, and try out these commands:
>>>     'f'e  'f'E  ';'  ';'  ','  ','  't'@  'T'P  't'e  't'E  ','  ';'  ','  ';'

    "PRACTICE line?" "Each and Every?" "Find thE char@cter and move to it.END


MATCHING
--------
vi has a handy way to determine if (), {}, and [] pairs match up.

        '%'       Move to matching () or {} or []

>>>  On the practice lines below, move your cursor over a (,),{,},[, or ].
>>>  Then type  '%'  .

    [TRY THIS.  ((Whether) the pairs match up is the question.)  [One]
    pair is incomplete].  Can you tell {which one? ]} END


WINDOW POSITIONS
----------------
You can move the cursor to the top, middle, or bottom of the vi window.

        'H'    Move to the HIGHEST position in the window
        'M'    Move to the MIDDLE position in the window
        'L'    Move to the LOWEST position in the window

>>>  Try out these commands:  type  H  then  M  and  L  and then  M  again.


MARKING LOCATIONS
-----------------
You can mark positions in the file and return to them.

     'm' char     MARK this location and name it char
     ''' char     (quote character) return to line named char
     ''''''         (quote quote) return from last movement

char can be any lower case letter, a-z.  A mark persists until you:
     1) use the same char to mark another location
  or 2) delete the marked line

>>>  Move to this line and type  ma  to mark it  a
>>>  Move to this line and type  mb  to mark it  b
>>>  Move to this line and type  mz  to mark it  z
>>>  Type  'a  to return to line  a
>>>  Type  'b  to return to line  b
>>>  Type  'z  to return to line  z

Certain commands can move you large distances. These commands cause
your last position to be remembered in the special mark named ' (quote).
To move to this special mark, just type '' (quote quote).

>>>  Try this:  'b  to return to line b, and then  ''  to return here.


GO TO A LINE
------------

         'G'      GO to the last line in the file
        #'G'      GO to line #.  (e.g., 3G , 5G , 124G )

Read these directions carefully:
>>>  Type  '1''G'  to go to the top of the file, and then  ''''''  (quote quote)
>>>  to return here.
>>>  Now try  'G'  to go to the end of the file, and then  ''''''  to return here.


BLOCKS OF TEXT
--------------
It is often convenient to move through files jumping from one block of
text to the next.  To do this use braces and parentheses:

        '{'       (left brace) Move to the beginning of a paragraph
        '}'       (right brace) Move to the end of a paragraph

        '('       (left paren) Move to the beginning of a sentence
        ')'       (right paren) Move to the beginning of the next sentence

>>>  Experiment with  '}'  and  '{'  on the two paragraphs provided below.
>>>  Note that paragraphs are separated by a blank line.

        EXPERIMENT on this first paragraph.  The quick brown fox jumped
    over the seven lazy dogs.  The fox must have been very large to
    jump over seven dogs!

        EXPERIMENT on this second paragraph.  The quick brown dog
    jumped over the seven lazy foxes.  The dog didn't have to be nearly
    as large, since foxes aren't too big.

>>>  Try out  ')'  and  '('  on the two paragraphs provided above.
>>>  Notice that sentences are separated by two blank spaces.

C programmers find it useful to move by sections, since sections may be
delimited by a left brace in the first column.  By placing the opening
brace of a C subroutine in the first column, you can move to the top of
the next subroutine, using '[''[' and  ']'']' .

        '[''['      Move to the beginning of a section
        ']'']'      Move to the end of a section

Note that if vi does not find a left brace at the far left, it will
move to the top or bottom of the file.

>>>  Now try  ']'']'  then  ']'']'  and  '[''['  on the subroutines provided below:

main()
{
    helloworld();
}

helloworld()
{
    printf( "Hello world\n" );
}


SEARCHING
---------
This enables you to jump to the next occurrence of a string in a file.
To initially find the string use:

    '/'string      Find string looking forward
    '?'string      Find string looking backward

To find additional occurrences of the string type:

        'n'        Repeat last / or ? command
        'N'        Reverse last / or ? command

vi may search past the bottom of the file and then start again at the top.
(Or, vi may search past the top and then start again at the bottom.)

>>>  You are going to search for a string, find the next three
>>>  occurrences.  Then flip directions and find the string until you
>>>  return to this location.  To do this:
>>>      Type   '/''t''h''e'   then press RETURN.
>>>      Type  'n'  three times.
>>>      Type  'N'  until you return to this location.

* EMACS-NOTICE: Emacs has very powerful SEARCH-COMMANDS which you may
  want to use in parallell to those above.  One of the first you want
  to try is probably C-s (ISEARCH-FORWARD).


SUMMARY
-------

        'w'       Move to the beginning of the next WORD
        'e'       Move to the END of the next word
        'b'       Move BACK to the beginning to the previous word

        '$'       Move to the end of the line
        '^'       Move to the first non-white character on the line

        '0'       Move to the first column on the line (column zero)
        #'|'      Move to an exact column on the line (column #) e.g.  5| 12|

    'f' char      FIND the next occurrence of char on the line
    't' char      Move 'TIL the next occurrence of char on the line

    'F' char      FIND the previous occurrence of char on the line
    'T' char      Move 'TIL the previous occurrence of char on the line

        ';'       Repeat the last  f, t, F, or T
        ','       Reverse the last  f, t, F, or T

        '%'       Show matching () or {} or []

        'H'       Move to the HIGHEST position in the window
        'M'       Move to the MIDDLE position in the window
        'L'       Move to the LOWEST position in the window

    'm' char      MARK this location and name it char
    ''' char      (quote character) return to line named char
    ''''''          (quote quote) return from last movement

         'G'      GO to the last line in the file
        #'G'      GO to line #.  (e.g., 3G , 5G , 175G )

        '{'       (left brace) Move to the beginning of a paragraph
        '}'       (right brace) Move to the end of a paragraph

        '('       (left paren) Move to the beginning of a sentence
        ')'       (right paren) Move to the beginning of the next sentence

        '[''['      Move to the beginning of a section
        ']'']'      Move to the end of a section

    '/'string      Find string looking forward
    '?'string      Find string looking backward

        'n'        Repeat last / or ? command
        'N'        Reverse last / or ? command

You should now be able to move around files very efficiently.  These
commands are especially useful if you are using vi over a slow modem.
Practice the material in this lesson for a few days and then take
either the third vi tutorial to learn how to copy, cut, and paste, or
the forth vi tutorial to learn additional insertion techniques.

Copyright (c) 1992 Jill Kliger and Wesley Craig.  All Rights Reserved.