summaryrefslogtreecommitdiffstats
path: root/emacs.d/nxhtml/etc/viper-tut/5tricks
blob: c1e414e1d8aad747e9b746f42f7325f082fd5b0b (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
Viper tutorial #5: Tricks and Timesavers

This lesson lasts 10-15 minutes.  You should have a strong
understanding of tutorials #1-3 before working through these timesaving
techniques.  Lines which begin with  >>>  mark exercises you should
try.  When you want to exit this tutorial type  'Z''Z' .


CASE CONVERSION
---------------
When you want to change an upper-case character to a lower-case
character (or lower-case to upper-case) there is a single command which
does both:

        '~'     (tilde) Convert case of current character

>>>  Move the cursor to be OVER the first character in the example
>>>  line below.  Press  '~'  until you have changed the case of the
>>>  entire line.  (  '~'  will advance to the right automatically).

        bOB WENT TO pARIS, fRANCE, TO SEE THE #1 CYCLING EVENT.  end.

Note that  '~'  only affects alphabetic characters.


UNDOING
-------
* EMACS-NOTICE: Uppercase U does the same thing as lowercase u in
  Viper so this part of the tutorial which was about U has been
  removed.


REPEAT LAST COMMAND
-------------------
Often you want to make the same change at multiple locations in the
file.  To help accomplish this, vi remembers your previous action.

        '.'       (dot) repeat last change

>>> Go through the example below changing "FISH" to "TOAD":
>>>     Go to the "F" in the first instance of "FISH"
>>>     To change the word:  type  'c''w'  then type  TOAD  then press ESC
>>>     Move the cursor to "F" in the second occurence of "FISH"
>>>     Type  '.'  (dot)
>>>     Move the cursor to "F" in the final occurence of "FISH"
>>>     Type  '.'  (dot)
>>>     Now move the cursor to each occurence of "CROW";  Type  '.'  (dot)

        EXAMPLE:  The FISH fed the cat.  The CROW fed the cat.  Example
        text is FISH to make interesting.  The man fed the CROW.  The
        worm fed the FISH.  Example text is hard to make CROW.  END.

>>> Go through the example above deleting all occurences of "TOAD":
>>>     Move to the beginning of the EXAMPLE paragraph above.
>>>     Type  '/''T''O''A''D'  and press RETURN (recall tutorial #2)
>>>     Delete the word by typing  'd''w'
>>>     Type  'n'  to move to the next occurence of "TOAD"
>>>     Type  '.'  (dot) to repeat the  dw  command
>>>     Use  'n''.'  to delete the remaining "TOAD"s

Note that  '.'  only repeats changes, not cursor movements.

* EMACS-NOTICE: In Emacs  '.'  also repeat undo and redo.

* EMACS-NOTICE: Emacs KEYBOARD-MACROS are very powerful for repeating
  whole sequences of keyboard commands.


WINDOW ACTIONS
--------------
You are already familiar with the  C-u  (depress the control key and
type u) and C-d  commands from tutorial #1.

        C-d     Move DOWN one half-screen
        C-u     Move UP one half-screen

There are several related commands:

        C-f     Move FORWARD one full-screen
        C-b     Move BACKWARD one full-screen

        C-e     Move the window down one line without moving cursor
        C-y     Move the window up one line without moving cursor

The  C-e  and  C-y  commands may seem obscure; however, notice that on
the keyboard,  e and  y  are close to  d  and  u  respectively.  This
should help you remember that  C-e  moves DOWN, and  C-y  moves UP.

Recall the  'H'  'M'  'L'  (HIGH MIDDLE LOW) window commands from Tutorial 2.
Consider a scenario where you want to yank from the current line to a
line near the top of the window.  You could use  C-e  and  C-y  to
position the text in the window before you use the  yH  command.

The  'z'  command also moves the window without moving your cursor:

    'z'<RETURN>   Position the current line to top of window
        'z''.'      Position the current line to middle of window
        'z''-'      Position the current line to bottom of window

>>>     Move to this line.  Type  'z'  and press RETURN.  Notice that
>>>     this text and the cursor have moved to the top of the window.
>>>     Try  'z''-'  and  'z''.'  also.


FILE AND DISPLAY CONTROL
------------------------

* EMACS-NOTICE: In vi C-g shows the status of the current file, but
  C-g in Emacs in most situation stops what Emacs is doing. To get
  information about the current file you can use C-c C-g instead when
  Viper is in vi state.

* EMACS-NOTICE: In vi C-l refreshes the screen, but C-l in Emacs calls
  the command recenter.


SUSPENDING VI
-------------
* EMACS-NOTICE: In vi C-z suspends vi. However in Viper C-z is by
  default the VIPER-TOGGLE-KEY. To suspend or iconify Emacs use C-x
  C-z.


BANG COMMAND
------------
* EMACS-NOTICE: Emacs has builtin commands to sort etc.

The exclamation point,  '!'  (aka BANG), command allows you to feed text
to any Unix command.  The output of the Unix command replaces the
original text.  Here is a useful Unix command to use from within vi:

        !}fmt   Format the paragraph, joining and filling lines to
                produce output lines of up to 72 characters

>>>  Move to the example paragraph below. Type  !}fmt  and press
>>>  RETURN.  Notice the paragraph will be reformatted such that
>>>  the lines are of approximately equal length.

        EXAMPLE:
        So we grow together,
        Like to a double cherry, seeming parted,
        But yet an union in partition;
        Two lovely berries moulded on one stem;
        So, with two seeming bodies, but one heart;
        END.

Another useful command is:

       !}sort   Sort lines of a paragraph alphabetically

>>>  Move to the example text below. Type  !}sort  and press RETURN.

        OBERON          king of the fairies.
        PUCK            or Robin Goodfellow.
        HERMIA          daughter to Egeus, in love with Lysander.
        HELENA          in love with Demetrius.
        LYSANDER        in love with Hermia.
        DEMETRIUS       in love with Hermia.

Remember, any Unix command may be used this way.


SHIFTING TEXT
-------------
It is possible to shift large blocks of text right and left with the '>'
and  '<'  commands.

   '>'movement    Shift right to where the movement command specifies
   '<'movement    Shift left to where the movement command specifies

These commands work like the  'd'  command.  For example:

        '>''}'      Shift right to the end of the paragraph
        '<''}'      Shift left to the end of the paragraph
        '>''>'      Shift the current line right
        '<''<'      Shift the current line left

>>>  Move the cursor to the first line of the paragraph below.
>>>  Type  '>''>'  and  '<''<'  to shift the line back and forth.  Next
>>>  try  '>''}'  to shift the paragraph to the right, then  '<''}'  to shift
>>>  it left, then type  '.'  until all four lines start at the left edge.

        THIS IS THE FIRST LINE OF EXAMPLE TEXT
            IS
    EXAMPLE
                TEXT END


SUMMARY
-------

        '~'       (tilde) Convert case of current character

        'U'       * EMACS-NOTICE: Same as lowercase u undo in Viper.

        '.'       (dot) repeat last change

        C-d      Move DOWN one half-screen
                (depress the control key and type d)

        C-u      Move UP one half-screen
                (depress the control key and type u)

        C-f     Move FORWARD one full-screen
        C-b     Move BACKWARD one full-screen

        C-e     Move the window down one line without moving cursor
        C-y     Move the window up one line without moving cursor

    'z'<RETURN>   Position the current line to top of window
        'z''.'      Position the current line to middle of window
        'z''-'      Position the current line to bottom of window

    C-c C-g     Show status of current file
        C-l     Recenter

        '!'}fmt   Format the paragraph, joining and filling lines to
                produce output lines of up to 72 characters

       '!'}sort   Sort lines of a paragraph alphabetically

   '>'movement    Shift right to where the movement command specifies
   '<'movement    Shift left to where the movement command specifies


These commands should significantly speed up your editing. Have a nice
day.  Tutorial 6 contains even more nifty commands.

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