1ex(1) User Commands ex(1)
2
3
4
6 ex - text editor
7
9 /usr/bin/ex [-| -s] [-l] [-L] [-R] [-r [file]] [-t tag]
10 [-v] [-V] [-x] [-wn] [-C] [+command | -c command] file...
11
12
13 /usr/xpg4/bin/ex [-| -s] [-l] [-L] [-R] [-r [file]]
14 [-t tag] [-v] [-V] [-x] [-wn] [-C]
15 [+command | -c command] file...
16
17
18 /usr/xpg6/bin/ex [-| -s] [-l] [-L] [-R] [-r [file]]
19 [-t tag] [-v] [-V] [-x] [-wn] [-C]
20 [+command | -c command] file...
21
22
24 The ex utility is the root of a family of editors: ex and vi. ex is a
25 superset of ed(1), with the most notable extension being a display
26 editing facility. Display based editing is the focus of vi.
27
28
29 If you have a CRT terminal, you can wish to use a display based editor;
30 in this case see vi(1), which is a command which focuses on the dis‐
31 play-editing portion of ex.
32
33
34 If you have used ed you find that, in addition to having all of the ed
35 commands available, ex has a number of additional features useful on
36 CRT terminals. Intelligent terminals and high speed terminals are very
37 pleasant to use with vi. Generally, the ex editor uses far more of the
38 capabilities of terminals than ed does, and uses the terminal capabil‐
39 ity data base (see terminfo(4)) and the type of the terminal you are
40 using from the environment variable TERM to determine how to drive your
41 terminal efficiently. The editor makes use of features such as insert
42 and delete character and line in its visual command (which can be
43 abbreviated vi) and which is the central mode of editing when using the
44 vi command.
45
46
47 The ex utility contains a number of features for easily viewing the
48 text of the file. The z command gives easy access to windows of text.
49 Typing ^D (CTRL-D) causes the editor to scroll a half-window of text
50 and is more useful for quickly stepping through a file than just typing
51 return. Of course, the screen-oriented visual mode gives constant
52 access to editing context.
53
54
55 The ex utility gives you help when you make mistakes. The undo (u) com‐
56 mand allows you to reverse any single change which goes astray. ex
57 gives you a lot of feedback, normally printing changed lines, and indi‐
58 cates when more than a few lines are affected by a command so that it
59 is easy to detect when a command has affected more lines than it should
60 have.
61
62
63 The editor also normally prevents overwriting existing files, unless
64 you edited them, so that you do not accidentally overwrite a file other
65 than the one you are editing. If the system (or editor) crashes, or you
66 accidentally hang up the telephone, you can use the editor recover com‐
67 mand (or -r file option) to retrieve your work. This gets you back to
68 within a few lines of where you left off.
69
70
71 The ex utility has several features for dealing with more than one file
72 at a time. You can give it a list of files on the command line and use
73 the next (n) command to deal with each in turn. The next command can
74 also be given a list of file names, or a pattern as used by the shell
75 to specify a new set of files to be dealt with. In general, file names
76 in the editor can be formed with full shell metasyntax. The metacharac‐
77 ter `%' is also available in forming file names and is replaced by the
78 name of the current file.
79
80
81 The editor has a group of buffers whose names are the ASCII lower-case
82 letters (a-z). You can place text in these named buffers where it is
83 available to be inserted elsewhere in the file. The contents of these
84 buffers remain available when you begin editing a new file using the
85 edit (e) command.
86
87
88 There is a command & in ex which repeats the last substitute command.
89 In addition, there is a confirmed substitute command. You give a range
90 of substitutions to be done and the editor interactively asks whether
91 each substitution is desired.
92
93
94 It is possible to ignore the case of letters in searches and substitu‐
95 tions. ex also allows regular expressions which match words to be con‐
96 structed. This is convenient, for example, in searching for the word
97 ``edit'' if your document also contains the word ``editor.''
98
99
100 ex has a set of options which you can set to tailor it to your liking.
101 One option which is very useful is the autoindent option that allows
102 the editor to supply leading white space to align text automatically.
103 You can then use ^D as a backtab and space or tab to move forward to
104 align new code easily.
105
106
107 Miscellaneous useful features include an intelligent join (j) command
108 that supplies white space between joined lines automatically, commands
109 < and > which shift groups of lines, and the ability to filter portions
110 of the buffer through commands such as sort.
111
113 The following options are supported:
114
115 − | -s Suppresses all interactive user feedback. This
116 is useful when processing editor scripts.
117
118
119 -l Sets up for editing LISP programs.
120
121
122 -L Lists the name of all files saved as the
123 result of an editor or system crash.
124
125
126 -R Readonly mode. The readonly flag is set, pre‐
127 venting accidental overwriting of the file.
128
129
130 -r file Edits file after an editor or system crash.
131 (Recovers the version of file that was in the
132 buffer when the crash occurred.)
133
134
135 -t tag Edits the file containing the tag and posi‐
136 tions the editor at its definition. It is an
137 error to specify more than one -t option.
138
139
140 -v Starts up in display editing state, using vi.
141 You can achieve the same effect by typing the
142 vi command itself.
143
144
145 -V Verbose. When ex commands are read by means of
146 standard input, the input is echoed to stan‐
147 dard error. This can be useful when processing
148 ex commands within shell scripts.
149
150
151 -x Encryption option. Simulates the X command and
152 prompts the user for a key. This key is used
153 to encrypt and decrypt text using the algo‐
154 rithm of the crypt command. The X command
155 makes an educated guess to determine whether
156 text read in is encrypted or not. The tempo‐
157 rary buffer file is encrypted also, using a
158 transformed version of the key typed in for
159 the -x option.
160
161
162 -wn Sets the default window size to n. This is
163 useful when using the editor over a slow speed
164 line.
165
166
167 -C Encryption option. Same as the -x option,
168 except that -C simulates the C command. The C
169 command is like the X command, except that all
170 text read in is assumed to have been
171 encrypted.
172
173
174 +command | -c command Begins editing by executing the specified edi‐
175 tor command (usually a search or positioning
176 command).
177
178
179 /usr/xpg4/bin/ex, /usr/xpg6/bin/ex
180
181 If both the -t tag and the -c command options are given, the -t tag
182 is processed first. That is, the file containing the tag is
183 selected by -t and then the command is executed.
184
185
187 The following operand is supported:
188
189 file A path name of a file to be edited.
190
191
193 This section defines the ex states, commands, initializing options, and
194 scanning pattern formations.
195
196 ex States
197 Command Normal and initial state. Input prompted for by ":". The
198 line kill character cancels a partial command.
199
200
201 Insert Entered by a, i, or c. Arbitrary text can be entered. Insert
202 state normally is terminated by a line having only "." on
203 it, or, abnormally, with an interrupt.
204
205
206 Visual Entered by typing vi. Terminated by typing Q or ^\ (Con‐
207 trol-\).
208
209
210 ex Command Names and Abbreviations
211 Command Abbrevi- Command Abbrevi- Command Abbrevi-
212 Name ation Name ation Name ation
213
214 abbrev ab map set se
215
216 append a mark ma shell sh
217
218 args ar move m source so
219
220 change c next n substitute s
221
222 copy co number nu unabbrev unab
223
224 delete d preserve pre undo u
225
226 edit e print p unmap unm
227
228 file f put pu version ve
229
230 global g quit q visual vi
231
232 insert i read r write
233 w
234
235 join j recover rec xit x
236
237 list l rewind rew yank ya
238
239
240
241 Join Command Arguments
242 Join [range] j[oin][!] [count] [flags]
243
244
245
246
247 If count is specified:
248
249 /usr/bin/ex, /usr/xpg6/bin/ex
250
251 If no address is specified, the join command behaves as if 2addr
252 were the current line and the current line plus count (.,. +
253 count). If one address is specified, the join command behaves as if
254 2addr were the specified address and the specified address plus
255 count ( addr, addr + count).
256
257
258 /usr/xpg4/bin/ex
259
260 If no address is specified, the join command behaves as if 2addr
261 were the current line and the current line plus count -1 (.,. +
262 count -1). If one address is specified, the join command behaves as
263 if 2addr were the specified address and the specified address plus
264 count -1 ( addr, addr + count -1).
265
266
267 /usr/bin/ex, /usr/xpg4/bin/ex, /usr/xpg6/bin/ex
268
269 If two or more addresses are specified, the join command behaves as
270 if an additional address, equal to the last address plus count -1
271 (addr1, ..., lastaddr, lastaddr + count -1), was specified. If
272 this results in a second address greater than the last line of the
273 edit buffer, it is corrected to be equal to the last line of the
274 edit buffer.
275
276
277
278 If no count is specified:
279
280 /usr/bin/ex, /usr/xpg4/bin/ex, /usr/xpg6/bin/ex
281
282 If no address is specified, the join command behaves as if 2addr
283 were the current line and the next line (.,. +1). If one address is
284 specified, the join command behaves as if 2addr were the specified
285 address and the next line ( addr, addr +1).
286
287
288 Additional ex Command Arguments
289 /usr/bin/ex, /usr/xpg6/bin/ex
290
291 For the following ex commands, if count is specified, it is equiva‐
292 lent to specifying an additional address to the command. The addi‐
293 tional address is equal to the last address specified to the com‐
294 mand (either explicitly or by default) plus count-1. If this
295 results in an address greater than the last line of the edit buf‐
296 fer, it is corrected to equal the last line of the edit buffer.
297
298
299 /usr/xpg4/bin/ex
300
301 For the following ex commands, if both a count and a range are
302 specified for a command that uses them, the number of lines
303 affected is taken from the count value rather than the range. The
304 starting line for the command is taken to be the first line
305 addressed by the range.
306
307
308
309
310
311 Abbreviate ab[brev] word rhs
312 Append [line]a[ppend][!]
313 Arguments ar[gs]
314 Change [range] c[hange][!] [count]
315 Change Directory chd[ir][!] [directory]; cd[!] [directory]
316 Copy [range] co[py] line [flags]; [range] t
317 line [flags]
318 Delete [range] d[elete] [buffer] [count] [flags]
319 Edit e[dit][!] [+line][file]; ex[!] [+line]
320 [file]
321 File f[ile] [file]
322 Global [range] g[lobal] /pattern/ [commands];
323 [range] v /pattern/ [commands]
324 Insert [line] i[nsert][!]
325 List [range] l[ist] [count] [flags]
326 Map map[!] [x rhs]
327 Mark [line] ma[rk] x; [line] k x
328 Move [range] m[ove] line
329 Next n[ext][!] [file ...]
330 Open [line] o[pen] /pattern/ [flags]
331 Preserve pre[serve]
332 Put [line] pu[t] [buffer]
333
334 Quit q[uit][!]
335 Read [line] r[ead][!] [file]
336 Recover rec[over] file
337 Rewind rew[ind][!]
338 Set se[t] [option[=[value]]...] [nooption...]
339 [option?...] [all]
340 Shell sh[ell]
341 Source so[urce] file
342 Suspend su[spend][!]; st[op][!]
343 Tag ta[g][!] tagstring
344 Unabbreviate una[bbrev] word
345 Undo u[ndo]
346 Unmap unm[ap][!] x
347 Visual [line] v[isual] [type] [count] [flags]
348 Write [range] w[rite][!] [>>] [file]; [range]
349 w[rite][!] [file]; [range] wq[!] [>>]
350 [file]
351 Write and Exit [range] x[it][!] [file]
352 Yank [range] ya[nk] [buffer] [count]
353 Adjust Window [line] z [type] [count] [flags]
354 Escape ! command [range]! command
355 Scroll EOF
356 Write Line Number [line] = [flags]
357 Execute @ buffer; * buffer
358
359
360 /usr/bin/ex, /usr/xpg4/bin/ex, /usr/xpg6/bin/ex
361
362 For the following ex commands, if count is specified, it is equiva‐
363 lent to specifying an additional address to the command. The addi‐
364 tional address is equal to the last address specified to the com‐
365 mand (either explicitly or by default) plus count-1. If this
366 results in an address greater than the last line of the edit buf‐
367 fer, it is corrected to equal the last line of the edit buffer.
368
369
370
371
372
373 Number [range] nu[mber] [count] [flags]; [range]
374 | # [count]
375 [flags]
376 Print [range] p[rint] [count] [flags]
377 Substitute [range] s[ubstitute] [/pat‐
378 tern/repl/[options] [count] [flags]]
379 Shift Left [range] < [count] [flags]
380 Shift Right [range] > [count] [flags]
381 Resubstitute [range] & [options] [count] [flags];
382 [range] s[ubstitute] [options] [count]
383 [flags]; [range] ~ [options] [count
384 [flags]
385
386
387 ex Commands
388 C forced encryption
389 X heuristic encryption
390 & resubst
391 CR print next
392 > rshift
393 < lshift
394 ^D scroll
395 z window
396 ! shell escape
397
398
399 ex Command Addresses
400 n line n
401
402 . current
403 $ last
404 + next
405 - previous
406 +n n forward
407 % 1,$
408 /pat next with pat
409 ?pat previous with pat
410 x-n n before x
411 x,y x through y
412 'x marked with x
413 " previous context
414
415
416 Initializing Options
417 EXINIT place set's here in environment variable
418 $HOME/.exrc editor initialization file
419 ./.exrc editor initialization file
420 set x enable option x
421 set nox disable option x
422 set x=val give value val to option x
423 set show changed options
424 set all show all options
425 set x? show value of option x
426
427
428 Useful Options and Abbreviations
429 autoindent ai supply indent
430 autowrite aw write before changing files
431 directory pathname of directory for temporary
432 work files
433 exrc ex allow vi/ex to read the .exrc in the
434 current directory. This option is set
435 in the EXINIT shell variable or in
436 the .exrc file in the $HOMEdirectory.
437 ignorecase ic ignore case of letters in scanning
438 list print ^I for tab, $ at end
439 magic treat . [ * special in patterns
440 modelines first five lines and last five lines
441 executed as vi/ex commands if they
442 are of the form ex:command: or
443 vi:command:
444 number nu number lines
445 paragraphs para macro names that start paragraphs
446 redraw simulate smart terminal
447 report informs you if the number of lines
448 modified by the last command is
449 greater than the value of the report
450 variable
451 scroll command mode lines
452 sections sect macro names that start sections
453 shiftwidth sw for < >, and input ^D
454 showmatch sm to ) and } as typed
455 showmode smd show insert mode in vi
456 slowopen slow stop updates during insert
457 term specifies to vi the type of terminal
458 being used (the default is the value
459 of the environment variable TERM)
460 window visual mode lines
461 wrapmargin wm automatic line splitting
462 wrapscan ws search around end (or beginning) of
463 buffer
464
465
466 Scanning Pattern Formation
467 ^ beginning of line
468 $ end of line
469
470 . any character
471 \< beginning of word
472 \> end of word
473 [str] any character in str
474 [^str] any character not in str
475 [xy] any character between x and y
476 * any number of preceding characters
477
478
480 See environ(5) for descriptions of the following environment variables
481 that affect the execution of ex: HOME, LANG, LC_ALL, LC_COLLATE,
482 LC_CTYPE, LC_MESSAGES, NLSPATH, PATH, SHELL, and TERM.
483
484 COLUMNS Override the system-selected horizontal screen size.
485
486
487 EXINIT Determine a list of ex commands that are executed on editor
488 start-up, before reading the first file. The list can con‐
489 tain multiple commands by separating them using a vertical-
490 line (|) character.
491
492
493 LINES Override the system-selected vertical screen size, used as
494 the number of lines in a screenful and the vertical screen
495 size in visual mode.
496
497
499 The following exit values are returned:
500
501 0 Successful completion.
502
503
504 >0 An error occurred.
505
506
508 /var/tmp/Exnnnnn editor temporary
509
510
511 /var/tmp/Rxnnnnn named buffer temporary
512
513
514 /usr/lib/expreserve preserve command
515
516
517 /usr/lib/exrecover recover command
518
519
520 /usr/lib/exstrings error messages
521
522
523 /usr/share/lib/terminfo/* describes capabilities of terminals
524
525
526 /var/preserve/login preservation directory (where login is the
527 user's login)
528
529
530 $HOME/.exrc editor startup file
531
532
533 ./.exrc editor startup file
534
535
537 See attributes(5) for descriptions of the following attributes:
538
539 /usr/bin/ex
540 ┌─────────────────────────────┬─────────────────────────────┐
541 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
542 ├─────────────────────────────┼─────────────────────────────┤
543 │Availability │SUNWcsu │
544 │CSI │Enabled │
545 └─────────────────────────────┴─────────────────────────────┘
546
547 /usr/xpg4/bin/ex
548 ┌─────────────────────────────┬─────────────────────────────┐
549 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
550 ├─────────────────────────────┼─────────────────────────────┤
551 │Availability │SUNWxcu4 │
552 │CSI │Enabled │
553 ├─────────────────────────────┼─────────────────────────────┤
554 │Interface Stability │Standard │
555 └─────────────────────────────┴─────────────────────────────┘
556
557 /usr/xpg6/bin/ex
558 ┌─────────────────────────────┬─────────────────────────────┐
559 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
560 ├─────────────────────────────┼─────────────────────────────┤
561 │Availability │SUNWxcu6 │
562 │CSI │Enabled │
563 ├─────────────────────────────┼─────────────────────────────┤
564 │Interface Stability │Standard │
565 └─────────────────────────────┴─────────────────────────────┘
566
568 ed(1), edit(1), grep(1), sed(1), sort(1), vi(1), curses(3CURSES),
569 term(4), terminfo(4), attributes(5), environ(5), standards(5)
570
571
572 Solaris Advanced User's Guide
573
575 The vi and ex utilities are based on software developed by The Univer‐
576 sity of California, Berkeley California, Computer Science Division,
577 Department of Electrical Engineering and Computer Science.
578
580 Several options, although they continue to be supported, have been
581 replaced in the documentation by options that follow the Command Syntax
582 Standard (see Intro(1)). The − option has been replaced by -s, a -r
583 option that is not followed with an option-argument has been replaced
584 by -L, and +command has been replaced by -c command.
585
586
587 The message file too large to recover with -r option, which is seen
588 when a file is loaded, indicates that the file can be edited and saved
589 successfully, but if the editing session is lost, recovery of the file
590 with the -r option is not possible.
591
592
593 The z command prints the number of logical rather than physical lines.
594 More than a screen full of output can result if long lines are present.
595
596
597 File input/output errors do not print a name if the command line -s
598 option is used.
599
600
601 The editing environment defaults to certain configuration options. When
602 an editing session is initiated, ex attempts to read the EXINIT envi‐
603 ronment variable. If it exists, the editor uses the values defined in
604 EXINIT, otherwise the values set in $HOME/.exrc are used. If
605 $HOME/.exrc does not exist, the default values are used.
606
607
608 To use a copy of .exrc located in the current directory other than
609 $HOME, set the exrc option in EXINIT or $HOME/.exrc. Options set in
610 EXINIT can be turned off in a local .exrc only if exrc is set in EXINIT
611 or $HOME/.exrc. In order to be used, .exrc in $HOME or the current
612 directory must fulfill these conditions:
613
614 o It must exist.
615
616 o It must be owned by the same userid as the real userid of
617 the process, or the process has appropriate privileges.
618
619 o It is not writable by anyone other than the owner.
620
621
622 There is no easy way to do a single scan ignoring case.
623
624
625 The editor does not warn if text is placed in named buffers and not
626 used before exiting the editor.
627
628
629 Null characters are discarded in input files and cannot appear in
630 resultant files.
631
632
633
634SunOS 5.11 15 Jun 2004 ex(1)