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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
|
.TH VI 1
.CT 1 editor
.SH NAME
ex, edit, vi \- text editor
.SH SYNOPSIS
.B ex
[
.I option ...
]
.I file ...
.PP
.B edit
[
.I option ...
]
.I file ...
.PP
.B vi
[
.I option ...
]
.I file ...
.SH DESCRIPTION
.I Ex
is elaborated from
.IR ed (1).
.I Vi
is the display editing aspect of
.IR ex ;
.I edit
is a simplified subset of
.IR ex .
The editors work on several
.I files
simultaneously.
.I Vi
gets the terminal type from environment variable
.BR TERM .
.PP
The options are:
.TP
.BI -r " file
Recover the
.I file
after a crash in the editor.
If no file is specified, list all saved files.
.TP
.B -l
Lisp indent mode; give special meaning to editor commands
.BR ()[]{} .
.TP
.BI -w n
Default window size is
.I n
lines.
.TP
.B -x
Edit encrypted files; a key will be prompted for.
.TP
.B -R
Read only; no files will be changed.
.TP
.BI + cmd
Execute the specified
.I ex
command upon entering the editor.
.PP
The editors begin in `command mode'.
An
.SM ESC
character typed in command mode cancels the command.
The commands
.B
a A c C i I o O R s S
enter input mode, where arbitrary text may be entered.
.SM ESC
or interrupt returns to command mode.
The commands
.B
: / ? !
take input from the last line of the screen, which is
ended by a newline, or canceled by an interrupt.
.PP
A number preceding commands
.B z G |
specifies a line.
A number before almost any other command causes it
to be repeated.
.PP
In the following summary of
.I vi
commands
.B ^
means the `control' key.
Commands so marked work in input mode;
others work in command mode.
.PP
.de fq
\&\f5\\$1\fR \\$2 \\$3 \\$4 \\$5 \\$6
..
.de fz
\&\f5\\$1 \fI\\$2\fR \\$3 \\$4 \\$5 \\$6
..
.ta \w'\f5:e + file'u
File manipulation
.2C
.fq :w write back changes
.fz :w file write \fIfile\fR
.fz :w! file overwrite \fIfile\fR
.fq :q quit
.fq :q! quit, discarding changes
.fz :e file edit \fIfile\fR
.fq :e! reedit, discarding changes
.fq ":e\ +" file edit, starting at end
.fz ":e\ +" starting at line \fIn\fP
.fq :sh run shell, then return
.fz :! cmd run shell command
.fq :n edit next \fIfile\fR argument
.fz : ex-cmd do editor command
.1C
.PP
Positioning in file
.2C
.fq ^F forward screen
.fq ^B backward screen
.fq ^D down half screen
.fq ^U up half screen
.fq G "to specified line (end default)
.fz / pat next line matching \fIpat\fR
.fz ? pat previous line matching
.fq n repeat last "\f5\e or ?\fP
.fz /\fIpat\fP/\o'+_' n "\fIn\fRth line after or before \fIpat\fR
.fq ( beginning of sentence
.fq ) end of sentence
.fq { beginning of paragraph
.fq } end of paragraph
.fq % find matching \f5(){}\fP
.1C
.PP
Adjusting the screen
.2C
.fq ^L clear and redraw
.fq ^R "retype, eliminate \f5@\fR lines
.fq z redraw, current line at window top
.fq z- \&... at bottom
.fq z. \&... at center
.fq /\fIpat\fP/z- \fIpat\fR line at bottom
.fz z n use \fIn\fR-line window
.fq ^E scroll down one line
.fq ^Y scroll up one line
.1C
.PP
Marking and returning
.2C
.fq `` move cursor to previous context
.fq '' \&... at first nonwhite in line
.fz m x "mark position with letter \fIx\fR
.fz ` x move cursor to mark
.fz ' x \&... at first nonwhite
.1C
.PP
Line positioning
.2C
.fq H top line of screen
.fq L bottom line
.fq M middle line
.fq + next line, at first nonwhite
.fq - previous line, at first nonwhite
<newline> same as \f5+\fR
.fq j next line, same column
.fq k previous line, same column
.1C
.PP
Character positioning
.2C
.fq ^ first nonwhite (not CTRL)
.fq 0 beginning of line
.fq $ end of line
.fq l forward
.fq h backward
.fq ^L ^H same as \f5l h\fR
<space> same as \f5l\fR
.fz f x find \fIx\fR forward
.fz F x find backward
.fz t x upto \fIx\fR forward
.fz T x back upto \fIx\fR
.fq ; repeat last \f5f F t T\fR
.fq , opposite of \f5;\fR
.fq | to specified column
.fq % find matching \f5(){}\fR
.1C
.PP
Words, sentences, paragraphs
.2C
.fq w word forward
.fq b word backward
.fq e end of word
.fq ) next sentence
.fq ( previous sentence
.fq } next paragraph
.fq { previous paragraph
.fq W blank-delimited word
.fq B backward to ...
.fq E to end of ...
.1C
.PP
Corrections
.2C
.fq ^H erase last character
.fq ^W erase last word
erase your erase, same as \f5^H\fR
kill your kill, erase this line
.fq \e quotes your erase or kill
ESC return to command mode
.fq ^? interrupt, return to command mode
.fq ^D backtab over autoindent
.fq ^V quote nonprinting character
.1C
.PP
Insert and replace
.2C
.fq a append after cursor
.fq A append at end of line
.fq i insert before cursor
.fq I insert before first non-blank
.fq o open below line
.fq O open above
.fz r x replace one character
.fz R text replace characters
.1C
.PP
Operators
.PP
.br
Operators are followed by cursor motion and affect all
text that would have been moved over:
.B dw
deletes a word.
Double the operator, e.g.\&
.BR dd ,
to affect whole lines.
.2C
.fq d delete
.fq c change
.fq y yank lines to buffer
.fq < left shift
.fq > right shift
.fq ! filter through command
.fq = Lisp indent
.1C
.PP
Miscellaneous operators
.2C
.fq C change rest of line (\f5c$\fR)
.fq D delete rest of line (\f5d$\fR)
.fq s substitute characters (\f5cd\fR)
.fq S substitute lines (\f5cc\fR)
.fq J join lines
.fq x delete characters (\f5dl\fR)
.fq X ... before cursor (\f5dh\fR)
.fq Y yank lines (\f5yy\fR)
.1C
.PP
Yank and put
.2C
.fq p put buffer after cursor
.fq P put buffer before cursor
\f5"\fI x \f5p\fR put from buffer \fIx\fR
.fz x y yank to buffer \fIx\fR
.fz x d delete to buffer \fIx\fR
.1C
.PP
Undo, redo, retrieve
.2C
.fq u undo last change
.fq U restore current line
.fq . repeat last change
\f5"\fI n \f5p\fR retrieve \fIn\fR-th last delete
.1C
.PP
Special ex commands
.PP
.br
.I Ex
understands most
.I ed
commands, plus the commands indicated with
.B :
in the
.I vi
summary, plus the following, shown with their
shortest possible spellings:
.PD0
.2C
.BI ab brev
.BI ar gs
.BI co py
.BI map
.BI ma rk
.BI n ext
.BI nu mber
.BI pre serve
.BI pu t
.BI re ad
.BI rec over
.BI rew ind
.BI se t
.BI sh ell
.BI so urce
.BI st op
.BI una bbrev
.BI u ndo
.BI unm ap
.BI ve rsion
.BI vi sual
.BI x it
.BI ya nk
.BI z " window"
.BI < " lshift
.BI > " rshift
.BI ^D " scroll
.1C
The
.B set
command
controls various options;
.L set all
shows the list.
.SH EXAMPLES
.2C
.PD0
.TF /\fItext\fR<newline>
.TP
.B \(<-\(da\(ua\(->
arrow keys move the cursor
.TP
.B hjkl
same as arrow keys
.TP
.BI i text\fR<ESC>
.RI insert " text
.TP
.BI cw new\fR<ESC>
.RI "change word to " new
.TP
.B 3dw
delete 3 words
.TP
.B ZZ
exit, saving changes
.TP
.BI / text\fR<newline>
.RI "search for " text
.TP
.B ^U ^D
scroll up or down
.1C
.PD
.SH FILES
.TF /usr/lib/ex?.?preserve
.TP
.F /usr/lib/ex?.?recover
recover command
.TP
.F /usr/lib/ex?.?preserve
preserve command
.TP
.F /etc/termcap
describes capabilities of terminals
.TP
.F $HOME/.exrc
editor startup file
.TP
.F /tmp/Ex*
editor temporary
.TP
.F /tmp/Rx*
named buffer temporary
.TP
.F /usr/preserve
preservation directory
.SH SEE ALSO
.IR ed (1),
.IR sam (9.1),
.IR sed (1)
.br
W. Joy and M. Horton,
`An Introduction to Display Editing with Vi',
in
.I
Unix Programmer's Manual, Seventh Edition, Virtual VAX-11 Version,
1980, Vol 2C
(Berkeley)
.ig
.SH BUGS
The
.I undo
command causes all marks to be lost on lines changed and then restored
if the marked lines were changed.
.br
.I Undo
never clears the buffer modified condition.
.br
The
.I z
command prints a number of logical rather than physical lines.
More than a screen full of output may result if long lines are present.
.br
File input/output errors don't print a name if the
.LR -
option is used.
.br
There is no easy way to do a single scan ignoring case.
.br
The editor does not warn if text is placed in named buffers and not used
before exiting the editor.
.br
Null characters are discarded in input files, and cannot appear in resultant
files.
.br
Software tabs using
.B ^T
work only immediately after the
.LR autoindent .
.br
The
.L wrapmargin
option can be fooled since it looks at output columns when blanks are typed.
If a long word passes through the margin and onto the next line without a
break, then the line won't be broken.
.br
The
.I source
command does not work when executed as
.BR :source ;
there is no way to use the
.BR :append ,
.BR :change ,
and
.BR :insert
commands in
.I vi,
since it is not possible to give
more than one line of input to a
.B :
escape.
To use these
on a
.B :global
you must
.B Q
to
.I ex
command mode,
execute them, and then reenter the screen editor with
.L vi
or
.LR open .
..
|