logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

ex.1p (221925B)


  1. '\" et
  2. .TH EX "1P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. ex
  12. \(em text editor
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. ex \fB[\fR-rR\fB] [\fR-s|-v\fB] [\fR-c \fIcommand\fB] [\fR-t \fItagstring\fB] [\fR-w \fIsize\fB] [\fIfile\fR...\fB]\fR
  17. .fi
  18. .SH DESCRIPTION
  19. The
  20. .IR ex
  21. utility is a line-oriented text editor. There are two other modes of
  22. the editor\(emopen and visual\(emin which screen-oriented editing is
  23. available. This is described more fully by the
  24. .IR ex
  25. .BR open
  26. and
  27. .BR visual
  28. commands and in
  29. .IR "\fIvi\fR\^".
  30. .P
  31. If an operand is
  32. .BR '\-' ,
  33. the results are unspecified.
  34. .P
  35. This section uses the term
  36. .IR "edit buffer"
  37. to describe the current working text. No specific implementation is
  38. implied by this term. All editing changes are performed on the edit
  39. buffer, and no changes to it shall affect any file until an editor
  40. command writes the file.
  41. .P
  42. Certain terminals do not have all the capabilities necessary to support
  43. the complete
  44. .IR ex
  45. definition, such as the full-screen editing commands (\c
  46. .IR "visual mode"
  47. or
  48. .IR "open mode" ).
  49. When these commands cannot be supported on such terminals, this
  50. condition shall not produce an error message such as ``not an editor
  51. command'' or report a syntax error. The implementation may either
  52. accept the commands and produce results on the screen that are the
  53. result of an unsuccessful attempt to meet the requirements of this volume of POSIX.1\(hy2017 or
  54. report an error describing the terminal-related deficiency.
  55. .SH OPTIONS
  56. The
  57. .IR ex
  58. utility shall conform to the Base Definitions volume of POSIX.1\(hy2017,
  59. .IR "Section 12.2" ", " "Utility Syntax Guidelines",
  60. except for the unspecified usage of
  61. .BR '\-' ,
  62. and that
  63. .BR '\(pl'
  64. may be recognized as an option delimiter as well as
  65. .BR '\-' .
  66. .P
  67. The following options shall be supported:
  68. .IP "\fB\-c\ \fIcommand\fR" 10
  69. Specify an initial command to be executed in the first edit buffer
  70. loaded from an existing file (see the EXTENDED DESCRIPTION section).
  71. Implementations may support more than a single
  72. .BR \-c
  73. option. In such implementations, the specified commands shall be
  74. executed in the order specified on the command line.
  75. .IP "\fB\-r\fP" 10
  76. Recover the named files (see the EXTENDED DESCRIPTION section).
  77. Recovery information for a file shall be saved during an editor or
  78. system crash (for example, when the editor is terminated by a signal
  79. which the editor can catch), or after the use of an
  80. .IR ex
  81. .BR preserve
  82. command.
  83. .RS 10
  84. .P
  85. A
  86. .IR crash
  87. in this context is an unexpected failure of the system or utility that
  88. requires restarting the failed system or utility. A system crash
  89. implies that any utilities running at the time also crash. In the case
  90. of an editor or system crash, the number of changes to the edit buffer
  91. (since the most recent
  92. .BR preserve
  93. command) that will be recovered is unspecified.
  94. .P
  95. If no
  96. .IR file
  97. operands are given and the
  98. .BR \-t
  99. option is not specified, all other options, the
  100. .IR EXINIT
  101. variable, and any
  102. .BR .exrc
  103. files shall be ignored; a list of all recoverable files available to
  104. the invoking user shall be written, and the editor shall exit normally
  105. without further action.
  106. .RE
  107. .IP "\fB\-R\fP" 10
  108. Set
  109. .BR readonly
  110. edit option.
  111. .IP "\fB\-s\fP" 10
  112. Prepare
  113. .IR ex
  114. for batch use by taking the following actions:
  115. .RS 10
  116. .IP " *" 4
  117. Suppress writing prompts and informational (but not diagnostic)
  118. messages.
  119. .IP " *" 4
  120. Ignore the value of
  121. .IR TERM
  122. and any implementation default terminal type and assume the terminal is
  123. a type incapable of supporting open or visual modes; see the
  124. .BR visual
  125. command and the description of
  126. .IR "\fIvi\fR\^".
  127. .IP " *" 4
  128. Suppress the use of the
  129. .IR EXINIT
  130. environment variable and the reading of any
  131. .BR .exrc
  132. file; see the EXTENDED DESCRIPTION section.
  133. .IP " *" 4
  134. Suppress autoindentation, ignoring the value of the
  135. .BR autoindent
  136. edit option.
  137. .RE
  138. .IP "\fB\-t\ \fItagstring\fR" 10
  139. Edit the file containing the specified
  140. .IR tagstring ;
  141. see
  142. .IR "\fIctags\fR\^".
  143. The tags feature represented by
  144. .BR \-t
  145. .IR tagstring
  146. and the
  147. .BR tag
  148. command is optional. It shall be provided on any system that also
  149. provides a conforming implementation of
  150. .IR ctags ;
  151. otherwise, the use of
  152. .BR \-t
  153. produces undefined results. On any system, it shall be an error to
  154. specify more than a single
  155. .BR \-t
  156. option.
  157. .IP "\fB\-v\fP" 10
  158. Begin in visual mode (see
  159. .IR "\fIvi\fR\^").
  160. .IP "\fB\-w\ \fIsize\fR" 10
  161. Set the value of the
  162. .IR window
  163. editor option to
  164. .IR size .
  165. .SH OPERANDS
  166. The following operand shall be supported:
  167. .IP "\fIfile\fR" 10
  168. A pathname of a file to be edited.
  169. .SH STDIN
  170. The standard input consists of a series of commands and input text, as
  171. described in the EXTENDED DESCRIPTION section. The implementation may
  172. limit each line of standard input to a length of
  173. {LINE_MAX}.
  174. .P
  175. If the standard input is not a terminal device, it shall be as if the
  176. .BR \-s
  177. option had been specified.
  178. .P
  179. If a read from the standard input returns an error, or if the editor
  180. detects an end-of-file condition from the standard input, it shall be
  181. equivalent to a SIGHUP asynchronous event.
  182. .SH "INPUT FILES"
  183. Input files shall be text files or files that would be text files
  184. except for an incomplete last line that is not longer than
  185. {LINE_MAX}\-1
  186. bytes in length and contains no NUL characters. By default, any
  187. incomplete last line shall be treated as if it had a trailing
  188. <newline>.
  189. The editing of other forms of files may optionally be allowed by
  190. .IR ex
  191. implementations.
  192. .P
  193. The
  194. .BR .exrc
  195. files and source files shall be text files consisting of
  196. .IR ex
  197. commands; see the EXTENDED DESCRIPTION section.
  198. .P
  199. By default, the editor shall read lines from the files to be edited
  200. without interpreting any of those lines as any form of editor command.
  201. .SH "ENVIRONMENT VARIABLES"
  202. The following environment variables shall affect the execution of
  203. .IR ex :
  204. .IP "\fICOLUMNS\fP" 10
  205. Override the system-selected horizontal screen size. See the Base Definitions volume of POSIX.1\(hy2017,
  206. .IR "Chapter 8" ", " "Environment Variables"
  207. for valid values and results when it is unset or null.
  208. .IP "\fIEXINIT\fP" 10
  209. Determine a list of
  210. .IR ex
  211. commands that are executed on editor start-up. See the EXTENDED
  212. DESCRIPTION section for more details of the initialization phase.
  213. .IP "\fIHOME\fP" 10
  214. Determine a pathname of a directory that shall be searched for an
  215. editor start-up file named
  216. .BR .exrc ;
  217. see the EXTENDED DESCRIPTION section.
  218. .IP "\fILANG\fP" 10
  219. Provide a default value for the internationalization variables that are
  220. unset or null. (See the Base Definitions volume of POSIX.1\(hy2017,
  221. .IR "Section 8.2" ", " "Internationalization Variables"
  222. for the precedence of internationalization variables used to determine
  223. the values of locale categories.)
  224. .IP "\fILC_ALL\fP" 10
  225. If set to a non-empty string value, override the values of all the
  226. other internationalization variables.
  227. .IP "\fILC_COLLATE\fP" 10
  228. .br
  229. Determine the locale for the behavior of ranges, equivalence classes,
  230. and multi-character collating elements within regular expressions.
  231. .IP "\fILC_CTYPE\fP" 10
  232. Determine the locale for the interpretation of sequences of bytes of
  233. text data as characters (for example, single-byte as opposed to
  234. multi-byte characters in arguments and input files), the behavior of
  235. character classes within regular expressions, the classification of
  236. characters as uppercase or lowercase letters, the case conversion of
  237. letters, and the detection of word boundaries.
  238. .IP "\fILC_MESSAGES\fP" 10
  239. .br
  240. Determine the locale that should be used to affect the format and
  241. contents of diagnostic messages written to standard error.
  242. .IP "\fILINES\fP" 10
  243. Override the system-selected vertical screen size, used as the number
  244. of lines in a screenful and the vertical screen size in visual mode.
  245. See the Base Definitions volume of POSIX.1\(hy2017,
  246. .IR "Chapter 8" ", " "Environment Variables"
  247. for valid values and results when it is unset or null.
  248. .IP "\fINLSPATH\fP" 10
  249. Determine the location of message catalogs for the processing of
  250. .IR LC_MESSAGES .
  251. .IP "\fIPATH\fP" 10
  252. Determine the search path for the shell command specified in the
  253. .IR ex
  254. editor commands
  255. .BR ! ,
  256. .BR shell ,
  257. .BR read ,
  258. and
  259. .BR write ,
  260. and the open and visual mode command
  261. .BR ! ;
  262. see the description of command search and execution in
  263. .IR "Section 2.9.1.1" ", " "Command Search and Execution".
  264. .IP "\fISHELL\fP" 10
  265. Determine the preferred command line interpreter for use as the default
  266. value of the
  267. .BR shell
  268. edit option.
  269. .IP "\fITERM\fP" 10
  270. Determine the name of the terminal type. If this variable is unset or
  271. null, an unspecified default terminal type shall be used.
  272. .SH "ASYNCHRONOUS EVENTS"
  273. The following term is used in this and following sections to specify
  274. command and asynchronous event actions:
  275. .IP "\fIcomplete\ write\fP" 10
  276. .br
  277. A complete write is a write of the entire contents of the edit buffer
  278. to a file of a type other than a terminal device, or the saving of the
  279. edit buffer caused by the user executing the
  280. .IR ex
  281. .BR preserve
  282. command. Writing the contents of the edit buffer to a temporary file
  283. that will be removed when the editor exits shall not be considered a
  284. complete write.
  285. .P
  286. The following actions shall be taken upon receipt of signals:
  287. .IP SIGINT 10
  288. If the standard input is not a terminal device,
  289. .IR ex
  290. shall not write the file or return to command or text input mode, and
  291. shall exit with a non-zero exit status.
  292. .RS 10
  293. .P
  294. Otherwise, if executing an open or visual text input mode command,
  295. .IR ex
  296. in receipt of SIGINT shall behave identically to its receipt of the
  297. <ESC>
  298. character.
  299. .P
  300. Otherwise:
  301. .IP " 1." 4
  302. If executing an
  303. .IR ex
  304. text input mode command, all input lines that have been completely
  305. entered shall be resolved into the edit buffer, and any partially
  306. entered line shall be discarded.
  307. .IP " 2." 4
  308. If there is a currently executing command, it shall be aborted and a
  309. message displayed. Unless otherwise specified by the
  310. .IR ex
  311. or
  312. .IR vi
  313. command descriptions, it is unspecified whether any lines modified by
  314. the executing command appear modified, or as they were before being
  315. modified by the executing command, in the buffer.
  316. .RS 4
  317. .P
  318. If the currently executing command was a motion command, its associated
  319. command shall be discarded.
  320. .RE
  321. .IP " 3." 4
  322. If in open or visual command mode, the terminal shall be alerted.
  323. .IP " 4." 4
  324. The editor shall then return to command mode.
  325. .RE
  326. .IP SIGCONT 10
  327. The screen shall be refreshed if in open or visual mode.
  328. .IP SIGHUP 10
  329. If the edit buffer has been modified since the last complete write,
  330. .IR ex
  331. shall attempt to save the edit buffer so that it can be recovered later
  332. using the
  333. .BR \-r
  334. option or the
  335. .IR ex
  336. .BR recover
  337. command. The editor shall not write the file or return to command or
  338. text input mode, and shall terminate with a non-zero exit status.
  339. .IP SIGTERM 10
  340. Refer to SIGHUP.
  341. .P
  342. The action taken for all other signals is unspecified.
  343. .SH STDOUT
  344. The standard output shall be used only for writing prompts to the user,
  345. for informational messages, and for writing lines from the file.
  346. .SH STDERR
  347. The standard error shall be used only for diagnostic messages.
  348. .SH "OUTPUT FILES"
  349. The output from
  350. .IR ex
  351. shall be text files.
  352. .SH "EXTENDED DESCRIPTION"
  353. Only the
  354. .IR ex
  355. mode of the editor is described in this section. See
  356. .IR "\fIvi\fR\^"
  357. for additional editing capabilities available in
  358. .IR ex .
  359. .P
  360. When an error occurs,
  361. .IR ex
  362. shall write a message. If the terminal supports a standout mode (such
  363. as inverse video), the message shall be written in standout mode. If
  364. the terminal does not support a standout mode, and the edit option
  365. .BR errorbells
  366. is set, an alert action shall precede the error message.
  367. .P
  368. By default,
  369. .IR ex
  370. shall start in command mode, which shall be indicated by a
  371. .BR :
  372. prompt; see the
  373. .BR prompt
  374. command. Text input mode can be entered by the
  375. .BR append ,
  376. .BR insert ,
  377. or
  378. .BR change
  379. commands; it can be exited (and command mode re-entered) by typing a
  380. <period>
  381. (\c
  382. .BR '.' )
  383. alone at the beginning of a line.
  384. .SS "Initialization in ex and vi"
  385. .P
  386. The following symbols are used in this and following sections to
  387. specify locations in the edit buffer:
  388. .IP "\fIalternate\ and\ current\ pathnames\fP" 6
  389. .br
  390. Two pathnames, named
  391. .IR current
  392. and
  393. .IR alternate ,
  394. are maintained by the editor. Any
  395. .IR ex
  396. commands that take filenames as arguments shall set them as follows:
  397. .RS 6
  398. .IP " 1." 4
  399. If a
  400. .IR file
  401. argument is specified to the
  402. .IR ex
  403. .BR edit ,
  404. .BR ex ,
  405. or
  406. .BR recover
  407. commands, or if an
  408. .IR ex
  409. .BR tag
  410. command replaces the contents of the edit buffer.
  411. .RS 4
  412. .IP " a." 4
  413. If the command replaces the contents of the edit buffer, the current
  414. pathname shall be set to the
  415. .IR file
  416. argument or the file indicated by the tag, and the alternate pathname
  417. shall be set to the previous value of the current pathname.
  418. .IP " b." 4
  419. Otherwise, the alternate pathname shall be set to the
  420. .IR file
  421. argument.
  422. .RE
  423. .IP " 2." 4
  424. If a
  425. .IR file
  426. argument is specified to the
  427. .IR ex
  428. .BR next
  429. command:
  430. .RS 4
  431. .IP " a." 4
  432. If the command replaces the contents of the edit buffer, the current
  433. pathname shall be set to the first
  434. .IR file
  435. argument, and the alternate pathname shall be set to the previous
  436. value of the current pathname.
  437. .RE
  438. .IP " 3." 4
  439. If a
  440. .IR file
  441. argument is specified to the
  442. .IR ex
  443. .BR file
  444. command, the current pathname shall be set to the
  445. .IR file
  446. argument, and the alternate pathname shall be set to the previous
  447. value of the current pathname.
  448. .IP " 4." 4
  449. If a
  450. .IR file
  451. argument is specified to the
  452. .IR ex
  453. .BR read
  454. and
  455. .BR write
  456. commands (that is, when reading or writing a file, and not to the
  457. program named by the
  458. .BR shell
  459. edit option), or a
  460. .IR file
  461. argument is specified to the
  462. .IR ex
  463. .BR xit
  464. command:
  465. .RS 4
  466. .IP " a." 4
  467. If the current pathname has no value, the current pathname shall be
  468. set to the
  469. .IR file
  470. argument.
  471. .IP " b." 4
  472. Otherwise, the alternate pathname shall be set to the
  473. .IR file
  474. argument.
  475. .RE
  476. .P
  477. If the alternate pathname is set to the previous value of the current
  478. pathname when the current pathname had no previous value, then the
  479. alternate pathname shall have no value as a result.
  480. .RE
  481. .IP "\fIcurrent\ line\fP" 6
  482. .br
  483. The line of the edit buffer referenced by the cursor. Each command
  484. description specifies the current line after the command has been
  485. executed, as the
  486. .IR "current line value" .
  487. When the edit buffer contains no lines, the current line shall be zero;
  488. see
  489. .IR "Addressing in ex".
  490. .IP "\fIcurrent\ column\fP" 6
  491. .br
  492. The current display line column occupied by the cursor. (The columns
  493. shall be numbered beginning at 1.) Each command description specifies
  494. the current column after the command has been executed, as the
  495. .IR "current column"
  496. value. This column is an
  497. .IR ideal
  498. column that is remembered over the lifetime of the editor. The actual
  499. display line column upon which the cursor rests may be different from
  500. the current column; see the cursor positioning discussion in
  501. .IR "Command Descriptions in vi".
  502. .IP "\fIset\ to\ non-<blank>\fP" 6
  503. .br
  504. A description for a current column value, meaning that the current
  505. column shall be set to the last display line column on which is
  506. displayed any part of the first non-\c
  507. <blank>
  508. of the line. If the line has no non-\c
  509. <blank>
  510. non-\c
  511. <newline>
  512. characters, the current column shall be set to the last display line
  513. column on which is displayed any part of the last non-\c
  514. <newline>
  515. character in the line. If the line is empty, the current column shall
  516. be set to column position 1.
  517. .P
  518. The length of lines in the edit buffer may be limited to
  519. {LINE_MAX}
  520. bytes. In open and visual mode, the length of lines in the edit buffer
  521. may be limited to the number of characters that will fit in the
  522. display. If either limit is exceeded during editing, an error message
  523. shall be written. If either limit is exceeded by a line read in from a
  524. file, an error message shall be written and the edit session may be
  525. terminated.
  526. .P
  527. If the editor stops running due to any reason other than a user
  528. command, and the edit buffer has been modified since the last complete
  529. write, it shall be equivalent to a SIGHUP asynchronous event. If the
  530. system crashes, it shall be equivalent to a SIGHUP asynchronous event.
  531. .P
  532. During initialization (before the first file is copied into the edit
  533. buffer or any user commands from the terminal are processed) the
  534. following shall occur:
  535. .IP " 1." 4
  536. If the environment variable
  537. .IR EXINIT
  538. is set, the editor shall execute the
  539. .IR ex
  540. commands contained in that variable.
  541. .IP " 2." 4
  542. If the
  543. .IR EXINIT
  544. variable is not set, and all of the following are true:
  545. .RS 4
  546. .IP " a." 4
  547. The
  548. .IR HOME
  549. environment variable is not null and not empty.
  550. .IP " b." 4
  551. The file
  552. .BR .exrc
  553. in the directory referred to by the
  554. .IR HOME
  555. environment variable:
  556. .RS 4
  557. .IP " i." 5
  558. Exists
  559. .IP ii. 5
  560. Is owned by the same user ID as the real user ID of the process or the
  561. process has appropriate privileges
  562. .IP iii. 5
  563. Is not writable by anyone other than the owner
  564. .RE
  565. .P
  566. the editor shall execute the
  567. .IR ex
  568. commands contained in that file.
  569. .RE
  570. .IP " 3." 4
  571. If and only if all of the following are true:
  572. .RS 4
  573. .IP " a." 4
  574. The current directory is not referred to by the
  575. .IR HOME
  576. environment variable.
  577. .IP " b." 4
  578. A command in the
  579. .IR EXINIT
  580. environment variable or a command in the
  581. .BR .exrc
  582. file in the directory referred to by the
  583. .IR HOME
  584. environment variable sets the editor option
  585. .BR exrc .
  586. .IP " c." 4
  587. The
  588. .BR .exrc
  589. file in the current directory:
  590. .RS 4
  591. .IP " i." 5
  592. Exists
  593. .IP ii. 5
  594. Is owned by the same user ID as the real user ID of the process, or by
  595. one of a set of implementation-defined user IDs
  596. .IP iii. 5
  597. Is not writable by anyone other than the owner
  598. .RE
  599. .P
  600. the editor shall attempt to execute the
  601. .IR ex
  602. commands contained in that file.
  603. .RE
  604. .P
  605. Lines in any
  606. .BR .exrc
  607. file that are blank lines shall be ignored. If any
  608. .BR .exrc
  609. file exists, but is not read for ownership or permission reasons, it
  610. shall be an error.
  611. .P
  612. After the
  613. .IR EXINIT
  614. variable and any
  615. .BR .exrc
  616. files are processed, the first file specified by the user shall be
  617. edited, as follows:
  618. .IP " 1." 4
  619. If the user specified the
  620. .BR \-t
  621. option, the effect shall be as if the
  622. .IR ex
  623. .BR tag
  624. command was entered with the specified argument, with the exception
  625. that if tag processing does not result in a file to edit, the effect
  626. shall be as described in step 3. below.
  627. .IP " 2." 4
  628. Otherwise, if the user specified any command line
  629. .IR file
  630. arguments, the effect shall be as if the
  631. .IR ex
  632. .BR edit
  633. command was entered with the first of those arguments as its
  634. .IR file
  635. argument.
  636. .IP " 3." 4
  637. Otherwise, the effect shall be as if the
  638. .IR ex
  639. .BR edit
  640. command was entered with a nonexistent filename as its
  641. .IR file
  642. argument. It is unspecified whether this action shall set the current
  643. pathname. In an implementation where this action does not set the
  644. current pathname, any editor command using the current pathname shall
  645. fail until an editor command sets the current pathname.
  646. .P
  647. If the
  648. .BR \-r
  649. option was specified, the first time a file in the initial argument
  650. list or a file specified by the
  651. .BR \-t
  652. option is edited, if recovery information has previously been saved
  653. about it, that information shall be recovered and the editor shall
  654. behave as if the contents of the edit buffer have already been
  655. modified. If there are multiple instances of the file to be recovered,
  656. the one most recently saved shall be recovered, and an informational
  657. message that there are previous versions of the file that can be
  658. recovered shall be written. If no recovery information about a file is
  659. available, an informational message to this effect shall be written,
  660. and the edit shall proceed as usual.
  661. .P
  662. If the
  663. .BR \-c
  664. option was specified, the first time a file that already exists
  665. (including a file that might not exist but for which recovery
  666. information is available, when the
  667. .BR \-r
  668. option is specified) replaces or initializes the contents of the edit
  669. buffer, the current line shall be set to the last line of the edit
  670. buffer, the current column shall be set to non-\c
  671. <blank>,
  672. and the
  673. .IR ex
  674. commands specified with the
  675. .BR \-c
  676. option shall be executed. In this case, the current line and current
  677. column shall not be set as described for the command associated with
  678. the replacement or initialization of the edit buffer contents. However,
  679. if the
  680. .BR \-t
  681. option or a
  682. .BR tag
  683. command is associated with this action, the
  684. .BR \-c
  685. option commands shall be executed and then the movement to the tag
  686. shall be performed.
  687. .P
  688. The current argument list shall initially be set to the filenames
  689. specified by the user on the command line. If no filenames are
  690. specified by the user, the current argument list shall be empty. If the
  691. .BR \-t
  692. option was specified, it is unspecified whether any filename resulting
  693. from tag processing shall be prepended to the current argument list. In
  694. the case where the filename is added as a prefix to the current
  695. argument list, the current argument list reference shall be set to that
  696. filename. In the case where the filename is not added as a prefix to
  697. the current argument list, the current argument list reference shall
  698. logically be located before the first of the filenames specified on
  699. the command line (for example, a subsequent
  700. .IR ex
  701. .BR next
  702. command shall edit the first filename from the command line). If the
  703. .BR \-t
  704. option was not specified, the current argument list reference shall be
  705. to the first of the filenames on the command line.
  706. .SS "Addressing in ex"
  707. .P
  708. Addressing in
  709. .IR ex
  710. relates to the current line and the current column; the address of a
  711. line is its 1-based line number, the address of a column is its 1-based
  712. count from the beginning of the line. Generally, the current line is
  713. the last line affected by a command. The current line number is the
  714. address of the current line. In each command description, the effect of
  715. the command on the current line number and the current column is
  716. described.
  717. .P
  718. Addresses are constructed as follows:
  719. .IP " 1." 4
  720. The character
  721. .BR '.'
  722. (period) shall address the current line.
  723. .IP " 2." 4
  724. The character
  725. .BR '$'
  726. shall address the last line of the edit buffer.
  727. .IP " 3." 4
  728. The positive decimal number
  729. .IR n
  730. shall address the
  731. .IR n th
  732. line of the edit buffer.
  733. .IP " 4." 4
  734. The address
  735. .BR \(dq\(aqx\(dq
  736. refers to the line marked with the mark name character
  737. .BR 'x' ,
  738. which shall be a lowercase letter from the portable character set,
  739. the backquote character, or the single-quote character. It shall be an
  740. error if the line that was marked is not currently present in the edit
  741. buffer or the mark has not been set. Lines can be marked with the
  742. .IR ex
  743. .BR mark
  744. or
  745. .BR k
  746. commands, or the
  747. .IR vi
  748. .BR m
  749. command.
  750. .IP " 5." 4
  751. A regular expression enclosed by
  752. <slash>
  753. characters (\c
  754. .BR '/' )
  755. shall address the first line found by searching forwards from the line
  756. following the current line toward the end of the edit buffer and
  757. stopping at the first line for which the line excluding the terminating
  758. <newline>
  759. matches the regular expression. As stated in
  760. .IR "Regular Expressions in ex",
  761. an address consisting of a null regular expression delimited by
  762. <slash>
  763. characters (\c
  764. .BR \(dq//\(dq )
  765. shall address the next line for which the line excluding the
  766. terminating
  767. <newline>
  768. matches the last regular expression encountered. In addition, the second
  769. <slash>
  770. can be omitted at the end of a command line. If the
  771. .BR wrapscan
  772. edit option is set, the search shall wrap around to the beginning of
  773. the edit buffer and continue up to and including the current line, so
  774. that the entire edit buffer is searched. Within the regular expression,
  775. the sequence
  776. .BR \(dq\e/\(dq
  777. shall represent a literal
  778. <slash>
  779. instead of the regular expression delimiter.
  780. .IP " 6." 4
  781. A regular expression enclosed in
  782. <question-mark>
  783. characters (\c
  784. .BR '?' )
  785. shall address the first line found by searching backwards from the line
  786. preceding the current line toward the beginning of the edit buffer and
  787. stopping at the first line for which the line excluding the terminating
  788. <newline>
  789. matches the regular expression. An address consisting of a null regular
  790. expression delimited by
  791. <question-mark>
  792. characters (\c
  793. .BR \(dq??\(dq )
  794. shall address the previous line for which the line excluding the
  795. terminating
  796. <newline>
  797. matches the last regular expression encountered. In addition, the second
  798. <question-mark>
  799. can be omitted at the end of a command line. If the
  800. .BR wrapscan
  801. edit option is set, the search shall wrap around from the beginning of
  802. the edit buffer to the end of the edit buffer and continue up to and
  803. including the current line, so that the entire edit buffer is
  804. searched. Within the regular expression, the sequence
  805. .BR \(dq\e?\(dq
  806. shall represent a literal
  807. <question-mark>
  808. instead of the RE delimiter.
  809. .IP " 7." 4
  810. A
  811. <plus-sign>
  812. (\c
  813. .BR '\(pl' )
  814. or a
  815. <hyphen-minus>
  816. (\c
  817. .BR '\-' )
  818. followed by a decimal number shall address the current line plus or
  819. minus the number. A
  820. .BR '\(pl'
  821. or
  822. .BR '\-'
  823. not followed by a decimal number shall address the current line plus or
  824. minus 1.
  825. .P
  826. Addresses can be followed by zero or more address offsets, optionally
  827. <blank>-separated.
  828. Address offsets are constructed as follows:
  829. .IP " 1." 4
  830. A
  831. .BR '\(pl'
  832. or
  833. .BR '\-'
  834. immediately followed by a decimal number shall add (subtract) the
  835. indicated number of lines to (from) the address. A
  836. .BR '\(pl'
  837. or
  838. .BR '\-'
  839. not followed by a decimal number shall add (subtract) 1 to (from) the
  840. address.
  841. .IP " 2." 4
  842. A decimal number shall add the indicated number of lines to the
  843. address.
  844. .P
  845. It shall not be an error for an intermediate address value to be less
  846. than zero or greater than the last line in the edit buffer. It shall be
  847. an error for the final address value to be less than zero or greater
  848. than the last line in the edit buffer.
  849. .P
  850. Commands take zero, one, or two addresses; see the descriptions of
  851. .IR 1addr
  852. and
  853. .IR 2addr
  854. in
  855. .IR "Command Descriptions in ex".
  856. If more than the required number of addresses are provided to a command
  857. that requires zero addresses, it shall be an error. Otherwise, if more
  858. than the required number of addresses are provided to a command, the
  859. addresses specified first shall be evaluated and then discarded until
  860. the maximum number of valid addresses remain.
  861. .P
  862. Addresses shall be separated from each other by a
  863. <comma>
  864. (\c
  865. .BR ',' )
  866. or a
  867. <semicolon>
  868. (\c
  869. .BR ';' ).
  870. If no address is specified before or after a
  871. <comma>
  872. or
  873. <semicolon>
  874. separator, it shall be as if the address of the current line was
  875. specified before or after the separator. In the case of a
  876. <semicolon>
  877. separator, the current line (\c
  878. .BR '.' )
  879. shall be set to the first address, and only then will the next address
  880. be calculated. This feature can be used to determine the starting line
  881. for forwards and backwards searches (see rules 5. and 6.).
  882. .P
  883. A
  884. <percent-sign>
  885. (\c
  886. .BR '%' )
  887. shall be equivalent to entering the two addresses
  888. .BR \(dq1,$\(dq .
  889. .P
  890. Any delimiting
  891. <blank>
  892. characters between addresses, address separators, or address offsets
  893. shall be discarded.
  894. .SS "Command Line Parsing in ex"
  895. .P
  896. The following symbol is used in this and following sections to describe
  897. parsing behavior:
  898. .IP "\fIescape\fP" 10
  899. If a character is referred to as ``\c
  900. <backslash>-escaped''
  901. or ``\c
  902. <control>\(hyV-escaped'',
  903. it shall mean that the character acquired or lost a special
  904. meaning by virtue of being preceded, respectively, by a
  905. <backslash>
  906. or
  907. <control>\(hyV
  908. character. Unless otherwise specified, the escaping character shall be
  909. discarded at that time and shall not be further considered for any
  910. purpose.
  911. .P
  912. Command-line parsing shall be done in the following steps. For each
  913. step, characters already evaluated shall be ignored; that is, the
  914. phrase ``leading character'' refers to the next character that has not
  915. yet been evaluated.
  916. .IP " 1." 4
  917. Leading
  918. <colon>
  919. characters shall be skipped.
  920. .IP " 2." 4
  921. Leading
  922. <blank>
  923. characters shall be skipped.
  924. .IP " 3." 4
  925. If the leading character is a double-quote character, the characters up
  926. to and including the next non-\c
  927. <backslash>-escaped
  928. <newline>
  929. shall be discarded, and any subsequent characters shall be parsed as a
  930. separate command.
  931. .IP " 4." 4
  932. Leading characters that can be interpreted as addresses shall be
  933. evaluated; see
  934. .IR "Addressing in ex".
  935. .IP " 5." 4
  936. Leading
  937. <blank>
  938. characters shall be skipped.
  939. .IP " 6." 4
  940. If the next character is a
  941. <vertical-line>
  942. character or a
  943. <newline>:
  944. .RS 4
  945. .IP " a." 4
  946. If the next character is a
  947. <newline>:
  948. .RS 4
  949. .IP " i." 5
  950. If
  951. .IR ex
  952. is in open or visual mode, the current line shall be set to the last
  953. address specified, if any.
  954. .IP ii. 5
  955. Otherwise, if the last command was terminated by a
  956. <vertical-line>
  957. character, no action shall be taken; for example, the command
  958. .BR \(dq||<newline>\(dq
  959. shall execute two implied commands, not three.
  960. .IP iii. 5
  961. Otherwise, step 6.b. shall apply.
  962. .RE
  963. .IP " b." 4
  964. Otherwise, the implied command shall be the
  965. .BR print
  966. command. The last
  967. .BR # ,
  968. .BR p ,
  969. and
  970. .BR l
  971. flags specified to any
  972. .IR ex
  973. command shall be remembered and shall apply to this implied command.
  974. Executing the
  975. .IR ex
  976. .BR number ,
  977. .BR print ,
  978. or
  979. .BR list
  980. command shall set the remembered flags to
  981. .BR # ,
  982. nothing, and
  983. .BR l ,
  984. respectively, plus any other flags specified for that execution of the
  985. .BR number ,
  986. .BR print ,
  987. or
  988. .BR list
  989. command.
  990. .RS 4
  991. .P
  992. If
  993. .IR ex
  994. is not currently performing a
  995. .BR global
  996. or
  997. .BR v
  998. command, and no address or count is specified, the current line shall
  999. be incremented by 1 before the command is executed. If incrementing the
  1000. current line would result in an address past the last line in the edit
  1001. buffer, the command shall fail, and the increment shall not happen.
  1002. .RE
  1003. .IP " c." 4
  1004. The
  1005. <newline>
  1006. or
  1007. <vertical-line>
  1008. character shall be discarded and any subsequent characters shall be
  1009. parsed as a separate command.
  1010. .RE
  1011. .IP " 7." 4
  1012. The command name shall be comprised of the next character (if the
  1013. character is not alphabetic), or the next character and any subsequent
  1014. alphabetic characters (if the character is alphabetic), with the
  1015. following exceptions:
  1016. .RS 4
  1017. .IP " a." 4
  1018. Commands that consist of any prefix of the characters in the command
  1019. name
  1020. .BR delete ,
  1021. followed immediately by any of the characters
  1022. .BR 'l' ,
  1023. .BR 'p' ,
  1024. .BR '\(pl' ,
  1025. .BR '\-' ,
  1026. or
  1027. .BR '#'
  1028. shall be interpreted as a
  1029. .BR delete
  1030. command, followed by a
  1031. <blank>,
  1032. followed by the characters that were not part of the prefix of the
  1033. .BR delete
  1034. command. The maximum number of characters shall be matched to the
  1035. command name
  1036. .BR delete ;
  1037. for example,
  1038. .BR \(dqdel\(dq
  1039. shall not be treated as
  1040. .BR \(dqde\(dq
  1041. followed by the flag
  1042. .BR l .
  1043. .IP " b." 4
  1044. Commands that consist of the character
  1045. .BR 'k' ,
  1046. followed by a character that can be used as the name of a mark, shall
  1047. be equivalent to the mark command followed by a
  1048. <blank>,
  1049. followed by the character that followed the
  1050. .BR 'k' .
  1051. .IP " c." 4
  1052. Commands that consist of the character
  1053. .BR 's' ,
  1054. followed by characters that could be interpreted as valid options to
  1055. the
  1056. .BR s
  1057. command, shall be the equivalent of the
  1058. .BR s
  1059. command, without any pattern or replacement values, followed by a
  1060. <blank>,
  1061. followed by the characters after the
  1062. .BR 's' .
  1063. .RE
  1064. .IP " 8." 4
  1065. The command name shall be matched against the possible command names,
  1066. and a command name that contains a prefix matching the characters
  1067. specified by the user shall be the executed command. In the case of
  1068. commands where the characters specified by the user could be ambiguous,
  1069. the executed command shall be as follows:
  1070. .TS
  1071. center tab(!) box;
  1072. lB | lB || lB | lB || lB | lB.
  1073. a!append!n!next!t!t
  1074. c!change!p!print!u!undo
  1075. ch!change!pr!print!un!undo
  1076. e!edit!r!read!v!v
  1077. m!move!re!read!w!write
  1078. ma!mark!s!s
  1079. .TE
  1080. .RS 4
  1081. .P
  1082. Implementation extensions with names causing similar ambiguities shall
  1083. not be checked for a match until all possible matches for commands
  1084. specified by POSIX.1\(hy2008 have been checked.
  1085. .RE
  1086. .IP " 9." 4
  1087. If the command is a
  1088. .BR !
  1089. command, or if the command is a
  1090. .BR read
  1091. command followed by zero or more
  1092. <blank>
  1093. characters and a
  1094. .BR ! ,
  1095. or if the command is a
  1096. .BR write
  1097. command followed by one or more
  1098. <blank>
  1099. characters and a
  1100. .BR ! ,
  1101. the rest of the command shall include all characters up to a non-\c
  1102. <backslash>-escaped
  1103. <newline>.
  1104. The
  1105. <newline>
  1106. shall be discarded and any subsequent characters shall be parsed as a
  1107. separate
  1108. .IR ex
  1109. command.
  1110. .IP 10. 4
  1111. Otherwise, if the command is an
  1112. .BR edit ,
  1113. .BR ex ,
  1114. or
  1115. .BR next
  1116. command, or a
  1117. .BR visual
  1118. command while in open or visual mode, the next part of the command
  1119. shall be parsed as follows:
  1120. .RS 4
  1121. .IP " a." 4
  1122. Any
  1123. .BR '!'
  1124. character immediately following the command shall be skipped and be
  1125. part of the command.
  1126. .IP " b." 4
  1127. Any leading
  1128. <blank>
  1129. characters shall be skipped and be part of the command.
  1130. .IP " c." 4
  1131. If the next character is a
  1132. .BR '\(pl' ,
  1133. characters up to the first non-\c
  1134. <backslash>-escaped
  1135. <newline>
  1136. or non-\c
  1137. <backslash>-escaped
  1138. <blank>
  1139. shall be skipped and be part of the command.
  1140. .IP " d." 4
  1141. The rest of the command shall be determined by the steps specified in
  1142. paragraph 12.
  1143. .RE
  1144. .IP 11. 4
  1145. Otherwise, if the command is a
  1146. .BR global ,
  1147. .BR open ,
  1148. .BR s ,
  1149. or
  1150. .BR v
  1151. command, the next part of the command shall be parsed as follows:
  1152. .RS 4
  1153. .IP " a." 4
  1154. Any leading
  1155. <blank>
  1156. characters shall be skipped and be part of the command.
  1157. .IP " b." 4
  1158. If the next character is not an alphanumeric, double-quote,
  1159. <newline>,
  1160. <backslash>,
  1161. or
  1162. <vertical-line>
  1163. character:
  1164. .RS 4
  1165. .IP " i." 5
  1166. The next character shall be used as a command delimiter.
  1167. .IP ii. 5
  1168. If the command is a
  1169. .BR global ,
  1170. .BR open ,
  1171. or
  1172. .BR v
  1173. command, characters up to the first non-\c
  1174. <backslash>-escaped
  1175. <newline>,
  1176. or first non-\c
  1177. <backslash>-escaped
  1178. delimiter character, shall be skipped and be part of the command.
  1179. .IP iii. 5
  1180. If the command is an
  1181. .BR s
  1182. command, characters up to the first non-\c
  1183. <backslash>-escaped
  1184. <newline>,
  1185. or second non-\c
  1186. <backslash>-escaped
  1187. delimiter character, shall be skipped and be part of the command.
  1188. .RE
  1189. .IP " c." 4
  1190. If the command is a
  1191. .BR global
  1192. or
  1193. .BR v
  1194. command, characters up to the first non-\c
  1195. <backslash>-escaped
  1196. <newline>
  1197. shall be skipped and be part of the command.
  1198. .IP " d." 4
  1199. Otherwise, the rest of the command shall be determined by the steps
  1200. specified in paragraph 12.
  1201. .RE
  1202. .IP 12. 4
  1203. Otherwise:
  1204. .RS 4
  1205. .IP " a." 4
  1206. If the command was a
  1207. .BR map ,
  1208. .BR unmap ,
  1209. .BR abbreviate ,
  1210. or
  1211. .BR unabbreviate
  1212. command, characters up to the first non-\c
  1213. <control>\(hyV-escaped
  1214. <newline>,
  1215. <vertical-line>,
  1216. or double-quote character shall be skipped and be part of the command.
  1217. .IP " b." 4
  1218. Otherwise, characters up to the first non-\c
  1219. <backslash>-escaped
  1220. <newline>,
  1221. <vertical-line>,
  1222. or double-quote character shall be skipped and be part of the command.
  1223. .IP " c." 4
  1224. If the command was an
  1225. .BR append ,
  1226. .BR change ,
  1227. or
  1228. .BR insert
  1229. command, and the step 12.b. ended at a
  1230. <vertical-line>
  1231. character, any subsequent characters, up to the next non-\c
  1232. <backslash>-escaped
  1233. <newline>
  1234. shall be used as input text to the command.
  1235. .IP " d." 4
  1236. If the command was ended by a double-quote character, all subsequent
  1237. characters, up to the next non-\c
  1238. <backslash>-escaped
  1239. <newline>,
  1240. shall be discarded.
  1241. .IP " e." 4
  1242. The terminating
  1243. <newline>
  1244. or
  1245. <vertical-line>
  1246. character shall be discarded and any subsequent characters shall be
  1247. parsed as a separate
  1248. .IR ex
  1249. command.
  1250. .RE
  1251. .P
  1252. Command arguments shall be parsed as described by the Synopsis and
  1253. Description of each individual
  1254. .IR ex
  1255. command. This parsing shall not be
  1256. <blank>-sensitive,
  1257. except for the
  1258. .BR !
  1259. argument, which must follow the command name without intervening
  1260. <blank>
  1261. characters, and where it would otherwise be ambiguous. For example,
  1262. .IR count
  1263. and
  1264. .IR flag
  1265. arguments need not be
  1266. <blank>-separated
  1267. because
  1268. .BR \(dqd22p\(dq
  1269. is not ambiguous, but
  1270. .IR file
  1271. arguments to the
  1272. .IR ex
  1273. .BR next
  1274. command must be separated by one or more
  1275. <blank>
  1276. characters. Any
  1277. <blank>
  1278. in command arguments for the
  1279. .BR abbreviate ,
  1280. .BR unabbreviate ,
  1281. .BR map ,
  1282. and
  1283. .BR unmap
  1284. commands can be
  1285. <control>\(hyV-escaped,
  1286. in which case the
  1287. <blank>
  1288. shall not be used as an argument delimiter. Any
  1289. <blank>
  1290. in the command argument for any other command can be
  1291. <backslash>-escaped,
  1292. in which case that
  1293. <blank>
  1294. shall not be used as an argument delimiter.
  1295. .P
  1296. Within command arguments for the
  1297. .BR abbreviate ,
  1298. .BR unabbreviate ,
  1299. .BR map ,
  1300. and
  1301. .BR unmap
  1302. commands, any character can be
  1303. <control>\(hyV-escaped.
  1304. All such escaped characters shall be treated literally and shall have
  1305. no special meaning. Within command arguments for all other
  1306. .IR ex
  1307. commands that are not regular expressions or replacement strings, any
  1308. character that would otherwise have a special meaning can be
  1309. <backslash>-escaped.
  1310. Escaped characters shall be treated literally, without special meaning
  1311. as shell expansion characters or
  1312. .BR '!' ,
  1313. .BR '%' ,
  1314. and
  1315. .BR '#'
  1316. expansion characters. See
  1317. .IR "Regular Expressions in ex"
  1318. and
  1319. .IR "Replacement Strings in ex"
  1320. for descriptions of command arguments that are regular expressions or
  1321. replacement strings.
  1322. .P
  1323. Non-\c
  1324. <backslash>-escaped
  1325. .BR '%'
  1326. characters appearing in
  1327. .IR file
  1328. arguments to any
  1329. .IR ex
  1330. command shall be replaced by the current pathname; unescaped
  1331. .BR '#'
  1332. characters shall be replaced by the alternate pathname. It shall be an
  1333. error if
  1334. .BR '%'
  1335. or
  1336. .BR '#'
  1337. characters appear unescaped in an argument and their corresponding
  1338. values are not set.
  1339. .P
  1340. Non-\c
  1341. <backslash>-escaped
  1342. .BR '!'
  1343. characters in the arguments to either the
  1344. .IR ex
  1345. .BR !
  1346. command or the open and visual mode
  1347. .BR !
  1348. command, or in the arguments to the
  1349. .IR ex
  1350. .BR read
  1351. command, where the first non-\c
  1352. <blank>
  1353. after the command name is a
  1354. .BR '!'
  1355. character, or in the arguments to the
  1356. .IR ex
  1357. .BR write
  1358. command where the command name is followed by one or more
  1359. <blank>
  1360. characters and the first non-\c
  1361. <blank>
  1362. after the command name is a
  1363. .BR '!'
  1364. character, shall be replaced with the arguments to the last of those
  1365. three commands as they appeared after all unescaped
  1366. .BR '%' ,
  1367. .BR '#' ,
  1368. and
  1369. .BR '!'
  1370. characters were replaced. It shall be an error if
  1371. .BR '!'
  1372. characters appear unescaped in one of these commands and there has been
  1373. no previous execution of one of these commands.
  1374. .P
  1375. If an error occurs during the parsing or execution of an
  1376. .IR ex
  1377. command:
  1378. .IP " *" 4
  1379. An informational message to this effect shall be written. Execution of
  1380. the
  1381. .IR ex
  1382. command shall stop, and the cursor (for example, the current line and
  1383. column) shall not be further modified.
  1384. .IP " *" 4
  1385. If the
  1386. .IR ex
  1387. command resulted from a map expansion, all characters from that map
  1388. expansion shall be discarded, except as otherwise specified by the
  1389. .BR map
  1390. command.
  1391. .IP " *" 4
  1392. Otherwise, if the
  1393. .IR ex
  1394. command resulted from the processing of an
  1395. .IR EXINIT
  1396. environment variable, a
  1397. .BR .exrc
  1398. file, a
  1399. .BR :source
  1400. command, a
  1401. .BR \-c
  1402. option, or a
  1403. .BR + \c
  1404. .IR command
  1405. specified to an
  1406. .IR ex
  1407. .BR edit ,
  1408. .BR ex ,
  1409. .BR next ,
  1410. or
  1411. .BR visual
  1412. command, no further commands from the source of the commands shall be
  1413. executed.
  1414. .IP " *" 4
  1415. Otherwise, if the
  1416. .IR ex
  1417. command resulted from the execution of a buffer or a
  1418. .BR global
  1419. or
  1420. .BR v
  1421. command, no further commands caused by the execution of the buffer or
  1422. the
  1423. .BR global
  1424. or
  1425. .BR v
  1426. command shall be executed.
  1427. .IP " *" 4
  1428. Otherwise, if the
  1429. .IR ex
  1430. command was not terminated by a
  1431. <newline>,
  1432. all characters up to and including the next non-\c
  1433. <backslash>-escaped
  1434. <newline>
  1435. shall be discarded.
  1436. .SS "Input Editing in ex"
  1437. .P
  1438. The following symbol is used in this and the following sections to
  1439. specify command actions:
  1440. .IP "\fIword\fP" 10
  1441. In the POSIX locale, a word consists of a maximal sequence of letters,
  1442. digits, and underscores, delimited at both ends by characters other
  1443. than letters, digits, or underscores, or by the beginning or end of a
  1444. line or the edit buffer.
  1445. .P
  1446. When accepting input characters from the user, in either
  1447. .IR ex
  1448. command mode or
  1449. .IR ex
  1450. text input mode,
  1451. .IR ex
  1452. shall enable canonical mode input processing, as defined in the System Interfaces volume of POSIX.1\(hy2017.
  1453. .br
  1454. .P
  1455. If in
  1456. .IR ex
  1457. text input mode:
  1458. .IP " 1." 4
  1459. If the
  1460. .BR number
  1461. edit option is set,
  1462. .IR ex
  1463. shall prompt for input using the line number that would be assigned to
  1464. the line if it is entered, in the format specified for the
  1465. .IR ex
  1466. .BR number
  1467. command.
  1468. .IP " 2." 4
  1469. If the
  1470. .BR autoindent
  1471. edit option is set,
  1472. .IR ex
  1473. shall prompt for input using
  1474. .BR autoindent
  1475. characters, as described by the
  1476. .BR autoindent
  1477. edit option.
  1478. .BR autoindent
  1479. characters shall follow the line number, if any.
  1480. .P
  1481. If in
  1482. .IR ex
  1483. command mode:
  1484. .IP " 1." 4
  1485. If the
  1486. .BR prompt
  1487. edit option is set, input shall be prompted for using a single
  1488. .BR ':'
  1489. character; otherwise, there shall be no prompt.
  1490. .P
  1491. The input characters in the following sections shall have the following
  1492. effects on the input line.
  1493. .SS "Scroll"
  1494. .IP "\fISynopsis\fR:" 10
  1495. .sp -1v
  1496. .RS 10
  1497. .sp
  1498. .RS 4
  1499. .nf
  1500. eof
  1501. .fi
  1502. .P
  1503. .RE
  1504. .RE
  1505. .P
  1506. See the description of the
  1507. .IR stty
  1508. .IR eof
  1509. character in
  1510. .IR "\fIstty\fR\^".
  1511. .P
  1512. If in
  1513. .IR ex
  1514. command mode:
  1515. .sp
  1516. .RS
  1517. If the
  1518. .IR eof
  1519. character is the first character entered on the line, the line shall be
  1520. evaluated as if it contained two characters: a
  1521. <control>\(hyD
  1522. and a
  1523. <newline>.
  1524. .P
  1525. Otherwise, the
  1526. .IR eof
  1527. character shall have no special meaning.
  1528. .RE
  1529. .br
  1530. .P
  1531. If in
  1532. .IR ex
  1533. text input mode:
  1534. .sp
  1535. .RS
  1536. If the cursor follows an
  1537. .BR autoindent
  1538. character, the
  1539. .BR autoindent
  1540. characters in the line shall be modified so that a part of the next
  1541. text input character will be displayed on the first column in the line
  1542. after the previous
  1543. .BR shiftwidth
  1544. edit option column boundary, and the user shall be prompted again for
  1545. input for the same line.
  1546. .P
  1547. Otherwise, if the cursor follows a
  1548. .BR '0' ,
  1549. which follows an
  1550. .BR autoindent
  1551. character, and the
  1552. .BR '0'
  1553. was the previous text input character, the
  1554. .BR '0'
  1555. and all
  1556. .BR autoindent
  1557. characters in the line shall be discarded, and the user shall be
  1558. prompted again for input for the same line.
  1559. .P
  1560. Otherwise, if the cursor follows a
  1561. .BR '\(ha' ,
  1562. which follows an
  1563. .BR autoindent
  1564. character, and the
  1565. .BR '\(ha'
  1566. was the previous text input character, the
  1567. .BR '\(ha'
  1568. and all
  1569. .BR autoindent
  1570. characters in the line shall be discarded, and the user shall be
  1571. prompted again for input for the same line. In addition, the
  1572. .BR autoindent
  1573. level for the next input line shall be derived from the same line from
  1574. which the
  1575. .BR autoindent
  1576. level for the current input line was derived.
  1577. .P
  1578. Otherwise, if there are no
  1579. .BR autoindent
  1580. or text input characters in the line, the
  1581. .IR eof
  1582. character shall be discarded.
  1583. .P
  1584. Otherwise, the
  1585. .IR eof
  1586. character shall have no special meaning.
  1587. .RE
  1588. .SS "<newline>"
  1589. .IP "\fISynopsis\fR:" 10
  1590. .sp -1v
  1591. .RS 10
  1592. .sp
  1593. .RS 4
  1594. .nf
  1595. <newline>
  1596. .br
  1597. <control>-J
  1598. .fi
  1599. .P
  1600. .RE
  1601. .RE
  1602. .P
  1603. If in
  1604. .IR ex
  1605. command mode:
  1606. .sp
  1607. .RS
  1608. Cause the command line to be parsed;
  1609. <control>\(hyJ
  1610. shall be mapped to the
  1611. <newline>
  1612. for this purpose.
  1613. .RE
  1614. .br
  1615. .P
  1616. If in
  1617. .IR ex
  1618. text input mode:
  1619. .sp
  1620. .RS
  1621. Terminate the current line. If there are no characters other than
  1622. .BR autoindent
  1623. characters on the line, all characters on the line shall be discarded.
  1624. .P
  1625. Prompt for text input on a new line after the current line. If the
  1626. .BR autoindent
  1627. edit option is set, an appropriate number of
  1628. .BR autoindent
  1629. characters shall be added as a prefix to the line as described by the
  1630. .IR ex
  1631. .BR autoindent
  1632. edit option.
  1633. .RE
  1634. .SS "<backslash>"
  1635. .IP "\fISynopsis\fR:" 10
  1636. .sp -1v
  1637. .RS 10
  1638. .sp
  1639. .RS 4
  1640. .nf
  1641. <backslash>
  1642. .fi
  1643. .P
  1644. .RE
  1645. .RE
  1646. .P
  1647. Allow the entry of a subsequent
  1648. <newline>
  1649. or
  1650. <control>\(hyJ
  1651. as a literal character, removing any special meaning that it may have
  1652. to the editor during text input mode. The
  1653. <backslash>
  1654. character shall be retained and evaluated when the command line is
  1655. parsed, or retained and included when the input text becomes part of
  1656. the edit buffer.
  1657. .SS "<control>\(hyV"
  1658. .IP "\fISynopsis\fR:" 10
  1659. .sp -1v
  1660. .RS 10
  1661. .sp
  1662. .RS 4
  1663. .nf
  1664. <control>-V
  1665. .fi
  1666. .P
  1667. .RE
  1668. .RE
  1669. .P
  1670. Allow the entry of any subsequent character as a literal character,
  1671. removing any special meaning that it may have to the editor during text
  1672. input mode. The
  1673. <control>\(hyV
  1674. character shall be discarded before the command line is parsed or the
  1675. input text becomes part of the edit buffer.
  1676. .P
  1677. If the ``literal next'' functionality is performed by the underlying
  1678. system, it is implementation-defined whether a character other than
  1679. <control>\(hyV
  1680. performs this function.
  1681. .SS "<control>\(hyW"
  1682. .IP "\fISynopsis\fR:" 10
  1683. .sp -1v
  1684. .RS 10
  1685. .sp
  1686. .RS 4
  1687. .nf
  1688. <control>-W
  1689. .fi
  1690. .P
  1691. .RE
  1692. .RE
  1693. .P
  1694. Discard the
  1695. <control>\(hyW,
  1696. and the word previous to it in the input line, including any
  1697. <blank>
  1698. characters following the word and preceding the
  1699. <control>\(hyW.
  1700. If the ``word erase'' functionality is performed by the underlying
  1701. system, it is implementation-defined whether a character other than
  1702. <control>\(hyW
  1703. performs this function.
  1704. .SS "Command Descriptions in ex"
  1705. .P
  1706. The following symbols are used in this section to represent command
  1707. modifiers. Some of these modifiers can be omitted, in which case the
  1708. specified defaults shall be used.
  1709. .IP "\fI1addr\fR" 10
  1710. A single line address, given in any of the forms described in
  1711. .IR "Addressing in ex";
  1712. the default shall be the current line (\c
  1713. .BR '.' ),
  1714. unless otherwise specified.
  1715. .RS 10
  1716. .P
  1717. If the line address is zero, it shall be an error, unless otherwise
  1718. specified in the following command descriptions.
  1719. .P
  1720. If the edit buffer is empty, and the address is specified with a
  1721. command other than
  1722. .BR = ,
  1723. .BR append ,
  1724. .BR insert ,
  1725. .BR open ,
  1726. .BR put ,
  1727. .BR read ,
  1728. or
  1729. .BR visual ,
  1730. or the address is not zero, it shall be an error.
  1731. .RE
  1732. .IP "\fI2addr\fP" 10
  1733. Two addresses specifying an inclusive range of lines. If no addresses
  1734. are specified, the default for
  1735. .IR 2addr
  1736. shall be the current line only (\c
  1737. .BR \(dq.,.\(dq ),
  1738. unless otherwise specified in the following command descriptions. If
  1739. one address is specified,
  1740. .IR 2addr
  1741. shall specify that line only, unless otherwise specified in the
  1742. following command descriptions.
  1743. .RS 10
  1744. .P
  1745. It shall be an error if the first address is greater than the second
  1746. address.
  1747. .P
  1748. If the edit buffer is empty, and the two addresses are specified with a
  1749. command other than the
  1750. .BR ! ,
  1751. .BR write ,
  1752. .BR wq ,
  1753. or
  1754. .BR xit
  1755. commands, or either address is not zero, it shall be an error.
  1756. .RE
  1757. .IP "\fIcount\fP" 10
  1758. A positive decimal number. If
  1759. .IR count
  1760. is specified, it shall be equivalent to specifying an additional
  1761. address to the command, unless otherwise specified by the following
  1762. command descriptions. The additional address shall be equal to the last
  1763. address specified to the command (either explicitly or by default) plus
  1764. .IR count \-1.
  1765. .RS 10
  1766. .P
  1767. If this would result in an address greater than the last line of the
  1768. edit buffer, it shall be corrected to equal the last line of the edit
  1769. buffer.
  1770. .RE
  1771. .IP "\fIflags\fP" 10
  1772. One or more of the characters
  1773. .BR '\(pl' ,
  1774. .BR '\-' ,
  1775. .BR '#' ,
  1776. .BR 'p' ,
  1777. or
  1778. .BR 'l'
  1779. (ell). The flag characters can be
  1780. <blank>-separated,
  1781. and in any order or combination. The characters
  1782. .BR '#' ,
  1783. .BR 'p' ,
  1784. and
  1785. .BR 'l'
  1786. shall cause lines to be written in the format specified by the
  1787. .BR print
  1788. command with the specified
  1789. .IR flags .
  1790. .RS 10
  1791. .P
  1792. The lines to be written are as follows:
  1793. .IP " 1." 4
  1794. All edit buffer lines written during the execution of the
  1795. .IR ex
  1796. .BR & ,
  1797. .BR ~ ,
  1798. .BR list ,
  1799. .BR number ,
  1800. .BR open ,
  1801. .BR print ,
  1802. .BR s ,
  1803. .BR visual ,
  1804. and
  1805. .BR z
  1806. commands shall be written as specified by
  1807. .IR flags .
  1808. .IP " 2." 4
  1809. After the completion of an
  1810. .IR ex
  1811. command with a flag as an argument, the current line shall be written
  1812. as specified by
  1813. .IR flags ,
  1814. unless the current line was the last line written by the command.
  1815. .P
  1816. The characters
  1817. .BR '\(pl'
  1818. and
  1819. .BR '\-'
  1820. cause the value of the current line after the execution of the
  1821. .IR ex
  1822. command to be adjusted by the offset address as described in
  1823. .IR "Addressing in ex".
  1824. This adjustment shall occur before the current line is written as
  1825. described in 2. above.
  1826. .P
  1827. The default for
  1828. .IR flags
  1829. shall be none.
  1830. .RE
  1831. .IP "\fIbuffer\fP" 10
  1832. One of a number of named areas for holding text. The named buffers are
  1833. specified by the alphanumeric characters of the POSIX locale. There
  1834. shall also be one ``unnamed'' buffer. When no buffer is specified for
  1835. editor commands that use a buffer, the unnamed buffer shall be used.
  1836. Commands that store text into buffers shall store the text as it was
  1837. before the command took effect, and shall store text occurring earlier
  1838. in the file before text occurring later in the file, regardless of how
  1839. the text region was specified. Commands that store text into buffers
  1840. shall store the text into the unnamed buffer as well as any specified
  1841. buffer.
  1842. .RS 10
  1843. .P
  1844. In
  1845. .IR ex
  1846. commands, buffer names are specified as the name by itself. In open or
  1847. visual mode commands the name is preceded by a double-quote (\c
  1848. .BR '\&"' )
  1849. character.
  1850. .P
  1851. If the specified buffer name is an uppercase character, and the buffer
  1852. contents are to be modified, the buffer shall be appended to rather
  1853. than being overwritten. If the buffer is not being modified, specifying
  1854. the buffer name in lowercase and uppercase shall have identical
  1855. results.
  1856. .P
  1857. There shall also be buffers named by the numbers 1 through 9. In open
  1858. and visual mode, if a region of text including characters from more
  1859. than a single line is being modified by the
  1860. .IR vi
  1861. .BR c
  1862. or
  1863. .BR d
  1864. commands, the motion character associated with the
  1865. .BR c
  1866. or
  1867. .BR d
  1868. commands specifies that the buffer text shall be in line mode, or the
  1869. commands
  1870. .BR % ,
  1871. .BR ` ,
  1872. .BR / ,
  1873. .BR ? ,
  1874. .BR ( ,
  1875. .BR ) ,
  1876. .BR N ,
  1877. .BR n ,
  1878. .BR { ,
  1879. or
  1880. .BR }
  1881. are used to define a region of text for the
  1882. .BR c
  1883. or
  1884. .BR d
  1885. commands, the contents of buffers 1 through 8 shall be moved into the
  1886. buffer named by the next numerically greater value, the contents of
  1887. buffer 9 shall be discarded, and the region of text shall be copied
  1888. into buffer 1. This shall be in addition to copying the text into a
  1889. user-specified buffer or unnamed buffer, or both. Numeric buffers can
  1890. be specified as a source buffer for open and visual mode commands;
  1891. however, specifying a numeric buffer as the write target of an open or
  1892. visual mode command shall have unspecified results.
  1893. .P
  1894. The text of each buffer shall have the characteristic of being in
  1895. either line or character mode. Appending text to a non-empty buffer
  1896. shall set the mode to match the characteristic of the
  1897. text being appended. Appending text to a buffer shall cause the
  1898. creation of at least one additional line in the buffer. All text stored
  1899. into buffers by
  1900. .IR ex
  1901. commands shall be in line mode. The
  1902. .IR ex
  1903. commands that use buffers as the source of text specify individually
  1904. how buffers of different modes are handled. Each open or visual mode
  1905. command that uses buffers for any purpose specifies individually the
  1906. mode of the text stored into the buffer and how buffers of different
  1907. modes are handled.
  1908. .RE
  1909. .IP "\fIfile\fP" 10
  1910. Command text used to derive a pathname. The default shall be the
  1911. current pathname, as defined previously, in which case, if no current
  1912. pathname has yet been established it shall be an error, except where
  1913. specifically noted in the individual command descriptions that follow.
  1914. If the command text contains any of the characters
  1915. .BR '\(ti' ,
  1916. .BR '{' ,
  1917. .BR '[' ,
  1918. .BR '*' ,
  1919. .BR '?' ,
  1920. .BR '$' ,
  1921. .BR '\&"' ,
  1922. backquote, single-quote, and
  1923. <backslash>,
  1924. it shall be subjected to the process of ``shell expansions'', as
  1925. described below; if more than a single pathname results and the
  1926. command expects only one, it shall be an error.
  1927. .RS 10
  1928. .P
  1929. The process of shell expansions in the editor shall be done as
  1930. follows. The
  1931. .IR ex
  1932. utility shall pass two arguments to the program named by the shell edit
  1933. option; the first shall be
  1934. .BR \-c ,
  1935. and the second shall be the string
  1936. .BR \(dqecho\(dq
  1937. and the command text as a single argument. The standard output and
  1938. standard error of that command shall replace the command text.
  1939. .RE
  1940. .IP "\fB!\fP" 10
  1941. A character that can be appended to the command name to modify its
  1942. operation, as detailed in the individual command descriptions. With the
  1943. exception of the
  1944. .IR ex
  1945. .BR read ,
  1946. .BR write ,
  1947. and
  1948. .BR !
  1949. commands, the
  1950. .BR '!'
  1951. character shall only act as a modifier if there are no
  1952. <blank>
  1953. characters between it and the command name.
  1954. .IP "\fIremembered\ search\ direction\fP" 10
  1955. .br
  1956. The
  1957. .IR vi
  1958. commands
  1959. .BR N
  1960. and
  1961. .BR n
  1962. begin searching in a forwards or backwards direction in the edit buffer
  1963. based on a remembered search direction, which is initially unset, and
  1964. is set by the
  1965. .IR ex
  1966. .BR global ,
  1967. .BR v ,
  1968. .BR s ,
  1969. and
  1970. .BR tag
  1971. commands, and the
  1972. .IR vi
  1973. .BR /
  1974. and
  1975. .BR ?
  1976. commands.
  1977. .SS "Abbreviate"
  1978. .IP "\fISynopsis\fR:" 10
  1979. .sp -1v
  1980. .RS 10
  1981. .sp
  1982. .RS 4
  1983. .nf
  1984. ab\fB[\fIbreviate\fB][\fIlhs rhs\fB]\fR
  1985. .fi
  1986. .P
  1987. .RE
  1988. .RE
  1989. .P
  1990. If
  1991. .IR lhs
  1992. and
  1993. .IR rhs
  1994. are not specified, write the current list of abbreviations and do
  1995. nothing more.
  1996. .P
  1997. Implementations may restrict the set of characters accepted in
  1998. .IR lhs
  1999. or
  2000. .IR rhs ,
  2001. except that printable characters and
  2002. <blank>
  2003. characters shall not be restricted. Additional restrictions shall be
  2004. implementation-defined.
  2005. .P
  2006. In both
  2007. .IR lhs
  2008. and
  2009. .IR rhs ,
  2010. any character may be escaped with a
  2011. <control>\(hyV,
  2012. in which case the character shall not be used to delimit
  2013. .IR lhs
  2014. from
  2015. .IR rhs ,
  2016. and the escaping
  2017. <control>\(hyV
  2018. shall be discarded.
  2019. .P
  2020. In open and visual text input mode, if a non-word or
  2021. <ESC>
  2022. character that is not escaped by a
  2023. <control>\(hyV
  2024. character is entered after a word character, a check shall be made for
  2025. a set of characters matching
  2026. .IR lhs ,
  2027. in the text input entered during this command. If it is found, the
  2028. effect shall be as if
  2029. .IR rhs
  2030. was entered instead of
  2031. .IR lhs .
  2032. .P
  2033. The set of characters that are checked is defined as follows:
  2034. .IP " 1." 4
  2035. If there are no characters inserted before the word and non-word or
  2036. <ESC>
  2037. characters that triggered the check, the set of characters shall
  2038. consist of the word character.
  2039. .IP " 2." 4
  2040. If the character inserted before the word and non-word or
  2041. <ESC>
  2042. characters that triggered the check is a word character, the set of
  2043. characters shall consist of the characters inserted immediately before
  2044. the triggering characters that are word characters, plus the triggering
  2045. word character.
  2046. .IP " 3." 4
  2047. If the character inserted before the word and non-word or
  2048. <ESC>
  2049. characters that triggered the check is not a word character, the set of
  2050. characters shall consist of the characters that were inserted before
  2051. the triggering characters that are neither
  2052. <blank>
  2053. characters nor word characters, plus the triggering word character.
  2054. .P
  2055. It is unspecified whether the
  2056. .IR lhs
  2057. argument entered for the
  2058. .IR ex
  2059. .BR abbreviate
  2060. and
  2061. .BR unabbreviate
  2062. commands is replaced in this fashion. Regardless of whether or not the
  2063. replacement occurs, the effect of the command shall be as if the
  2064. replacement had not occurred.
  2065. .P
  2066. .IR "Current line" :
  2067. Unchanged.
  2068. .P
  2069. .IR "Current column" :
  2070. Unchanged.
  2071. .SS "Append"
  2072. .IP "\fISynopsis\fR:" 10
  2073. .sp -1v
  2074. .RS 10
  2075. .sp
  2076. .RS 4
  2077. .nf
  2078. \fB[\fI1addr\fB] \fRa\fB[\fRppend\fB][\fR!\fB]\fR
  2079. .fi
  2080. .P
  2081. .RE
  2082. .RE
  2083. .P
  2084. Enter
  2085. .IR ex
  2086. text input mode; the input text shall be placed after the specified
  2087. line. If line zero is specified, the text shall be placed at the
  2088. beginning of the edit buffer.
  2089. .P
  2090. This command shall be affected by the
  2091. .BR number
  2092. and
  2093. .BR autoindent
  2094. edit options; following the command name with
  2095. .BR '!'
  2096. shall cause the
  2097. .BR autoindent
  2098. edit option setting to be toggled for the duration of this command
  2099. only.
  2100. .P
  2101. .IR "Current line" :
  2102. Set to the last input line; if no lines were input, set to the
  2103. specified line, or to the first line of the edit buffer if a line of
  2104. zero was specified, or zero if the edit buffer is empty.
  2105. .P
  2106. .IR "Current column" :
  2107. Set to non-\c
  2108. <blank>.
  2109. .SS "Arguments"
  2110. .IP "\fISynopsis\fR:" 10
  2111. .sp -1v
  2112. .RS 10
  2113. .sp
  2114. .RS 4
  2115. .nf
  2116. ar\fB[\fIgs\fB]\fR
  2117. .fi
  2118. .P
  2119. .RE
  2120. .RE
  2121. .P
  2122. Write the current argument list, with the current argument-list entry,
  2123. if any, between
  2124. .BR '['
  2125. and
  2126. .BR ']'
  2127. characters.
  2128. .P
  2129. .IR "Current line" :
  2130. Unchanged.
  2131. .P
  2132. .IR "Current column" :
  2133. Unchanged.
  2134. .SS "Change"
  2135. .IP "\fISynopsis\fR:" 10
  2136. .sp -1v
  2137. .RS 10
  2138. .sp
  2139. .RS 4
  2140. .nf
  2141. \fB[\fI2addr\fB] \fRc\fB[\fRhange\fB][\fR!\fB][\fIcount\fB]\fR
  2142. .fi
  2143. .P
  2144. .RE
  2145. .RE
  2146. .P
  2147. Enter
  2148. .IR ex
  2149. text input mode; the input text shall replace the specified lines. The
  2150. specified lines shall be copied into the unnamed buffer, which shall
  2151. become a line mode buffer.
  2152. .P
  2153. This command shall be affected by the
  2154. .BR number
  2155. and
  2156. .BR autoindent
  2157. edit options; following the command name with
  2158. .BR '!'
  2159. shall cause the
  2160. .BR autoindent
  2161. edit option setting to be toggled for the duration of this command
  2162. only.
  2163. .P
  2164. .IR "Current line" :
  2165. Set to the last input line; if no lines were input, set to the line
  2166. before the first address, or to the first line of the edit buffer if
  2167. there are no lines preceding the first address, or to zero if the edit
  2168. buffer is empty.
  2169. .P
  2170. .IR "Current column" :
  2171. Set to non-\c
  2172. <blank>.
  2173. .SS "Change Directory"
  2174. .IP "\fISynopsis\fR:" 10
  2175. .sp -1v
  2176. .RS 10
  2177. .sp
  2178. .RS 4
  2179. .nf
  2180. chd\fB[\fRir\fB][\fR!\fB][\fIdirectory\fB]\fR
  2181. cd\fB[\fR!\fB][\fIdirectory\fB]\fR
  2182. .fi
  2183. .P
  2184. .RE
  2185. .RE
  2186. .P
  2187. Change the current working directory to
  2188. .IR directory .
  2189. .P
  2190. If no
  2191. .IR directory
  2192. argument is specified, and the
  2193. .IR HOME
  2194. environment variable is set to a non-null and non-empty value,
  2195. .IR directory
  2196. shall default to the value named in the
  2197. .IR HOME
  2198. environment variable. If the
  2199. .IR HOME
  2200. environment variable is empty or is undefined, the default value of
  2201. .IR directory
  2202. is implementation-defined.
  2203. .P
  2204. If no
  2205. .BR '!'
  2206. is appended to the command name, and the edit buffer has been modified
  2207. since the last complete write, and the current pathname does not begin
  2208. with a
  2209. .BR '/' ,
  2210. it shall be an error.
  2211. .P
  2212. .IR "Current line" :
  2213. Unchanged.
  2214. .P
  2215. .IR "Current column" :
  2216. Unchanged.
  2217. .SS "Copy"
  2218. .IP "\fISynopsis\fR:" 10
  2219. .sp -1v
  2220. .RS 10
  2221. .sp
  2222. .RS 4
  2223. .nf
  2224. \fB[\fI2addr\fB] \fRco\fB[\fRpy\fB] \fI1addr \fB[\fIflags\fB]
  2225. [\fI2addr\fB] \fRt \fI1addr \fB[\fIflags\fB]\fR
  2226. .fi
  2227. .P
  2228. .RE
  2229. .RE
  2230. .P
  2231. Copy the specified lines after the specified destination line; line
  2232. zero specifies that the lines shall be placed at the beginning of the
  2233. edit buffer.
  2234. .P
  2235. .IR "Current line" :
  2236. Set to the last line copied.
  2237. .P
  2238. .IR "Current column" :
  2239. Set to non-\c
  2240. <blank>.
  2241. .SS "Delete"
  2242. .IP "\fISynopsis\fR:" 10
  2243. .sp -1v
  2244. .RS 10
  2245. .sp
  2246. .RS 4
  2247. .nf
  2248. \fB[\fI2addr\fB] \fRd\fB[\fRelete\fB][\fIbuffer\fB][\fIcount\fB][\fIflags\fB]\fR
  2249. .fi
  2250. .P
  2251. .RE
  2252. .RE
  2253. .P
  2254. Delete the specified lines into a buffer (defaulting to the unnamed
  2255. buffer), which shall become a line-mode buffer.
  2256. .P
  2257. Flags can immediately follow the command name; see
  2258. .IR "Command Line Parsing in ex".
  2259. .P
  2260. .IR "Current line" :
  2261. Set to the line following the deleted lines, or to the last line in the
  2262. edit buffer if that line is past the end of the edit buffer, or to zero
  2263. if the edit buffer is empty.
  2264. .P
  2265. .IR "Current column" :
  2266. Set to non-\c
  2267. <blank>.
  2268. .SS "Edit"
  2269. .IP "\fISynopsis\fR:" 10
  2270. .sp -1v
  2271. .RS 10
  2272. .sp
  2273. .RS 4
  2274. .nf
  2275. e\fB[\fRdit\fB][\fR!\fB][\fR+\fIcommand\fB][\fIfile\fB]\fR
  2276. ex\fB[\fR!\fB][\fR+\fIcommand\fB][\fIfile\fB]\fR
  2277. .fi
  2278. .P
  2279. .RE
  2280. .RE
  2281. .P
  2282. If no
  2283. .BR '!'
  2284. is appended to the command name, and the edit buffer has been modified
  2285. since the last complete write, it shall be an error.
  2286. .P
  2287. If
  2288. .IR file
  2289. is specified, replace the current contents of the edit buffer with the
  2290. current contents of
  2291. .IR file ,
  2292. and set the current pathname to
  2293. .IR file .
  2294. If
  2295. .IR file
  2296. is not specified, replace the current contents of the edit buffer with
  2297. the current contents of the file named by the current pathname. If for
  2298. any reason the current contents of the file cannot be accessed, the
  2299. edit buffer shall be empty.
  2300. .P
  2301. The
  2302. .BR + \c
  2303. .IR command
  2304. option shall be
  2305. <blank>-delimited;
  2306. <blank>
  2307. characters within the
  2308. .BR + \c
  2309. .IR command
  2310. can be escaped by preceding them with a
  2311. <backslash>
  2312. character. The
  2313. .BR + \c
  2314. .IR command
  2315. shall be interpreted as an
  2316. .IR ex
  2317. command immediately after the contents of the edit buffer have been
  2318. replaced and the current line and column have been set.
  2319. .P
  2320. If the edit buffer is empty:
  2321. .P
  2322. .IR "Current line" :
  2323. Set to 0.
  2324. .P
  2325. .IR "Current column" :
  2326. Set to 1.
  2327. .P
  2328. Otherwise, if executed while in
  2329. .IR ex
  2330. command mode or if the
  2331. .BR + \c
  2332. .IR command
  2333. argument is specified:
  2334. .P
  2335. .IR "Current line" :
  2336. Set to the last line of the edit buffer.
  2337. .P
  2338. .IR "Current column" :
  2339. Set to non-\c
  2340. <blank>.
  2341. .P
  2342. Otherwise, if
  2343. .IR file
  2344. is omitted or results in the current pathname:
  2345. .P
  2346. .IR "Current line" :
  2347. Set to the first line of the edit buffer.
  2348. .P
  2349. .IR "Current column" :
  2350. Set to non-\c
  2351. <blank>.
  2352. .P
  2353. Otherwise, if
  2354. .IR file
  2355. is the same as the last file edited, the line and column shall be set
  2356. as follows; if the file was previously edited, the line and column may
  2357. be set as follows:
  2358. .P
  2359. .IR "Current line" :
  2360. Set to the last value held when that file was last edited. If this
  2361. value is not a valid line in the new edit buffer, set to the first line
  2362. of the edit buffer.
  2363. .P
  2364. .IR "Current column" :
  2365. If the current line was set to the last value held when the file was
  2366. last edited, set to the last value held when the file was last edited.
  2367. Otherwise, or if the last value is not a valid column in the new edit
  2368. buffer, set to non-\c
  2369. <blank>.
  2370. .br
  2371. .P
  2372. Otherwise:
  2373. .P
  2374. .IR "Current line" :
  2375. Set to the first line of the edit buffer.
  2376. .P
  2377. .IR "Current column" :
  2378. Set to non-\c
  2379. <blank>.
  2380. .SS "File"
  2381. .IP "\fISynopsis\fR:" 10
  2382. .sp -1v
  2383. .RS 10
  2384. .sp
  2385. .RS 4
  2386. .nf
  2387. f\fB[\fRile\fB][\fIfile\fB]\fR
  2388. .fi
  2389. .P
  2390. .RE
  2391. .RE
  2392. .P
  2393. If a
  2394. .IR file
  2395. argument is specified, the alternate pathname shall be set to the
  2396. current pathname, and the current pathname shall be set to
  2397. .IR file .
  2398. .P
  2399. Write an informational message. If the file has a current pathname, it
  2400. shall be included in this message; otherwise, the message shall
  2401. indicate that there is no current pathname. If the edit buffer
  2402. contains lines, the current line number and the number of lines in the
  2403. edit buffer shall be included in this message; otherwise, the message
  2404. shall indicate that the edit buffer is empty. If the edit buffer has
  2405. been modified since the last complete write, this fact shall be
  2406. included in this message. If the
  2407. .BR readonly
  2408. edit option is set, this fact shall be included in this message. The
  2409. message may contain other unspecified information.
  2410. .P
  2411. .IR "Current line" :
  2412. Unchanged.
  2413. .P
  2414. .IR "Current column" :
  2415. Unchanged.
  2416. .SS "Global"
  2417. .IP "\fISynopsis\fR:" 10
  2418. .sp -1v
  2419. .RS 10
  2420. .sp
  2421. .RS 4
  2422. .nf
  2423. \fB[\fI2addr\fB] \fRg\fB[\fRlobal\fB] \fR/\fIpattern\fR/ \fB[\fIcommands\fB]
  2424. [\fI2addr\fB] \fRv /\fIpattern\fR/ \fB[\fIcommands\fB]\fR
  2425. .fi
  2426. .P
  2427. .RE
  2428. .RE
  2429. .P
  2430. The optional
  2431. .BR '!'
  2432. character after the
  2433. .BR global
  2434. command shall be the same as executing the
  2435. .BR v
  2436. command.
  2437. .P
  2438. If
  2439. .IR pattern
  2440. is empty (for example,
  2441. .BR \(dq//\(dq )
  2442. or not specified, the last regular expression used in the editor
  2443. command shall be used as the
  2444. .IR pattern .
  2445. The
  2446. .IR pattern
  2447. can be delimited by
  2448. <slash>
  2449. characters (shown in the Synopsis), as well as any non-alphanumeric
  2450. or non-\c
  2451. <blank>
  2452. other than
  2453. <backslash>,
  2454. <vertical-line>,
  2455. <newline>,
  2456. or double-quote.
  2457. .P
  2458. If no lines are specified, the lines shall default to the entire file.
  2459. .P
  2460. The
  2461. .BR global
  2462. and
  2463. .BR v
  2464. commands are logically two-pass operations. First, mark the lines
  2465. within the specified lines for which the line excluding the terminating
  2466. <newline>
  2467. matches (\c
  2468. .BR global )
  2469. or does not match (\c
  2470. .BR v
  2471. or
  2472. .BR global! )
  2473. the specified pattern. Second, execute the
  2474. .IR ex
  2475. commands given by
  2476. .IR commands ,
  2477. with the current line (\c
  2478. .BR '.' )
  2479. set to each marked line. If an error occurs during this process, or the
  2480. contents of the edit buffer are replaced (for example, by the
  2481. .IR ex
  2482. .BR :edit
  2483. command) an error message shall be written and no more commands
  2484. resulting from the execution of this command shall be processed.
  2485. .P
  2486. Multiple
  2487. .IR ex
  2488. commands can be specified by entering multiple commands on a single
  2489. line using a
  2490. <vertical-line>
  2491. to delimit them, or one per line, by escaping each
  2492. <newline>
  2493. with a
  2494. <backslash>.
  2495. .P
  2496. If no commands are specified:
  2497. .IP " 1." 4
  2498. If in
  2499. .IR ex
  2500. command mode, it shall be as if the
  2501. .BR print
  2502. command were specified.
  2503. .IP " 2." 4
  2504. Otherwise, no command shall be executed.
  2505. .P
  2506. For the
  2507. .BR append ,
  2508. .BR change ,
  2509. and
  2510. .BR insert
  2511. commands, the input text shall be included as part of the command, and
  2512. the terminating
  2513. <period>
  2514. can be omitted if the command ends the list of commands. The
  2515. .BR open
  2516. and
  2517. .BR visual
  2518. commands can be specified as one of the commands, in which case each
  2519. marked line shall cause the editor to enter open or visual mode. If
  2520. open or visual mode is exited using the
  2521. .IR vi
  2522. .BR Q
  2523. command, the current line shall be set to the next marked line, and
  2524. open or visual mode reentered, until the list of marked lines is
  2525. exhausted.
  2526. .P
  2527. The
  2528. .BR global ,
  2529. .BR v ,
  2530. and
  2531. .BR undo
  2532. commands cannot be used in
  2533. .IR commands .
  2534. Marked lines may be deleted by commands executed for lines occurring
  2535. earlier in the file than the marked lines. In this case, no commands
  2536. shall be executed for the deleted lines.
  2537. .P
  2538. If the remembered search direction is not set, the
  2539. .BR global
  2540. and
  2541. .BR v
  2542. commands shall set it to forward.
  2543. .P
  2544. The
  2545. .BR autoprint
  2546. and
  2547. .BR autoindent
  2548. edit options shall be inhibited for the duration of the
  2549. .BR g
  2550. or
  2551. .BR v
  2552. command.
  2553. .P
  2554. .IR "Current line" :
  2555. If no commands executed, set to the last marked line. Otherwise, as
  2556. specified for the executed
  2557. .IR ex
  2558. commands.
  2559. .P
  2560. .IR "Current column" :
  2561. If no commands are executed, set to non-\c
  2562. <blank>;
  2563. otherwise, as specified for the individual
  2564. .IR ex
  2565. commands.
  2566. .SS "Insert"
  2567. .IP "\fISynopsis\fR:" 10
  2568. .sp -1v
  2569. .RS 10
  2570. .sp
  2571. .RS 4
  2572. .nf
  2573. \fB[\fI1addr\fB] \fRi\fB[\fRnsert\fB][\fR!\fB]\fR
  2574. .fi
  2575. .P
  2576. .RE
  2577. .RE
  2578. .P
  2579. Enter
  2580. .IR ex
  2581. text input mode; the input text shall be placed before the specified
  2582. line. If the line is zero or 1, the text shall be placed at the
  2583. beginning of the edit buffer.
  2584. .P
  2585. This command shall be affected by the
  2586. .BR number
  2587. and
  2588. .BR autoindent
  2589. edit options; following the command name with
  2590. .BR '!'
  2591. shall cause the
  2592. .BR autoindent
  2593. edit option setting to be toggled for the duration of this command
  2594. only.
  2595. .P
  2596. .IR "Current line" :
  2597. Set to the last input line; if no lines were input, set to the line
  2598. before the specified line, or to the first line of the edit buffer if
  2599. there are no lines preceding the specified line, or zero if the edit
  2600. buffer is empty.
  2601. .P
  2602. .IR "Current column" :
  2603. Set to non-\c
  2604. <blank>.
  2605. .SS "Join"
  2606. .IP "\fISynopsis\fR:" 10
  2607. .sp -1v
  2608. .RS 10
  2609. .sp
  2610. .RS 4
  2611. .nf
  2612. \fB[\fI2addr\fB] \fRj\fB[\fRoin\fB][\fR!\fB][\fIcount\fB][\fIflags\fB]\fR
  2613. .fi
  2614. .P
  2615. .RE
  2616. .RE
  2617. .P
  2618. If
  2619. .IR count
  2620. is specified:
  2621. .sp
  2622. .RS
  2623. If no address was specified, the
  2624. .BR join
  2625. command shall behave as if
  2626. .IR 2addr
  2627. were the current line and the current line plus
  2628. .IR count
  2629. (.\|,\|. +
  2630. .IR count ).
  2631. .P
  2632. If one address was specified, the
  2633. .BR join
  2634. command shall behave as if
  2635. .IR 2addr
  2636. were the specified address and the specified address plus
  2637. .IR count
  2638. (\c
  2639. .IR addr ,\c
  2640. .IR addr
  2641. +
  2642. .IR count ).
  2643. .P
  2644. If two addresses were specified, the
  2645. .BR join
  2646. command shall behave as if an additional address, equal to the last
  2647. address plus
  2648. .IR count
  2649. \-1 (\c
  2650. .IR addr1 ,\c
  2651. .IR addr2 ,\c
  2652. .IR addr2
  2653. +
  2654. .IR count
  2655. \-1), was specified.
  2656. .P
  2657. If this would result in a second address greater than the last line of
  2658. the edit buffer, it shall be corrected to be equal to the last line of
  2659. the edit buffer.
  2660. .RE
  2661. .P
  2662. If no
  2663. .IR count
  2664. is specified:
  2665. .sp
  2666. .RS
  2667. If no address was specified, the
  2668. .BR join
  2669. command shall behave as if
  2670. .IR 2addr
  2671. were the current line and the next line (.\|,\|. +1).
  2672. .P
  2673. If one address was specified, the
  2674. .BR join
  2675. command shall behave as if
  2676. .IR 2addr
  2677. were the specified address and the next line (\c
  2678. .IR addr ,\c
  2679. .IR addr
  2680. +1).
  2681. .RE
  2682. .P
  2683. Join the text from the specified lines together into a single line,
  2684. which shall replace the specified lines.
  2685. .P
  2686. If a
  2687. .BR '!'
  2688. character is appended to the command name, the
  2689. .BR join
  2690. shall be without modification of any line, independent of the current
  2691. locale.
  2692. .P
  2693. Otherwise, in the POSIX locale, set the current line to the first of
  2694. the specified lines, and then, for each subsequent line, proceed as
  2695. follows:
  2696. .IP " 1." 4
  2697. Discard leading
  2698. <space>
  2699. characters from the line to be joined.
  2700. .IP " 2." 4
  2701. If the line to be joined is now empty, delete it, and skip steps 3
  2702. through 5.
  2703. .IP " 3." 4
  2704. If the current line ends in a
  2705. <blank>,
  2706. or the first character of the line to be joined is a
  2707. .BR ')'
  2708. character, join the lines without further modification.
  2709. .IP " 4." 4
  2710. If the last character of the current line is a
  2711. .BR '.' ,
  2712. join the lines with two
  2713. <space>
  2714. characters between them.
  2715. .IP " 5." 4
  2716. Otherwise, join the lines with a single
  2717. <space>
  2718. between them.
  2719. .P
  2720. .IR "Current line" :
  2721. Set to the first line specified.
  2722. .P
  2723. .IR "Current column" :
  2724. Set to non-\c
  2725. <blank>.
  2726. .SS "List"
  2727. .IP "\fISynopsis\fR:" 10
  2728. .sp -1v
  2729. .RS 10
  2730. .sp
  2731. .RS 4
  2732. .nf
  2733. \fB[\fI2addr\fB] \fRl\fB[\fRist\fB][\fIcount\fB][\fIflags\fB]\fR
  2734. .fi
  2735. .P
  2736. .RE
  2737. .RE
  2738. .P
  2739. This command shall be equivalent to the
  2740. .IR ex
  2741. command:
  2742. .sp
  2743. .RS 4
  2744. .nf
  2745. \fB[\fI2addr\fB] \fRp\fB[\fRrint\fB][\fIcount\fB] \fRl\fB[\fIflags\fB]\fR
  2746. .fi
  2747. .P
  2748. .RE
  2749. .P
  2750. See
  2751. .IR "Print".
  2752. .SS "Map"
  2753. .IP "\fISynopsis\fR:" 10
  2754. .sp -1v
  2755. .RS 10
  2756. .sp
  2757. .RS 4
  2758. .nf
  2759. map\fB[\fR!\fB][\fIlhs rhs\fB]\fR
  2760. .fi
  2761. .P
  2762. .RE
  2763. .RE
  2764. .P
  2765. If
  2766. .IR lhs
  2767. and
  2768. .IR rhs
  2769. are not specified:
  2770. .IP " 1." 4
  2771. If
  2772. .BR '!'
  2773. is specified, write the current list of text input mode maps.
  2774. .IP " 2." 4
  2775. Otherwise, write the current list of command mode maps.
  2776. .IP " 3." 4
  2777. Do nothing more.
  2778. .P
  2779. Implementations may restrict the set of characters accepted in
  2780. .IR lhs
  2781. or
  2782. .IR rhs ,
  2783. except that printable characters and
  2784. <blank>
  2785. characters shall not be restricted. Additional restrictions shall be
  2786. implementation-defined. In both
  2787. .IR lhs
  2788. and
  2789. .IR rhs ,
  2790. any character can be escaped with a
  2791. <control>\(hyV,
  2792. in which case the character shall not be used to delimit
  2793. .IR lhs
  2794. from
  2795. .IR rhs ,
  2796. and the escaping
  2797. <control>\(hyV
  2798. shall be discarded.
  2799. .P
  2800. If the character
  2801. .BR '!'
  2802. is appended to the
  2803. .BR map
  2804. command name, the mapping shall be effective during open or visual text
  2805. input mode rather than
  2806. .BR open
  2807. or
  2808. .BR visual
  2809. command mode. This allows
  2810. .IR lhs
  2811. to have two different
  2812. .BR map
  2813. definitions at the same time: one for command mode and one for text
  2814. input mode.
  2815. .br
  2816. .P
  2817. For command mode mappings:
  2818. .sp
  2819. .RS
  2820. When the
  2821. .IR lhs
  2822. is entered as any part of a
  2823. .IR vi
  2824. command in open or visual mode (but not as part of the arguments to the
  2825. command), the action shall be as if the corresponding
  2826. .IR rhs
  2827. had been entered.
  2828. .P
  2829. If any character in the command, other than the first, is escaped using
  2830. a
  2831. <control>\(hyV
  2832. character, that character shall not be part of a match to an
  2833. .IR lhs .
  2834. .P
  2835. It is unspecified whether implementations shall support
  2836. .BR map
  2837. commands where the
  2838. .IR lhs
  2839. is more than a single character in length, where the first character of
  2840. the
  2841. .IR lhs
  2842. is printable.
  2843. .RE
  2844. .P
  2845. .sp
  2846. .RS
  2847. If
  2848. .IR lhs
  2849. contains more than one character and the first character is
  2850. .BR '#' ,
  2851. followed by a sequence of digits corresponding to a numbered function
  2852. key, then when this function key is typed it shall be mapped to
  2853. .IR rhs .
  2854. Characters other than digits following a
  2855. .BR '#'
  2856. character also represent the function key named by the characters in
  2857. the
  2858. .IR lhs
  2859. following the
  2860. .BR '#'
  2861. and may be mapped to
  2862. .IR rhs .
  2863. It is unspecified how function keys are named or what function keys are
  2864. supported.
  2865. .RE
  2866. .P
  2867. For text input mode mappings:
  2868. .sp
  2869. .RS
  2870. When the
  2871. .IR lhs
  2872. is entered as any part of text entered in open or visual text input
  2873. modes, the action shall be as if the corresponding
  2874. .IR rhs
  2875. had been entered.
  2876. .P
  2877. If any character in the input text is escaped using a
  2878. <control>\(hyV
  2879. character, that character shall not be part of a match to an
  2880. .IR lhs .
  2881. .P
  2882. It is unspecified whether the
  2883. .IR lhs
  2884. text entered for subsequent
  2885. .BR map
  2886. or
  2887. .BR unmap
  2888. commands is replaced with the
  2889. .IR rhs
  2890. text for the purposes of the screen display; regardless of whether or
  2891. not the display appears as if the corresponding
  2892. .IR rhs
  2893. text was entered, the effect of the command shall be as if the
  2894. .IR lhs
  2895. text was entered.
  2896. .RE
  2897. .P
  2898. If only part of the
  2899. .IR lhs
  2900. is entered, it is unspecified how long the editor will wait for
  2901. additional, possibly matching characters before treating the already
  2902. entered characters as not matching the
  2903. .IR lhs .
  2904. .P
  2905. The
  2906. .IR rhs
  2907. characters shall themselves be subject to remapping, unless otherwise
  2908. specified by the
  2909. .BR remap
  2910. edit option, except that if the characters in
  2911. .IR lhs
  2912. occur as prefix characters in
  2913. .IR rhs ,
  2914. those characters shall not be remapped.
  2915. .P
  2916. On block-mode terminals, the mapping need not occur immediately (for
  2917. example, it may occur after the terminal transmits a group of
  2918. characters to the system), but it shall achieve the same results as if
  2919. it occurred immediately.
  2920. .P
  2921. .IR "Current line" :
  2922. Unchanged.
  2923. .P
  2924. .IR "Current column" :
  2925. Unchanged.
  2926. .SS "Mark"
  2927. .IP "\fISynopsis\fR:" 10
  2928. .sp -1v
  2929. .RS 10
  2930. .sp
  2931. .RS 4
  2932. .nf
  2933. \fB[\fI1addr\fB] \fRma\fB[\fRrk\fB] \fIcharacter
  2934. \fB[\fI1addr\fB] \fRk \fIcharacter\fR
  2935. .fi
  2936. .P
  2937. .RE
  2938. .RE
  2939. .P
  2940. Implementations shall support
  2941. .IR character
  2942. values of a single lowercase letter of the POSIX locale and the
  2943. backquote and single-quote characters; support of other characters is
  2944. implementation-defined.
  2945. .P
  2946. If executing the
  2947. .IR vi
  2948. .BR m
  2949. command, set the specified mark to the current line and 1-based
  2950. numbered character referenced by the current column, if any; otherwise,
  2951. column position 1.
  2952. .P
  2953. Otherwise, set the specified mark to the specified line and 1-based
  2954. numbered first non-\c
  2955. <blank>
  2956. non-\c
  2957. <newline>
  2958. in the line, if any; otherwise, the last non-\c
  2959. <newline>
  2960. in the line, if any; otherwise, column position 1.
  2961. .P
  2962. The mark shall remain associated with the line until the mark is reset
  2963. or the line is deleted. If a deleted line is restored by a subsequent
  2964. .BR undo
  2965. command, any marks previously associated with the line, which have not
  2966. been reset, shall be restored as well. Any use of a mark not associated
  2967. with a current line in the edit buffer shall be an error.
  2968. .P
  2969. The marks
  2970. .BR `
  2971. and
  2972. .BR \(aq
  2973. shall be set as described previously, immediately before the following
  2974. events occur in the editor:
  2975. .IP " 1." 4
  2976. The use of
  2977. .BR '$'
  2978. as an
  2979. .IR ex
  2980. address
  2981. .IP " 2." 4
  2982. The use of a positive decimal number as an
  2983. .IR ex
  2984. address
  2985. .IP " 3." 4
  2986. The use of a search command as an
  2987. .IR ex
  2988. address
  2989. .IP " 4." 4
  2990. The use of a mark reference as an
  2991. .IR ex
  2992. address
  2993. .IP " 5." 4
  2994. The use of the following open and visual mode commands:
  2995. <control>\(hy],
  2996. .BR % ,
  2997. .BR ( ,
  2998. .BR ) ,
  2999. .BR [ ,
  3000. .BR ] ,
  3001. .BR { ,
  3002. .BR }
  3003. .IP " 6." 4
  3004. The use of the following open and visual mode commands:
  3005. .BR \(aq ,
  3006. .BR G ,
  3007. .BR H ,
  3008. .BR L ,
  3009. .BR M ,
  3010. .BR z
  3011. if the current line will change as a result of the command
  3012. .IP " 7." 4
  3013. The use of the open and visual mode commands:
  3014. .BR / ,
  3015. .BR ? ,
  3016. .BR N ,
  3017. .BR ` ,
  3018. .BR n
  3019. if the current line or column will change as a result of the command
  3020. .IP " 8." 4
  3021. The use of the
  3022. .IR ex
  3023. mode commands:
  3024. .BR z ,
  3025. .BR undo ,
  3026. .BR global ,
  3027. .BR v
  3028. .P
  3029. For rules 1., 2., 3., and 4., the
  3030. .BR `
  3031. and
  3032. .BR \(aq
  3033. marks shall not be set if the
  3034. .IR ex
  3035. command is parsed as specified by rule 6.a. in
  3036. .IR "Command Line Parsing in ex".
  3037. .P
  3038. For rules 5., 6., and 7., the
  3039. .BR `
  3040. and
  3041. .BR \(aq
  3042. marks shall not be set if the commands are used as motion commands in
  3043. open and visual mode.
  3044. .P
  3045. For rules 1., 2., 3., 4., 5., 6., 7., and 8., the
  3046. .BR `
  3047. and
  3048. .BR \(aq
  3049. marks shall not be set if the command fails.
  3050. .P
  3051. The
  3052. .BR `
  3053. and
  3054. .BR \(aq
  3055. marks shall be set as described previously, each time the contents of
  3056. the edit buffer are replaced (including the editing of the initial
  3057. buffer), if in open or visual mode, or if in
  3058. .BR ex
  3059. mode and the edit buffer is not empty, before any commands or movements
  3060. (including commands or movements specified by the
  3061. .BR \-c
  3062. or
  3063. .BR \-t
  3064. options or the
  3065. .BR + \c
  3066. .IR command
  3067. argument) are executed on the edit buffer. If in open or visual mode,
  3068. the marks shall be set as if executing the
  3069. .IR vi
  3070. .BR m
  3071. command; otherwise, as if executing the
  3072. .IR ex
  3073. .BR mark
  3074. command.
  3075. .P
  3076. When changing from
  3077. .BR ex
  3078. mode to open or visual mode, if the
  3079. .BR `
  3080. and
  3081. .BR \(aq
  3082. marks are not already set, the
  3083. .BR `
  3084. and
  3085. .BR \(aq
  3086. marks shall be set as described previously.
  3087. .P
  3088. .IR "Current line" :
  3089. Unchanged.
  3090. .P
  3091. .IR "Current column" :
  3092. Unchanged.
  3093. .SS "Move"
  3094. .IP "\fISynopsis\fR:" 10
  3095. .sp -1v
  3096. .RS 10
  3097. .sp
  3098. .RS 4
  3099. .nf
  3100. \fB[\fI2addr\fB] \fRm\fB[\fRove\fB] \fI1addr\fR \fB[\fIflags\fB]\fR
  3101. .fi
  3102. .P
  3103. .RE
  3104. .RE
  3105. .P
  3106. Move the specified lines after the specified destination line. A
  3107. destination of line zero specifies that the lines shall be placed at
  3108. the beginning of the edit buffer. It shall be an error if the
  3109. destination line is within the range of lines to be moved.
  3110. .P
  3111. .IR "Current line" :
  3112. Set to the last of the moved lines.
  3113. .P
  3114. .IR "Current column" :
  3115. Set to non-\c
  3116. <blank>.
  3117. .SS "Next"
  3118. .IP "\fISynopsis\fR:" 10
  3119. .sp -1v
  3120. .RS 10
  3121. .sp
  3122. .RS 4
  3123. .nf
  3124. n\fB[\fRext\fB][\fR!\fB][\fR+\fIcommand\fB][\fIfile \fR...\fB]\fR
  3125. .fi
  3126. .P
  3127. .RE
  3128. .RE
  3129. .P
  3130. If no
  3131. .BR '!'
  3132. is appended to the command name, and the edit buffer has been modified
  3133. since the last complete write, it shall be an error, unless the file is
  3134. successfully written as specified by the
  3135. .BR autowrite
  3136. option.
  3137. .br
  3138. .P
  3139. If one or more files is specified:
  3140. .IP " 1." 4
  3141. Set the argument list to the specified filenames.
  3142. .IP " 2." 4
  3143. Set the current argument list reference to be the first entry in the
  3144. argument list.
  3145. .IP " 3." 4
  3146. Set the current pathname to the first filename specified.
  3147. .P
  3148. Otherwise:
  3149. .IP " 1." 4
  3150. It shall be an error if there are no more filenames in the argument
  3151. list after the filename currently referenced.
  3152. .IP " 2." 4
  3153. Set the current pathname and the current argument list reference to
  3154. the filename after the filename currently referenced in the argument
  3155. list.
  3156. .P
  3157. Replace the contents of the edit buffer with the contents of the file
  3158. named by the current pathname. If for any reason the contents of the
  3159. file cannot be accessed, the edit buffer shall be empty.
  3160. .P
  3161. This command shall be affected by the
  3162. .BR autowrite
  3163. and
  3164. .BR writeany
  3165. edit options.
  3166. .P
  3167. The
  3168. .BR + \c
  3169. .IR command
  3170. option shall be
  3171. <blank>-delimited;
  3172. <blank>
  3173. characters can be escaped by preceding them with a
  3174. <backslash>
  3175. character. The
  3176. .BR + \c
  3177. .IR command
  3178. shall be interpreted as an
  3179. .IR ex
  3180. command immediately after the contents of the edit buffer have been
  3181. replaced and the current line and column have been set.
  3182. .P
  3183. .IR "Current line" :
  3184. Set as described for the
  3185. .BR edit
  3186. command.
  3187. .P
  3188. .IR "Current column" :
  3189. Set as described for the
  3190. .BR edit
  3191. command.
  3192. .SS "Number"
  3193. .IP "\fISynopsis\fR:" 10
  3194. .sp -1v
  3195. .RS 10
  3196. .sp
  3197. .RS 4
  3198. .nf
  3199. \fB[\fI2addr\fB] \fRnu\fB[\fRmber\fB][\fIcount\fB][\fIflags\fB]
  3200. [\fI2addr\fB] \fR#\fB[\fIcount\fB][\fIflags\fB]\fR
  3201. .fi
  3202. .P
  3203. .RE
  3204. .RE
  3205. .P
  3206. These commands shall be equivalent to the
  3207. .IR ex
  3208. command:
  3209. .sp
  3210. .RS 4
  3211. .nf
  3212. \fB[\fI2addr\fB] \fRp\fB[\fRrint\fB][\fIcount\fB] \fR#\fB[\fIflags\fB]\fR
  3213. .fi
  3214. .P
  3215. .RE
  3216. .P
  3217. See
  3218. .IR "Print".
  3219. .SS "Open"
  3220. .IP "\fISynopsis\fR:" 10
  3221. .sp -1v
  3222. .RS 10
  3223. .sp
  3224. .RS 4
  3225. .nf
  3226. \fB[\fI1addr\fB] \fRo\fB[\fRpen\fB]\fR /\fIpattern\fR/ \fB[\fIflags\fB]\fR
  3227. .fi
  3228. .P
  3229. .RE
  3230. .RE
  3231. .P
  3232. This command need not be supported on block-mode terminals or terminals
  3233. with insufficient capabilities. If standard input, standard output, or
  3234. standard error are not terminal devices, the results are unspecified.
  3235. .P
  3236. Enter open mode.
  3237. .P
  3238. The trailing delimiter can be omitted from
  3239. .IR pattern
  3240. at the end of the command line. If
  3241. .IR pattern
  3242. is empty (for example,
  3243. .BR \(dq//\(dq )
  3244. or not specified, the last regular expression used in the editor shall
  3245. be used as the pattern. The pattern can be delimited by
  3246. <slash>
  3247. characters (shown in the Synopsis), as well as any alphanumeric, or non-\c
  3248. <blank>
  3249. other than
  3250. <backslash>,
  3251. <vertical-line>,
  3252. <newline>,
  3253. or
  3254. double-quote.
  3255. .P
  3256. .IR "Current line" :
  3257. Set to the specified line.
  3258. .P
  3259. .IR "Current column" :
  3260. Set to non-\c
  3261. <blank>.
  3262. .SS "Preserve"
  3263. .IP "\fISynopsis\fR:" 10
  3264. .sp -1v
  3265. .RS 10
  3266. .sp
  3267. .RS 4
  3268. .nf
  3269. pre\fB[\fRserve\fB]\fR
  3270. .fi
  3271. .P
  3272. .RE
  3273. .RE
  3274. .P
  3275. Save the edit buffer in a form that can later be recovered by using the
  3276. .BR \-r
  3277. option or by using the
  3278. .IR ex
  3279. .BR recover
  3280. command. After the file has been preserved, a mail message shall be
  3281. sent to the user. This message shall be readable by invoking the
  3282. .IR mailx
  3283. utility. The message shall contain the name of the file, the time of
  3284. preservation, and an
  3285. .IR ex
  3286. command that could be used to recover the file. Additional information
  3287. may be included in the mail message.
  3288. .P
  3289. .IR "Current line" :
  3290. Unchanged.
  3291. .P
  3292. .IR "Current column" :
  3293. Unchanged.
  3294. .SS "Print"
  3295. .IP "\fISynopsis\fR:" 10
  3296. .sp -1v
  3297. .RS 10
  3298. .sp
  3299. .RS 4
  3300. .nf
  3301. \fB[\fI2addr\fB] \fRp\fB[\fRrint\fB][\fIcount\fB][\fIflags\fB]\fR
  3302. .fi
  3303. .P
  3304. .RE
  3305. .RE
  3306. .P
  3307. Write the addressed lines. The behavior is unspecified if the number of
  3308. columns on the display is less than the number of columns required to
  3309. write any single character in the lines being written.
  3310. .P
  3311. Non-printable characters, except for the
  3312. <tab>,
  3313. shall be written as implementation-defined multi-character sequences.
  3314. .P
  3315. If the
  3316. .BR #
  3317. flag is specified or the
  3318. .BR number
  3319. edit option is set, each line shall be preceded by its line number in
  3320. the following format:
  3321. .sp
  3322. .RS 4
  3323. .nf
  3324. "%6d ", <\fIline number\fR>
  3325. .fi
  3326. .P
  3327. .RE
  3328. .P
  3329. If the
  3330. .BR l
  3331. flag is specified or the
  3332. .BR list
  3333. edit option is set:
  3334. .IP " 1." 4
  3335. The characters listed in the Base Definitions volume of POSIX.1\(hy2017,
  3336. .IR "Table 5-1" ", " "Escape Sequences and Associated Actions"
  3337. shall be written as the corresponding escape sequence.
  3338. .IP " 2." 4
  3339. Non-printable characters not in the Base Definitions volume of POSIX.1\(hy2017,
  3340. .IR "Table 5-1" ", " "Escape Sequences and Associated Actions"
  3341. shall be written as one three-digit octal number (with a preceding
  3342. <backslash>)
  3343. for each byte in the character (most significant byte first).
  3344. .IP " 3." 4
  3345. The end of each line shall be marked with a
  3346. .BR '$' ,
  3347. and literal
  3348. .BR '$'
  3349. characters within the line shall be written with a preceding
  3350. <backslash>.
  3351. .P
  3352. Long lines shall be folded; the length at which folding occurs is
  3353. unspecified, but should be appropriate for the output terminal,
  3354. considering the number of columns of the terminal.
  3355. .P
  3356. If a line is folded, and the
  3357. .BR l
  3358. flag is not specified and the
  3359. .BR list
  3360. edit option is not set, it is unspecified whether a multi-column
  3361. character at the folding position is separated; it shall not be
  3362. discarded.
  3363. .P
  3364. .IR "Current line" :
  3365. Set to the last written line.
  3366. .P
  3367. .IR "Current column" :
  3368. Unchanged if the current line is unchanged; otherwise, set to non-\c
  3369. <blank>.
  3370. .SS "Put"
  3371. .IP "\fISynopsis\fR:" 10
  3372. .sp -1v
  3373. .RS 10
  3374. .sp
  3375. .RS 4
  3376. .nf
  3377. \fB[\fI1addr\fB] \fRpu\fB[\fRt\fB][\fIbuffer\fB]\fR
  3378. .fi
  3379. .P
  3380. .RE
  3381. .RE
  3382. .P
  3383. Append text from the specified buffer (by default, the unnamed buffer)
  3384. to the specified line; line zero specifies that the text shall be
  3385. placed at the beginning of the edit buffer. Each portion of a line in
  3386. the buffer shall become a new line in the edit buffer, regardless of
  3387. the mode of the buffer.
  3388. .P
  3389. .IR "Current line" :
  3390. Set to the last line entered into the edit buffer.
  3391. .P
  3392. .IR "Current column" :
  3393. Set to non-\c
  3394. <blank>.
  3395. .SS "Quit"
  3396. .IP "\fISynopsis\fR:" 10
  3397. .sp -1v
  3398. .RS 10
  3399. .sp
  3400. .RS 4
  3401. .nf
  3402. q\fB[\fRuit\fB][\fR!\fB]\fR
  3403. .fi
  3404. .P
  3405. .RE
  3406. .RE
  3407. .P
  3408. If no
  3409. .BR '!'
  3410. is appended to the command name:
  3411. .IP " 1." 4
  3412. If the edit buffer has been modified since the last complete write, it
  3413. shall be an error.
  3414. .IP " 2." 4
  3415. If there are filenames in the argument list after the filename
  3416. currently referenced, and the last command was not a
  3417. .BR quit ,
  3418. .BR wq ,
  3419. .BR xit ,
  3420. or
  3421. .BR ZZ
  3422. (see
  3423. .IR "Exit")
  3424. command, it shall be an error.
  3425. .P
  3426. Otherwise, terminate the editing session.
  3427. .SS "Read"
  3428. .IP "\fISynopsis\fR:" 10
  3429. .sp -1v
  3430. .RS 10
  3431. .sp
  3432. .RS 4
  3433. .nf
  3434. \fB[\fI1addr\fB] \fRr\fB[\fRead\fB][\fR!\fB][\fIfile\fB]\fR
  3435. .fi
  3436. .P
  3437. .RE
  3438. .RE
  3439. .P
  3440. If
  3441. .BR '!'
  3442. is not the first non-\c
  3443. <blank>
  3444. to follow the command name, a copy of the specified file shall be
  3445. appended into the edit buffer after the specified line; line zero
  3446. specifies that the copy shall be placed at the beginning of the edit
  3447. buffer. The number of lines and bytes read shall be written. If no
  3448. .IR file
  3449. is named, the current pathname shall be the default. If there is no
  3450. current pathname, then
  3451. .IR file
  3452. shall become the current pathname. If there is no current pathname or
  3453. .IR file
  3454. operand, it shall be an error. Specifying a
  3455. .IR file
  3456. that is not of type regular shall have unspecified results.
  3457. .P
  3458. Otherwise, if
  3459. .IR file
  3460. is preceded by
  3461. .BR '!' ,
  3462. the rest of the line after the
  3463. .BR '!'
  3464. shall have
  3465. .BR '%' ,
  3466. .BR '#' ,
  3467. and
  3468. .BR '!'
  3469. characters expanded as described in
  3470. .IR "Command Line Parsing in ex".
  3471. .P
  3472. The
  3473. .IR ex
  3474. utility shall then pass two arguments to the program named by the
  3475. shell edit option; the first shall be
  3476. .BR \-c
  3477. and the second shall be the expanded arguments to the
  3478. .BR read
  3479. command as a single argument. The standard input of the program shall
  3480. be set to the standard input of the
  3481. .IR ex
  3482. program when it was invoked. The standard error and standard output of
  3483. the program shall be appended into the edit buffer after the specified
  3484. line.
  3485. .P
  3486. Each line in the copied file or program output (as delimited by
  3487. <newline>
  3488. characters or the end of the file or output if it is not immediately
  3489. preceded by a
  3490. <newline>),
  3491. shall be a separate line in the edit buffer. Any occurrences of
  3492. <carriage-return>
  3493. and
  3494. <newline>
  3495. pairs in the output shall be treated as single
  3496. <newline>
  3497. characters.
  3498. .P
  3499. The special meaning of the
  3500. .BR '!'
  3501. following the
  3502. .BR read
  3503. command can be overridden by escaping it with a
  3504. <backslash>
  3505. character.
  3506. .P
  3507. .IR "Current line" :
  3508. If no lines are added to the edit buffer, unchanged. Otherwise, if in
  3509. open or visual mode, set to the first line entered into the edit
  3510. buffer. Otherwise, set to the last line entered into the edit buffer.
  3511. .P
  3512. .IR "Current column" :
  3513. Set to non-\c
  3514. <blank>.
  3515. .SS "Recover"
  3516. .IP "\fISynopsis\fR:" 10
  3517. .sp -1v
  3518. .RS 10
  3519. .sp
  3520. .RS 4
  3521. .nf
  3522. rec\fB[\fRover\fB][\fR!\fB] \fIfile\fR
  3523. .fi
  3524. .P
  3525. .RE
  3526. .RE
  3527. .P
  3528. If no
  3529. .BR '!'
  3530. is appended to the command name, and the edit buffer has been modified
  3531. since the last complete write, it shall be an error.
  3532. .P
  3533. If no
  3534. .IR file
  3535. operand is specified, then the current pathname shall be used. If
  3536. there is no current pathname or
  3537. .IR file
  3538. operand, it shall be an error.
  3539. .P
  3540. If no recovery information has previously been saved about
  3541. .IR file ,
  3542. the
  3543. .BR recover
  3544. command shall behave identically to the
  3545. .BR edit
  3546. command, and an informational message to this effect shall be written.
  3547. .P
  3548. Otherwise, set the current pathname to
  3549. .IR file ,
  3550. and replace the current contents of the edit buffer with the recovered
  3551. contents of
  3552. .IR file .
  3553. If there are multiple instances of the file to be recovered, the one
  3554. most recently saved shall be recovered, and an informational message
  3555. that there are previous versions of the file that can be recovered
  3556. shall be written. The editor shall behave as if the contents of the
  3557. edit buffer have already been modified.
  3558. .P
  3559. .IR "Current file" :
  3560. Set as described for the
  3561. .BR edit
  3562. command.
  3563. .P
  3564. .IR "Current column" :
  3565. Set as described for the
  3566. .BR edit
  3567. command.
  3568. .SS "Rewind"
  3569. .IP "\fISynopsis\fR:" 10
  3570. .sp -1v
  3571. .RS 10
  3572. .sp
  3573. .RS 4
  3574. .nf
  3575. rew\fB[\fRind\fB][\fR!\fB]\fR
  3576. .fi
  3577. .P
  3578. .RE
  3579. .RE
  3580. .P
  3581. If no
  3582. .BR '!'
  3583. is appended to the command name, and the edit buffer has been modified
  3584. since the last complete write, it shall be an error, unless the file is
  3585. successfully written as specified by the
  3586. .BR autowrite
  3587. option.
  3588. .P
  3589. If the argument list is empty, it shall be an error.
  3590. .P
  3591. The current argument list reference and the current pathname shall be
  3592. set to the first filename in the argument list.
  3593. .P
  3594. Replace the contents of the edit buffer with the contents of the file
  3595. named by the current pathname. If for any reason the contents of the
  3596. file cannot be accessed, the edit buffer shall be empty.
  3597. .P
  3598. This command shall be affected by the
  3599. .BR autowrite
  3600. and
  3601. .BR writeany
  3602. edit options.
  3603. .P
  3604. .IR "Current line" :
  3605. Set as described for the
  3606. .BR edit
  3607. command.
  3608. .P
  3609. .IR "Current column" :
  3610. Set as described for the
  3611. .BR edit
  3612. command.
  3613. .SS "Set"
  3614. .IP "\fISynopsis\fR:" 10
  3615. .sp -1v
  3616. .RS 10
  3617. .sp
  3618. .RS 4
  3619. .nf
  3620. se\fB[\fRt\fB][\fIoption\fB[\fR=\fB[\fIvalue\fB]]\fR ...\fB][\fRno\fIoption\fR ...\fB][\fIoption\fR? ...\fB][\fRall\fB]\fR
  3621. .fi
  3622. .P
  3623. .RE
  3624. .RE
  3625. .P
  3626. When no arguments are specified, write the value of the
  3627. .BR term
  3628. edit option and those options whose values have been changed from the
  3629. default settings; when the argument
  3630. .IR all
  3631. is specified, write all of the option values.
  3632. .P
  3633. Giving an option name followed by the character
  3634. .BR '?'
  3635. shall cause the current value of that option to be written. The
  3636. .BR '?'
  3637. can be separated from the option name by zero or more
  3638. <blank>
  3639. characters. The
  3640. .BR '?'
  3641. shall be necessary only for Boolean valued options. Boolean options can
  3642. be given values by the form
  3643. .BR set
  3644. .IR option
  3645. to turn them on or
  3646. .BR set
  3647. .BR no \c
  3648. .IR option
  3649. to turn them off; string and numeric options can be assigned by the
  3650. form
  3651. .BR set
  3652. .IR option =\c
  3653. .IR value .
  3654. Any
  3655. <blank>
  3656. characters in strings can be included as is by preceding each
  3657. <blank>
  3658. with an escaping
  3659. <backslash>.
  3660. More than one option can be set or listed by a single set command by
  3661. specifying multiple arguments, each separated from the next by one or more
  3662. <blank>
  3663. characters.
  3664. .P
  3665. See
  3666. .IR "Edit Options in ex"
  3667. for details about specific options.
  3668. .P
  3669. .IR "Current line" :
  3670. Unchanged.
  3671. .P
  3672. .IR "Current column" :
  3673. Unchanged.
  3674. .SS "Shell"
  3675. .IP "\fISynopsis\fR:" 10
  3676. .sp -1v
  3677. .RS 10
  3678. .sp
  3679. .RS 4
  3680. .nf
  3681. sh\fB[\fRell\fB]\fR
  3682. .fi
  3683. .P
  3684. .RE
  3685. .RE
  3686. .P
  3687. Invoke the program named in the
  3688. .BR shell
  3689. edit option with the single argument
  3690. .BR \-i
  3691. (interactive mode). Editing shall be resumed when the program exits.
  3692. .P
  3693. .IR "Current line" :
  3694. Unchanged.
  3695. .P
  3696. .IR "Current column" :
  3697. Unchanged.
  3698. .SS "Source"
  3699. .IP "\fISynopsis\fR:" 10
  3700. .sp -1v
  3701. .RS 10
  3702. .sp
  3703. .RS 4
  3704. .nf
  3705. so\fB[\fRurce\fB] \fIfile\fR
  3706. .fi
  3707. .P
  3708. .RE
  3709. .RE
  3710. .P
  3711. Read and execute
  3712. .IR ex
  3713. commands from
  3714. .IR file .
  3715. Lines in the file that are blank lines shall be ignored.
  3716. .P
  3717. .IR "Current line" :
  3718. As specified for the individual
  3719. .IR ex
  3720. commands.
  3721. .P
  3722. .IR "Current column" :
  3723. As specified for the individual
  3724. .IR ex
  3725. commands.
  3726. .SS "Substitute"
  3727. .IP "\fISynopsis\fR:" 10
  3728. .sp -1v
  3729. .RS 10
  3730. .sp
  3731. .RS 4
  3732. .nf
  3733. \fB[\fI2addr\fB] \fRs\fB[\fRubstitute\fB][\fR/\fIpattern\fR/\fIrepl\fR/\fB[\fIoptions\fB][\fIcount\fB][\fIflags\fB]]\fR
  3734. .br
  3735. \fB[\fI2addr\fB] \fR&\fB[\fIoptions\fB][\fIcount\fB][\fIflags\fB]]\fR
  3736. .br
  3737. \fB[\fI2addr\fB] \fR\(ti\fB[\fIoptions\fB][\fIcount\fB][\fIflags\fB]]\fR
  3738. .fi
  3739. .P
  3740. .RE
  3741. .RE
  3742. .P
  3743. Replace the first instance of the pattern
  3744. .IR pattern
  3745. by the string
  3746. .IR repl
  3747. on each specified line. (See
  3748. .IR "Regular Expressions in ex"
  3749. and
  3750. .IR "Replacement Strings in ex".)
  3751. Any non-alphabetic, non-\c
  3752. <blank>
  3753. delimiter other than
  3754. <backslash>,
  3755. .BR '|' ,
  3756. <newline>,
  3757. or double-quote
  3758. can be used instead of
  3759. .BR '/' .
  3760. <backslash>
  3761. characters can be used to escape delimiters,
  3762. <backslash>
  3763. characters, and other special characters.
  3764. .P
  3765. The trailing delimiter can be omitted from
  3766. .IR pattern
  3767. or from
  3768. .IR repl
  3769. at the end of the command line. If both
  3770. .IR pattern
  3771. and
  3772. .IR repl
  3773. are not specified or are empty (for example,
  3774. .BR \(dq//\(dq ),
  3775. the last
  3776. .BR s
  3777. command shall be repeated. If only
  3778. .IR pattern
  3779. is not specified or is empty, the last regular expression used in the
  3780. editor shall be used as the pattern. If only
  3781. .IR repl
  3782. is not specified or is empty, the pattern shall be replaced by nothing.
  3783. If the entire replacement pattern is
  3784. .BR '%' ,
  3785. the last replacement pattern to an
  3786. .BR s
  3787. command shall be used.
  3788. .P
  3789. Entering a
  3790. <carriage-return>
  3791. in
  3792. .IR repl
  3793. (which requires an escaping
  3794. <backslash>
  3795. in
  3796. .IR ex
  3797. mode and an escaping
  3798. <control>\(hyV
  3799. in open or
  3800. .IR vi
  3801. mode) shall split the line at that point, creating a new line in the
  3802. edit buffer. The
  3803. <carriage-return>
  3804. shall be discarded.
  3805. .P
  3806. If
  3807. .IR options
  3808. includes the letter
  3809. .BR 'g'
  3810. (\c
  3811. .BR global ),
  3812. all non-overlapping instances of the pattern in the line shall be
  3813. replaced.
  3814. .P
  3815. If
  3816. .IR options
  3817. includes the letter
  3818. .BR 'c'
  3819. (\c
  3820. .BR confirm ),
  3821. then before each substitution the line shall be written; the written
  3822. line shall reflect all previous substitutions. On the following line,
  3823. <space>
  3824. characters shall be written beneath the characters from the line that
  3825. are before the
  3826. .IR pattern
  3827. to be replaced, and
  3828. .BR '\(ha'
  3829. characters written beneath the characters included in the
  3830. .IR pattern
  3831. to be replaced. The
  3832. .IR ex
  3833. utility shall then wait for a response from the user. An affirmative
  3834. response shall cause the substitution to be done, while any other input
  3835. shall not make the substitution. An affirmative response shall consist
  3836. of a line with the affirmative response (as defined by the current
  3837. locale) at the beginning of the line. This line shall be subject to
  3838. editing in the same way as the
  3839. .IR ex
  3840. command line.
  3841. .P
  3842. If interrupted (see the ASYNCHRONOUS EVENTS section), any modifications
  3843. confirmed by the user shall be preserved in the edit buffer after the
  3844. interrupt.
  3845. .P
  3846. If the remembered search direction is not set, the
  3847. .BR s
  3848. command shall set it to forward.
  3849. .P
  3850. In the second Synopsis, the
  3851. .BR &
  3852. command shall repeat the previous substitution, as if the
  3853. .BR &
  3854. command were replaced by:
  3855. .sp
  3856. .RS 4
  3857. .nf
  3858. s/\fIpattern\fR/\fIrepl\fR/
  3859. .fi
  3860. .P
  3861. .RE
  3862. .P
  3863. where
  3864. .IR pattern
  3865. and
  3866. .IR repl
  3867. are as specified in the previous
  3868. .BR s ,
  3869. .BR & ,
  3870. or
  3871. .BR ~
  3872. command.
  3873. .P
  3874. In the third Synopsis, the
  3875. .BR ~
  3876. command shall repeat the previous substitution, as if the
  3877. .BR '\(ti'
  3878. were replaced by:
  3879. .sp
  3880. .RS 4
  3881. .nf
  3882. s/\fIpattern\fR/\fIrepl\fR/
  3883. .fi
  3884. .P
  3885. .RE
  3886. .P
  3887. where
  3888. .IR pattern
  3889. shall be the last regular expression specified to the editor, and
  3890. .IR repl
  3891. shall be from the previous substitution (including
  3892. .BR &
  3893. and
  3894. .BR ~ )
  3895. command.
  3896. .P
  3897. These commands shall be affected by the
  3898. .IR LC_MESSAGES
  3899. environment variable.
  3900. .P
  3901. .IR "Current line" :
  3902. Set to the last line in which a substitution occurred, or, unchanged if
  3903. no substitution occurred.
  3904. .P
  3905. .IR "Current column":
  3906. Set to non-\c
  3907. <blank>.
  3908. .SS "Suspend"
  3909. .IP "\fISynopsis\fR:" 10
  3910. .sp -1v
  3911. .RS 10
  3912. .sp
  3913. .RS 4
  3914. .nf
  3915. su\fB[\fRspend\fB][\fR!\fB]\fR
  3916. st\fB[\fRop\fB][\fR!\fB]\fR
  3917. .fi
  3918. .P
  3919. .RE
  3920. .RE
  3921. .P
  3922. Allow control to return to the invoking process;
  3923. .IR ex
  3924. shall suspend itself as if it had received the SIGTSTP signal. The
  3925. suspension shall occur only if job control is enabled in the invoking
  3926. shell (see the description of
  3927. .IR set
  3928. .BR \-m ).
  3929. .P
  3930. These commands shall be affected by the
  3931. .BR autowrite
  3932. and
  3933. .BR writeany
  3934. edit options.
  3935. .P
  3936. The current
  3937. .BR susp
  3938. character (see
  3939. .IR "\fIstty\fR\^")
  3940. shall be equivalent to the
  3941. .BR suspend
  3942. command.
  3943. .SS "Tag"
  3944. .IP "\fISynopsis\fR:" 10
  3945. .sp -1v
  3946. .RS 10
  3947. .sp
  3948. .RS 4
  3949. .nf
  3950. ta\fB[\fRg\fB][\fR!\fB] \fItagstring\fR
  3951. .fi
  3952. .P
  3953. .RE
  3954. .RE
  3955. .P
  3956. The results are unspecified if the format of a tags file is not as
  3957. specified by the
  3958. .IR ctags
  3959. utility (see
  3960. .IR "\fIctags\fR\^")
  3961. description.
  3962. .P
  3963. The
  3964. .BR tag
  3965. command shall search for
  3966. .IR tagstring
  3967. in the tag files referred to by the
  3968. .BR tag
  3969. edit option, in the order they are specified, until a reference to
  3970. .IR tagstring
  3971. is found. Files shall be searched from beginning to end. If no
  3972. reference is found, it shall be an error and an error message to this
  3973. effect shall be written. If the reference is not found, or if an error
  3974. occurs while processing a file referred to in the
  3975. .BR tag
  3976. edit option, it shall be an error, and an error message shall be
  3977. written at the first occurrence of such an error.
  3978. .P
  3979. Otherwise, if the tags file contained a pattern, the pattern shall be
  3980. treated as a regular expression used in the editor; for example, for
  3981. the purposes of the
  3982. .BR s
  3983. command.
  3984. .P
  3985. If the
  3986. .IR tagstring
  3987. is in a file with a different name than the current pathname, set the
  3988. current pathname to the name of that file, and replace the contents of
  3989. the edit buffer with the contents of that file. In this case, if no
  3990. .BR '!'
  3991. is appended to the command name, and the edit buffer has been modified
  3992. since the last complete write, it shall be an error, unless the file is
  3993. successfully written as specified by the
  3994. .BR autowrite
  3995. option.
  3996. .P
  3997. This command shall be affected by the
  3998. .BR autowrite ,
  3999. .BR tag ,
  4000. .BR taglength ,
  4001. and
  4002. .BR writeany
  4003. edit options.
  4004. .P
  4005. .IR "Current line" :
  4006. If the tags file contained a line number, set to that line number. If
  4007. the line number is larger than the last line in the edit buffer, an
  4008. error message shall be written and the current line shall be set as
  4009. specified for the
  4010. .BR edit
  4011. command.
  4012. .P
  4013. If the tags file contained a pattern, set to the first occurrence of
  4014. the pattern in the file. If no matching pattern is found, an error
  4015. message shall be written and the current line shall be set as specified
  4016. for the
  4017. .BR edit
  4018. command.
  4019. .P
  4020. .IR "Current column" :
  4021. If the tags file contained a line-number reference and that line-number
  4022. was not larger than the last line in the edit buffer, or if the tags
  4023. file contained a pattern and that pattern was found, set to non-\c
  4024. <blank>.
  4025. Otherwise, set as specified for the
  4026. .BR edit
  4027. command.
  4028. .SS "Unabbreviate"
  4029. .IP "\fISynopsis\fR:" 10
  4030. .sp -1v
  4031. .RS 10
  4032. .sp
  4033. .RS 4
  4034. .nf
  4035. una\fB[\fRbbrev\fB] \fIlhs\fR
  4036. .fi
  4037. .P
  4038. .RE
  4039. .RE
  4040. .P
  4041. If
  4042. .IR lhs
  4043. is not an entry in the current list of abbreviations (see
  4044. .IR "Abbreviate"),
  4045. it shall be an error. Otherwise, delete
  4046. .IR lhs
  4047. from the list of abbreviations.
  4048. .P
  4049. .IR "Current line" :
  4050. Unchanged.
  4051. .P
  4052. .IR "Current column" :
  4053. Unchanged.
  4054. .SS "Undo"
  4055. .IP "\fISynopsis\fR:" 10
  4056. .sp -1v
  4057. .RS 10
  4058. .sp
  4059. .RS 4
  4060. .nf
  4061. u\fB[\fRndo\fB]\fR
  4062. .fi
  4063. .P
  4064. .RE
  4065. .RE
  4066. .P
  4067. Reverse the changes made by the last command that modified the contents
  4068. of the edit buffer, including
  4069. .BR undo .
  4070. For this purpose, the
  4071. .BR global ,
  4072. .BR v ,
  4073. .BR open ,
  4074. and
  4075. .BR visual
  4076. commands, and commands resulting from buffer executions and mapped
  4077. character expansions, are considered single commands.
  4078. .P
  4079. If no action that can be undone preceded the
  4080. .BR undo
  4081. command, it shall be an error.
  4082. .P
  4083. If the
  4084. .BR undo
  4085. command restores lines that were marked, the mark shall also be
  4086. restored unless it was reset subsequent to the deletion of the lines.
  4087. .P
  4088. .IR "Current line" :
  4089. .IP " 1." 4
  4090. If lines are added or changed in the file, set to the first line added
  4091. or changed.
  4092. .IP " 2." 4
  4093. Set to the line before the first line deleted, if it exists.
  4094. .IP " 3." 4
  4095. Set to 1 if the edit buffer is not empty.
  4096. .IP " 4." 4
  4097. Set to zero.
  4098. .P
  4099. .IR "Current column" :
  4100. Set to non-\c
  4101. <blank>.
  4102. .SS "Unmap"
  4103. .IP "\fISynopsis\fR:" 10
  4104. .sp -1v
  4105. .RS 10
  4106. .sp
  4107. .RS 4
  4108. .nf
  4109. unm\fB[\fRap\fB][\fR!\fB] \fIlhs\fR
  4110. .fi
  4111. .P
  4112. .RE
  4113. .RE
  4114. .P
  4115. If
  4116. .BR '!'
  4117. is appended to the command name, and if
  4118. .IR lhs
  4119. is not an entry in the list of text input mode map definitions, it
  4120. shall be an error. Otherwise, delete
  4121. .IR lhs
  4122. from the list of text input mode map definitions.
  4123. .P
  4124. If no
  4125. .BR '!'
  4126. is appended to the command name, and if
  4127. .IR lhs
  4128. is not an entry in the list of command mode map definitions, it shall
  4129. be an error. Otherwise, delete
  4130. .IR lhs
  4131. from the list of command mode map definitions.
  4132. .P
  4133. .IR "Current line" :
  4134. Unchanged.
  4135. .P
  4136. .IR "Current column" :
  4137. Unchanged.
  4138. .SS "Version"
  4139. .IP "\fISynopsis\fR:" 10
  4140. .sp -1v
  4141. .RS 10
  4142. .sp
  4143. .RS 4
  4144. .nf
  4145. ve\fB[\fRrsion\fB]\fR
  4146. .fi
  4147. .P
  4148. .RE
  4149. .RE
  4150. .P
  4151. Write a message containing version information for the editor. The
  4152. format of the message is unspecified.
  4153. .P
  4154. .IR "Current line" :
  4155. Unchanged.
  4156. .P
  4157. .IR "Current column" :
  4158. Unchanged.
  4159. .SS "Visual"
  4160. .IP "\fISynopsis\fR:" 10
  4161. .sp -1v
  4162. .RS 10
  4163. .sp
  4164. .RS 4
  4165. .nf
  4166. \fB[\fI1addr\fB] \fRvi\fB[\fRsual\fB][\fItype\fB][\fIcount\fB][\fIflags\fB]\fR
  4167. .fi
  4168. .P
  4169. .RE
  4170. .RE
  4171. .P
  4172. If
  4173. .IR ex
  4174. is currently in open or visual mode, the Synopsis and behavior of the
  4175. visual command shall be the same as the
  4176. .BR edit
  4177. command, as specified by
  4178. .IR "Edit".
  4179. .P
  4180. Otherwise, this command need not be supported on block-mode terminals
  4181. or terminals with insufficient capabilities. If standard input,
  4182. standard output, or standard error are not terminal devices, the
  4183. results are unspecified.
  4184. .P
  4185. If
  4186. .IR count
  4187. is specified, the value of the
  4188. .BR window
  4189. edit option shall be set to
  4190. .IR count
  4191. (as described in
  4192. .IR "window").
  4193. If the
  4194. .BR '\(ha'
  4195. type character was also specified, the
  4196. .BR window
  4197. edit option shall be set before being used by the type character.
  4198. .P
  4199. Enter visual mode. If
  4200. .IR type
  4201. is not specified, it shall be as if a
  4202. .IR type
  4203. of
  4204. .BR '\(pl'
  4205. was specified. The
  4206. .IR type
  4207. shall cause the following effects:
  4208. .IP "\fR+\fP" 6
  4209. Place the beginning of the specified line at the top of the display.
  4210. .IP "\fR-\fP" 6
  4211. Place the end of the specified line at the bottom of the display.
  4212. .IP "\fR.\fP" 6
  4213. Place the beginning of the specified line in the middle of the display.
  4214. .IP "\fR^\fP" 6
  4215. If the specified line is less than or equal to the value of the
  4216. .BR window
  4217. edit option, set the line to 1; otherwise, decrement the line by the
  4218. value of the
  4219. .BR window
  4220. edit option minus 1. Place the beginning of this line as close to the
  4221. bottom of the displayed lines as possible, while still displaying the
  4222. value of the
  4223. .BR window
  4224. edit option number of lines.
  4225. .P
  4226. .IR "Current line" :
  4227. Set to the specified line.
  4228. .P
  4229. .IR "Current column" :
  4230. Set to non-\c
  4231. <blank>.
  4232. .SS "Write"
  4233. .IP "\fISynopsis\fR:" 10
  4234. .sp -1v
  4235. .RS 10
  4236. .sp
  4237. .RS 4
  4238. .nf
  4239. \fB[\fI2addr\fB] \fRw\fB[\fRrite\fB][\fR!\fB][\fR>>\fB][\fIfile\fB]
  4240. [\fI2addr\fB] \fRw\fB[\fRrite\fB][\fR!\fB][\fIfile\fB]
  4241. [\fI2addr\fB] \fRwq\fB[\fR!\fB][\fR>>\fB][\fIfile\fB]\fR
  4242. .fi
  4243. .P
  4244. .RE
  4245. .RE
  4246. .P
  4247. If no lines are specified, the lines shall default to the entire file.
  4248. .P
  4249. The command
  4250. .BR wq
  4251. shall be equivalent to a
  4252. .BR write
  4253. command followed by a
  4254. .BR quit
  4255. command;
  4256. .BR wq!
  4257. shall be equivalent to
  4258. .BR write!
  4259. followed by
  4260. .BR quit .
  4261. In both cases, if the
  4262. .BR write
  4263. command fails, the
  4264. .BR quit
  4265. shall not be attempted.
  4266. .P
  4267. If the command name is not followed by one or more
  4268. <blank>
  4269. characters, or
  4270. .IR file
  4271. is not preceded by a
  4272. .BR '!'
  4273. character, the
  4274. .BR write
  4275. shall be to a file.
  4276. .IP " 1." 4
  4277. If the
  4278. .BR >>
  4279. argument is specified, and the file already exists, the lines shall be
  4280. appended to the file instead of replacing its contents. If the
  4281. .BR >>
  4282. argument is specified, and the file does not already exist, it is
  4283. unspecified whether the write shall proceed as if the
  4284. .BR >>
  4285. argument had not been specified or if the write shall fail.
  4286. .IP " 2." 4
  4287. If the
  4288. .BR readonly
  4289. edit option is set (see
  4290. .IR "readonly"),
  4291. the
  4292. .BR write
  4293. shall fail.
  4294. .IP " 3." 4
  4295. If
  4296. .IR file
  4297. is specified, and is not the current pathname, and the file exists,
  4298. the
  4299. .BR write
  4300. shall fail.
  4301. .IP " 4." 4
  4302. If
  4303. .IR file
  4304. is not specified, the current pathname shall be used. If there is no
  4305. current pathname, the
  4306. .BR write
  4307. command shall fail.
  4308. .IP " 5." 4
  4309. If the current pathname is used, and the current pathname has been
  4310. changed by the
  4311. .BR file
  4312. or
  4313. .BR read
  4314. commands, and the file exists, the
  4315. .BR write
  4316. shall fail. If the
  4317. .BR write
  4318. is successful, subsequent
  4319. .BR write s
  4320. shall not fail for this reason (unless the current pathname is changed
  4321. again).
  4322. .IP " 6." 4
  4323. If the whole edit buffer is not being written, and the file to be
  4324. written exists, the
  4325. .BR write
  4326. shall fail.
  4327. .P
  4328. For rules 1., 2., 3., and 5., the
  4329. .BR write
  4330. can be forced by appending the character
  4331. .BR '!'
  4332. to the command name.
  4333. .P
  4334. For rules 2., 3., and 5., the
  4335. .BR write
  4336. can be forced by setting the
  4337. .BR writeany
  4338. edit option.
  4339. .P
  4340. Additional, implementation-defined tests may cause the
  4341. .BR write
  4342. to fail.
  4343. .P
  4344. If the edit buffer is empty, a file without any contents shall be written.
  4345. .P
  4346. An informational message shall be written noting the number of lines
  4347. and bytes written.
  4348. .P
  4349. Otherwise, if the command is followed by one or more
  4350. <blank>
  4351. characters, and the file is preceded by
  4352. .BR '!' ,
  4353. the rest of the line after the
  4354. .BR '!'
  4355. shall have
  4356. .BR '%' ,
  4357. .BR '#' ,
  4358. and
  4359. .BR '!'
  4360. characters expanded as described in
  4361. .IR "Command Line Parsing in ex".
  4362. .P
  4363. The
  4364. .IR ex
  4365. utility shall then pass two arguments to the program named by the
  4366. .BR shell
  4367. edit option; the first shall be
  4368. .BR \-c
  4369. and the second shall be the expanded arguments to the
  4370. .BR write
  4371. command as a single argument. The specified lines shall be written to
  4372. the standard input of the command. The standard error and standard
  4373. output of the program, if any, shall be written as described for the
  4374. .BR print
  4375. command. If the last character in that output is not a
  4376. <newline>,
  4377. a
  4378. <newline>
  4379. shall be written at the end of the output.
  4380. .P
  4381. The special meaning of the
  4382. .BR '!'
  4383. following the
  4384. .BR write
  4385. command can be overridden by escaping it with a
  4386. <backslash>
  4387. character.
  4388. .P
  4389. .IR "Current line" :
  4390. Unchanged.
  4391. .P
  4392. .IR "Current column" :
  4393. Unchanged.
  4394. .SS "Write and Exit"
  4395. .IP "\fISynopsis\fR:" 10
  4396. .sp -1v
  4397. .RS 10
  4398. .sp
  4399. .RS 4
  4400. .nf
  4401. \fB[\fI2addr\fB] \fRx\fB[\fRit\fB][\fR!\fB][\fIfile\fB]\fR
  4402. .fi
  4403. .P
  4404. .RE
  4405. .RE
  4406. .P
  4407. If the edit buffer has not been modified since the last complete
  4408. .BR write ,
  4409. .BR xit
  4410. shall be equivalent to the
  4411. .BR quit
  4412. command, or if a
  4413. .BR '!'
  4414. is appended to the command name, to
  4415. .BR quit! .
  4416. .P
  4417. Otherwise,
  4418. .BR xit
  4419. shall be equivalent to the
  4420. .BR wq
  4421. command, or if a
  4422. .BR '!'
  4423. is appended to the command name, to
  4424. .BR wq! .
  4425. .P
  4426. .IR "Current line" :
  4427. Unchanged.
  4428. .P
  4429. .IR "Current column" :
  4430. Unchanged.
  4431. .SS "Yank"
  4432. .IP "\fISynopsis\fR:" 10
  4433. .sp -1v
  4434. .RS 10
  4435. .sp
  4436. .RS 4
  4437. .nf
  4438. \fB[\fI2addr\fB] \fRya\fB[\fRnk\fB][\fIbuffer\fB][\fIcount\fB]\fR
  4439. .fi
  4440. .P
  4441. .RE
  4442. .RE
  4443. .P
  4444. Copy the specified lines to the specified buffer (by default, the
  4445. unnamed buffer), which shall become a line-mode buffer.
  4446. .P
  4447. .IR "Current line" :
  4448. Unchanged.
  4449. .P
  4450. .IR "Current column" :
  4451. Unchanged.
  4452. .SS "Adjust Window"
  4453. .IP "\fISynopsis\fR:" 10
  4454. .sp -1v
  4455. .RS 10
  4456. .sp
  4457. .RS 4
  4458. .nf
  4459. \fB[\fI1addr\fB] \fRz\fB[\fR!\fB][\fItype \fR...\fB][\fIcount\fB][\fIflags\fB]\fR
  4460. .fi
  4461. .P
  4462. .RE
  4463. .RE
  4464. .P
  4465. If no line is specified, the current line shall be the default; if
  4466. .IR type
  4467. is omitted as well, the current line value shall first be incremented
  4468. by 1. If incrementing the current line would cause it to be greater
  4469. than the last line in the edit buffer, it shall be an error.
  4470. .P
  4471. If there are
  4472. <blank>
  4473. characters between the
  4474. .IR type
  4475. argument and the preceding
  4476. .BR z
  4477. command name or optional
  4478. .BR '!'
  4479. character, it shall be an error.
  4480. .P
  4481. If
  4482. .IR count
  4483. is specified, the value of the
  4484. .BR window
  4485. edit option shall be set to
  4486. .IR count
  4487. (as described in
  4488. .IR "window").
  4489. If
  4490. .IR count
  4491. is omitted, it shall default to 2 times the value of the
  4492. .BR scroll
  4493. edit option, or if
  4494. .BR !
  4495. was specified, the number of lines in the display minus 1.
  4496. .P
  4497. If
  4498. .IR type
  4499. is omitted, then
  4500. .IR count
  4501. lines starting with the specified line shall be written. Otherwise,
  4502. .IR count
  4503. lines starting with the line specified by the
  4504. .IR type
  4505. argument shall be written.
  4506. .P
  4507. The
  4508. .IR type
  4509. argument shall change the lines to be written. The possible values of
  4510. .IR type
  4511. are as follows:
  4512. .IP "\fR\-\fP" 6
  4513. The specified line shall be decremented by the following value:
  4514. .RS 6
  4515. .sp
  4516. .RS 4
  4517. .nf
  4518. (((number of \(aq-\(aq characters) x \fIcount\fR) -1)
  4519. .fi
  4520. .P
  4521. .RE
  4522. .P
  4523. If the calculation would result in a number less than 1, it shall be an
  4524. error. Write lines from the edit buffer, starting at the new value of
  4525. line, until
  4526. .IR count
  4527. lines or the last line in the edit buffer has been written.
  4528. .RE
  4529. .IP "\fR+\fP" 6
  4530. The specified line shall be incremented by the following value:
  4531. .RS 6
  4532. .sp
  4533. .RS 4
  4534. .nf
  4535. (((number of \(aq+\(aq characters) -1) x \fIcount\fR) +1
  4536. .fi
  4537. .P
  4538. .RE
  4539. .P
  4540. If the calculation would result in a number greater than the last line
  4541. in the edit buffer, it shall be an error. Write lines from the edit
  4542. buffer, starting at the new value of line, until
  4543. .IR count
  4544. lines or the last line in the edit buffer has been written.
  4545. .RE
  4546. .IP "\fR=\fR,\fR.\fR" 6
  4547. If more than a single
  4548. .BR '.'
  4549. or
  4550. .BR '='
  4551. is specified, it shall be an error. The following steps shall be
  4552. taken:
  4553. .RS 6
  4554. .IP " 1." 4
  4555. If
  4556. .IR count
  4557. is zero, nothing shall be written.
  4558. .IP " 2." 4
  4559. Write as many of the
  4560. .IR N
  4561. lines before the current line in the edit buffer as exist. If
  4562. .IR count
  4563. or
  4564. .BR '!'
  4565. was specified,
  4566. .IR N
  4567. shall be:
  4568. .RS 4
  4569. .sp
  4570. .RS 4
  4571. .nf
  4572. (\fIcount\fR -1) /2
  4573. .fi
  4574. .P
  4575. .RE
  4576. .P
  4577. Otherwise,
  4578. .IR N
  4579. shall be:
  4580. .sp
  4581. .RS 4
  4582. .nf
  4583. (\fIcount\fP -3) /2
  4584. .fi
  4585. .P
  4586. .RE
  4587. .P
  4588. If
  4589. .IR N
  4590. is a number less than 3, no lines shall be written.
  4591. .RE
  4592. .IP " 3." 4
  4593. If
  4594. .BR '='
  4595. was specified as the type character, write a line consisting of the
  4596. smaller of the number of columns in the display divided by two, or 40
  4597. .BR '\-'
  4598. characters.
  4599. .IP " 4." 4
  4600. Write the current line.
  4601. .IP " 5." 4
  4602. Repeat step 3.
  4603. .IP " 6." 4
  4604. Write as many of the
  4605. .IR N
  4606. lines after the current line in the edit buffer as exist.
  4607. .IR N
  4608. shall be defined as in step 2. If
  4609. .IR N
  4610. is a number less than 3, no lines shall be written. If
  4611. .IR count
  4612. is less than 3, no lines shall be written.
  4613. .RE
  4614. .IP "\fR^\fP" 6
  4615. The specified line shall be decremented by the following value:
  4616. .RS 6
  4617. .sp
  4618. .RS 4
  4619. .nf
  4620. (((number of \(aq\(ha\(aq characters) +1) x \fIcount\fR) -1
  4621. .fi
  4622. .P
  4623. .RE
  4624. .P
  4625. If the calculation would result in a number less than 1, it shall be an
  4626. error. Write lines from the edit buffer, starting at the new value of
  4627. line, until
  4628. .IR count
  4629. lines or the last line in the edit buffer has been written.
  4630. .RE
  4631. .P
  4632. .IR "Current line" :
  4633. Set to the last line written, unless the type is
  4634. .BR = ,
  4635. in which case, set to the specified line.
  4636. .P
  4637. .IR "Current column" :
  4638. Set to non-\c
  4639. <blank>.
  4640. .SS "Escape"
  4641. .IP "\fISynopsis\fR:" 10
  4642. .sp -1v
  4643. .RS 10
  4644. .sp
  4645. .RS 4
  4646. .nf
  4647. ! \fIcommand
  4648. \fB[\fIaddr\fB]\fR! \fIcommand\fR
  4649. .fi
  4650. .P
  4651. .RE
  4652. .RE
  4653. .P
  4654. The contents of the line after the
  4655. .BR '!'
  4656. shall have
  4657. .BR '%' ,
  4658. .BR '#' ,
  4659. and
  4660. .BR '!'
  4661. characters expanded as described in
  4662. .IR "Command Line Parsing in ex".
  4663. If the expansion causes the text of the line to change, it shall be
  4664. redisplayed, preceded by a single
  4665. .BR '!'
  4666. character.
  4667. .P
  4668. The
  4669. .IR ex
  4670. utility shall execute the program named by the
  4671. .BR shell
  4672. edit option. It shall pass two arguments to the program; the first
  4673. shall be
  4674. .BR \-c ,
  4675. and the second shall be the expanded arguments to the
  4676. .BR !
  4677. command as a single argument.
  4678. .P
  4679. If no lines are specified, the standard input, standard output, and
  4680. standard error of the program shall be set to the standard input,
  4681. standard output, and standard error of the
  4682. .IR ex
  4683. program when it was invoked. In addition, a warning message shall be
  4684. written if the edit buffer has been modified since the last complete
  4685. write, and the
  4686. .BR warn
  4687. edit option is set.
  4688. .P
  4689. If lines are specified, they shall be passed to the program as standard
  4690. input, and the standard output and standard error of the program shall
  4691. replace those lines in the edit buffer. Each line in the program output
  4692. (as delimited by
  4693. <newline>
  4694. characters or the end of the output if it is not immediately preceded by a
  4695. <newline>),
  4696. shall be a separate line in the edit buffer. Any occurrences of
  4697. <carriage-return>
  4698. and
  4699. <newline>
  4700. pairs in the output shall be treated as single
  4701. <newline>
  4702. characters. The specified lines shall be copied into the unnamed buffer
  4703. before they are replaced, and the unnamed buffer shall become a line-mode
  4704. buffer.
  4705. .P
  4706. If in
  4707. .IR ex
  4708. mode, a single
  4709. .BR '!'
  4710. character shall be written when the program completes.
  4711. .P
  4712. This command shall be affected by the
  4713. .BR shell
  4714. and
  4715. .BR warn
  4716. edit options. If no lines are specified, this command shall be affected
  4717. by the
  4718. .BR autowrite
  4719. and
  4720. .BR writeany
  4721. edit options. If lines are specified, this command shall be affected by
  4722. the
  4723. .BR autoprint
  4724. edit option.
  4725. .br
  4726. .P
  4727. .IR "Current line" :
  4728. .IP " 1." 4
  4729. If no lines are specified, unchanged.
  4730. .IP " 2." 4
  4731. Otherwise, set to the last line read in, if any lines are read in.
  4732. .IP " 3." 4
  4733. Otherwise, set to the line before the first line of the lines
  4734. specified, if that line exists.
  4735. .IP " 4." 4
  4736. Otherwise, set to the first line of the edit buffer if the edit buffer
  4737. is not empty.
  4738. .IP " 5." 4
  4739. Otherwise, set to zero.
  4740. .P
  4741. .IR "Current column" :
  4742. If no lines are specified, unchanged. Otherwise, set to non-\c
  4743. <blank>.
  4744. .SS "Shift Left"
  4745. .IP "\fISynopsis\fR:" 10
  4746. .sp -1v
  4747. .RS 10
  4748. .sp
  4749. .RS 4
  4750. .nf
  4751. \fB[\fI2addr\fB]\fR <\fB[\fR< ...\fB][\fIcount\fB][\fIflags\fB]\fR
  4752. .fi
  4753. .P
  4754. .RE
  4755. .RE
  4756. .P
  4757. Shift the specified lines to the start of the line; the number of
  4758. column positions to be shifted shall be the number of command
  4759. characters times the value of the
  4760. .BR shiftwidth
  4761. edit option. Only leading
  4762. <blank>
  4763. characters shall be deleted or changed into other
  4764. <blank>
  4765. characters in shifting; other characters shall not be affected.
  4766. .P
  4767. Lines to be shifted shall be copied into the unnamed buffer, which
  4768. shall become a line-mode buffer.
  4769. .P
  4770. This command shall be affected by the
  4771. .BR autoprint
  4772. edit option.
  4773. .P
  4774. .IR "Current line" :
  4775. Set to the last line in the lines specified.
  4776. .P
  4777. .IR "Current column" :
  4778. Set to non-\c
  4779. <blank>.
  4780. .SS "Shift Right"
  4781. .IP "\fISynopsis\fR:" 10
  4782. .sp -1v
  4783. .RS 10
  4784. .sp
  4785. .RS 4
  4786. .nf
  4787. \fB[\fI2addr\fB]\fR >\fB[\fR> ...\fB][\fIcount\fB][\fIflags\fB]\fR
  4788. .fi
  4789. .P
  4790. .RE
  4791. .RE
  4792. .P
  4793. Shift the specified lines away from the start of the line; the number
  4794. of column positions to be shifted shall be the number of command
  4795. characters times the value of the
  4796. .BR shiftwidth
  4797. edit option. The shift shall be accomplished by adding
  4798. <blank>
  4799. characters as a prefix to the line or changing leading
  4800. <blank>
  4801. characters into other
  4802. <blank>
  4803. characters. Empty lines shall not be changed.
  4804. .P
  4805. Lines to be shifted shall be copied into the unnamed buffer, which
  4806. shall become a line-mode buffer.
  4807. .P
  4808. This command shall be affected by the
  4809. .BR autoprint
  4810. edit option.
  4811. .P
  4812. .IR "Current line" :
  4813. Set to the last line in the lines specified.
  4814. .P
  4815. .IR "Current column" :
  4816. Set to non-\c
  4817. <blank>.
  4818. .SS "<control>\(hyD"
  4819. .IP "\fISynopsis\fR:" 10
  4820. .sp -1v
  4821. .RS 10
  4822. .sp
  4823. .RS 4
  4824. .nf
  4825. <control>-D
  4826. .fi
  4827. .P
  4828. .RE
  4829. .RE
  4830. .P
  4831. Write the next
  4832. .IR n
  4833. lines, where
  4834. .IR n
  4835. is the minimum of the values of the
  4836. .BR scroll
  4837. edit option and the number of lines after the current line in the edit
  4838. buffer. If the current line is the last line of the edit buffer it
  4839. shall be an error.
  4840. .P
  4841. .IR "Current line" :
  4842. Set to the last line written.
  4843. .P
  4844. .IR "Current column" :
  4845. Set to non-\c
  4846. <blank>.
  4847. .SS "Write Line Number"
  4848. .IP "\fISynopsis\fR:" 10
  4849. .sp -1v
  4850. .RS 10
  4851. .sp
  4852. .RS 4
  4853. .nf
  4854. \fB[\fI1addr\fB] \fR= \fB[\fIflags\fB]\fR
  4855. .fi
  4856. .P
  4857. .RE
  4858. .RE
  4859. .P
  4860. If
  4861. .IR line
  4862. is not specified, it shall default to the last line in the edit buffer.
  4863. Write the line number of the specified line.
  4864. .P
  4865. .IR "Current line" :
  4866. Unchanged.
  4867. .P
  4868. .IR "Current column" :
  4869. Unchanged.
  4870. .SS "Execute"
  4871. .IP "\fISynopsis\fR:" 10
  4872. .sp -1v
  4873. .RS 10
  4874. .sp
  4875. .RS 4
  4876. .nf
  4877. \fB[\fI2addr\fB]\fR @ \fIbuffer\fR
  4878. \fB[\fI2addr\fB]\fR * \fIbuffer\fR
  4879. .fi
  4880. .P
  4881. .RE
  4882. .RE
  4883. .P
  4884. If no buffer is specified or is specified as
  4885. .BR '@'
  4886. or
  4887. .BR '*' ,
  4888. the last buffer executed shall be used. If no previous buffer has been
  4889. executed, it shall be an error.
  4890. .P
  4891. For each line specified by the addresses, set the current line (\c
  4892. .BR '.' )
  4893. to the specified line, and execute the contents of the named
  4894. .IR buffer
  4895. (as they were at the time the
  4896. .BR @
  4897. command was executed) as
  4898. .IR ex
  4899. commands. For each line of a line-mode buffer, and all but the last
  4900. line of a character-mode buffer, the
  4901. .IR ex
  4902. command parser shall behave as if the line was terminated by a
  4903. <newline>.
  4904. .P
  4905. If an error occurs during this process, or a line specified by the
  4906. addresses does not exist when the current line would be set to it, or
  4907. more than a single line was specified by the addresses, and the
  4908. contents of the edit buffer are replaced (for example, by the
  4909. .IR ex
  4910. .BR :edit
  4911. command) an error message shall be written, and no more commands
  4912. resulting from the execution of this command shall be processed.
  4913. .P
  4914. .IR "Current line" :
  4915. As specified for the individual
  4916. .IR ex
  4917. commands.
  4918. .P
  4919. .IR "Current column" :
  4920. As specified for the individual
  4921. .IR ex
  4922. commands.
  4923. .SS "Regular Expressions in ex"
  4924. .P
  4925. The
  4926. .IR ex
  4927. utility shall support regular expressions that are a superset of the
  4928. basic regular expressions described in the Base Definitions volume of POSIX.1\(hy2017,
  4929. .IR "Section 9.3" ", " "Basic Regular Expressions".
  4930. A null regular expression (\c
  4931. .BR \(dq//\(dq )
  4932. shall be equivalent to the last regular expression encountered.
  4933. .P
  4934. Regular expressions can be used in addresses to specify lines and, in
  4935. some commands (for example, the
  4936. .BR substitute
  4937. command), to specify portions of a line to be substituted.
  4938. .P
  4939. The following constructs can be used to enhance the basic regular
  4940. expressions:
  4941. .IP "\fR\e<\fR" 6
  4942. Match the beginning of a
  4943. .IR word .
  4944. (See the definition of
  4945. .IR word
  4946. at the beginning of
  4947. .IR "Command Descriptions in ex".)
  4948. .IP "\fR\e>\fR" 6
  4949. Match the end of a
  4950. .IR word .
  4951. .IP "\fR~\fR" 6
  4952. Match the replacement part of the last
  4953. .BR substitute
  4954. command. The
  4955. <tilde>
  4956. (\c
  4957. .BR '\(ti' )
  4958. character can be escaped in a regular expression to become a normal
  4959. character with no special meaning. The
  4960. <backslash>
  4961. shall be discarded.
  4962. .P
  4963. When the editor option
  4964. .BR magic
  4965. is not set, the only characters with special meanings shall be
  4966. .BR '\(ha'
  4967. at the beginning of a pattern,
  4968. .BR '$'
  4969. at the end of a pattern, and
  4970. <backslash>.
  4971. The characters
  4972. .BR '.' ,
  4973. .BR '*' ,
  4974. .BR '[' ,
  4975. and
  4976. .BR '\(ti'
  4977. shall be treated as ordinary characters unless preceded by a
  4978. <backslash>;
  4979. when preceded by a
  4980. <backslash>
  4981. they shall regain their special meaning, or in the case of
  4982. <backslash>,
  4983. be handled as a single
  4984. <backslash>.
  4985. <backslash>
  4986. characters used to escape other characters shall be discarded.
  4987. .SS "Replacement Strings in ex"
  4988. .P
  4989. The character
  4990. .BR '&'
  4991. (\c
  4992. .BR '\e&'
  4993. if the editor option
  4994. .BR magic
  4995. is not set) in the replacement string shall stand for the text matched
  4996. by the pattern to be replaced. The character
  4997. .BR '\(ti'
  4998. (\c
  4999. .BR '\e\(ti'
  5000. if
  5001. .BR magic
  5002. is not set) shall be replaced by the replacement part of the previous
  5003. .BR substitute
  5004. command. The sequence
  5005. .BR '\en' ,
  5006. where
  5007. .IR n
  5008. is an integer, shall be replaced by the text matched by the
  5009. corresponding back-reference expression. If the corresponding
  5010. back-reference expression does not match, then the characters
  5011. .BR '\en'
  5012. shall be replaced by the empty string.
  5013. .P
  5014. The strings
  5015. .BR '\el' ,
  5016. .BR '\eu' ,
  5017. .BR '\eL' ,
  5018. and
  5019. .BR '\eU'
  5020. can be used to modify the case of elements in the replacement string
  5021. (using the
  5022. .BR '\e&'
  5023. or
  5024. .BR \(dq\e\(dq digit)
  5025. notation. The string
  5026. .BR '\el'
  5027. (\c
  5028. .BR '\eu' )
  5029. shall cause the character that follows to be converted to lowercase
  5030. (uppercase). The string
  5031. .BR '\eL'
  5032. (\c
  5033. .BR '\eU' )
  5034. shall cause all characters subsequent to it to be converted to
  5035. lowercase (uppercase) as they are inserted by the substitution until
  5036. the string
  5037. .BR '\ee'
  5038. or
  5039. .BR '\eE' ,
  5040. or the end of the replacement string, is encountered.
  5041. .P
  5042. Otherwise, any character following a
  5043. <backslash>
  5044. shall be treated as that literal character, and the escaping
  5045. <backslash>
  5046. shall be discarded.
  5047. .P
  5048. An example of case conversion with the
  5049. .BR s
  5050. command is as follows:
  5051. .sp
  5052. .RS 4
  5053. .nf
  5054. \fB:\fRp
  5055. \fBThe cat sat on the mat.
  5056. \fB:\fRs/\e<.at\e>/\eu&/gp
  5057. \fBThe Cat Sat on the Mat.
  5058. \fB:\fRs/S\e(.*\e)M/S\eU\e1\eeM/p
  5059. \fBThe Cat SAT ON THE Mat.\fR
  5060. .fi
  5061. .P
  5062. .RE
  5063. .SS "Edit Options in ex"
  5064. .P
  5065. The
  5066. .IR ex
  5067. utility has a number of options that modify its behavior. These options
  5068. have default settings, which can be changed using the
  5069. .BR set
  5070. command.
  5071. .P
  5072. Options are Boolean unless otherwise specified.
  5073. .SS "autoindent, ai"
  5074. .P
  5075. [Default \fIunset\fR]
  5076. .P
  5077. If
  5078. .BR autoindent
  5079. is set, each line in input mode shall be indented (using first as many
  5080. <tab>
  5081. characters as possible, as determined by the editor option
  5082. .BR tabstop ,
  5083. and then using
  5084. <space>
  5085. characters) to align with another line, as follows:
  5086. .IP " 1." 4
  5087. If in open or visual mode and the text input is part of a line-oriented
  5088. command (see the EXTENDED DESCRIPTION in
  5089. .IR "\fIvi\fR\^"),
  5090. align to the first column.
  5091. .IP " 2." 4
  5092. Otherwise, if in open or visual mode, indentation for each line shall
  5093. be set as follows:
  5094. .RS 4
  5095. .IP " a." 4
  5096. If a line was previously inserted as part of this command, it shall be
  5097. set to the indentation of the last inserted line by default, or as
  5098. otherwise specified for the
  5099. <control>\(hyD
  5100. character in
  5101. .IR "Input Mode Commands in vi".
  5102. .IP " b." 4
  5103. Otherwise, it shall be set to the indentation of the previous current
  5104. line, if any; otherwise, to the first column.
  5105. .RE
  5106. .IP " 3." 4
  5107. For the
  5108. .IR ex
  5109. .BR a ,
  5110. .BR i ,
  5111. and
  5112. .BR c
  5113. commands, indentation for each line shall be set as follows:
  5114. .RS 4
  5115. .IP " a." 4
  5116. If a line was previously inserted as part of this command, it shall be
  5117. set to the indentation of the last inserted line by default, or as
  5118. otherwise specified for the
  5119. .IR eof
  5120. character in
  5121. .IR "Scroll".
  5122. .IP " b." 4
  5123. Otherwise, if the command is the
  5124. .IR ex
  5125. .BR a
  5126. command, it shall be set to the line appended after, if any; otherwise
  5127. to the first column.
  5128. .IP " c." 4
  5129. Otherwise, if the command is the
  5130. .IR ex
  5131. .BR i
  5132. command, it shall be set to the line inserted before, if any; otherwise
  5133. to the first column.
  5134. .IP " d." 4
  5135. Otherwise, if the command is the
  5136. .IR ex
  5137. .BR c
  5138. command, it shall be set to the indentation of the line replaced.
  5139. .RE
  5140. .SS "autoprint, ap"
  5141. .P
  5142. [Default \fIset\fR]
  5143. .P
  5144. If
  5145. .BR autoprint
  5146. is set, the current line shall be written after each
  5147. .IR ex
  5148. command that modifies the contents of the current edit buffer, and
  5149. after each
  5150. .BR tag
  5151. command for which the tag search pattern was found or tag line number
  5152. was valid, unless:
  5153. .IP " 1." 4
  5154. The command was executed while in open or visual mode.
  5155. .IP " 2." 4
  5156. The command was executed as part of a
  5157. .BR global
  5158. or
  5159. .BR v
  5160. command or
  5161. .BR @
  5162. buffer execution.
  5163. .IP " 3." 4
  5164. The command was the form of the
  5165. .BR read
  5166. command that reads a file into the edit buffer.
  5167. .IP " 4." 4
  5168. The command was the
  5169. .BR append ,
  5170. .BR change ,
  5171. or
  5172. .BR insert
  5173. command.
  5174. .IP " 5." 4
  5175. The command was not terminated by a
  5176. <newline>.
  5177. .IP " 6." 4
  5178. The current line shall be written by a flag specified to the command;
  5179. for example,
  5180. .BR "delete #"
  5181. shall write the current line as specified for the flag modifier to the
  5182. .BR delete
  5183. command, and not as specified by the
  5184. .BR autoprint
  5185. edit option.
  5186. .SS "autowrite, aw"
  5187. .P
  5188. [Default \fIunset\fR]
  5189. .P
  5190. If
  5191. .BR autowrite
  5192. is set, and the edit buffer has been modified since it was last
  5193. completely written to any file, the contents of the edit buffer shall
  5194. be written as if the
  5195. .IR ex
  5196. .BR write
  5197. command had been specified without arguments, before each command
  5198. affected by the
  5199. .BR autowrite
  5200. edit option is executed. Appending the character
  5201. .BR '!'
  5202. to the command name of any of the
  5203. .IR ex
  5204. commands except
  5205. .BR '!'
  5206. shall prevent the write. If the write fails, it shall be an error and
  5207. the command shall not be executed.
  5208. .SS "beautify, bf"
  5209. .P
  5210. [Default \fIunset\fR]
  5211. .P
  5212. If
  5213. .BR beautify
  5214. is set, all non-printable characters, other than
  5215. <tab>,
  5216. <newline>,
  5217. and
  5218. <form-feed>
  5219. characters, shall be discarded from text read in from files.
  5220. .SS "directory, dir"
  5221. .P
  5222. [Default \fIimplementation-defined\fR]
  5223. .P
  5224. The value of this option specifies the directory in which the editor
  5225. buffer is to be placed. If this directory is not writable by the user,
  5226. the editor shall quit.
  5227. .SS "edcompatible, ed"
  5228. .P
  5229. [Default \fIunset\fR]
  5230. .P
  5231. Causes the presence of
  5232. .BR g
  5233. and
  5234. .BR c
  5235. suffixes on substitute commands to be remembered, and toggled by
  5236. repeating the suffixes.
  5237. .SS "errorbells, eb"
  5238. .P
  5239. [Default \fIunset\fR]
  5240. .P
  5241. If the editor is in
  5242. .IR ex
  5243. mode, and the terminal does not support a standout mode (such as
  5244. inverse video), and
  5245. .BR errorbells
  5246. is set, error messages shall be preceded by alerting the terminal.
  5247. .SS "exrc"
  5248. .P
  5249. [Default \fIunset\fR]
  5250. .P
  5251. If
  5252. .BR exrc
  5253. is set,
  5254. .IR ex
  5255. shall access any
  5256. .BR .exrc
  5257. file in the current directory, as described in
  5258. .IR "Initialization in ex and vi".
  5259. If
  5260. .BR exrc
  5261. is not set,
  5262. .IR ex
  5263. shall ignore any
  5264. .BR .exrc
  5265. file in the current directory during initialization, unless the current
  5266. directory is that named by the
  5267. .IR HOME
  5268. environment variable.
  5269. .SS "ignorecase, ic"
  5270. .P
  5271. [Default \fIunset\fR]
  5272. .P
  5273. If
  5274. .BR ignorecase
  5275. is set, characters that have uppercase and lowercase representations
  5276. shall have those representations considered as equivalent for purposes
  5277. of regular expression comparison.
  5278. .P
  5279. The
  5280. .BR ignorecase
  5281. edit option shall affect all remembered regular expressions; for
  5282. example, unsetting the
  5283. .BR ignorecase
  5284. edit option shall cause a subsequent
  5285. .IR vi
  5286. .BR n
  5287. command to search for the last basic regular expression in a
  5288. case-sensitive fashion.
  5289. .SS "list"
  5290. .P
  5291. [Default \fIunset\fR]
  5292. .P
  5293. If
  5294. .BR list
  5295. is set, edit buffer lines written while in
  5296. .IR ex
  5297. command mode shall be written as specified for the
  5298. .BR print
  5299. command with the
  5300. .BR l
  5301. flag specified. In open or visual mode, each edit buffer line shall be
  5302. displayed as specified for the
  5303. .IR ex
  5304. .BR print
  5305. command with the
  5306. .BR l
  5307. flag specified. In open or visual text input mode, when the cursor
  5308. does not rest on any character in the line, it shall rest on the
  5309. .BR '$'
  5310. marking the end of the line.
  5311. .SS "magic"
  5312. .P
  5313. [Default \fIset\fR]
  5314. .P
  5315. If
  5316. .BR magic
  5317. is set, modify the interpretation of characters in regular expressions
  5318. and substitution replacement strings (see
  5319. .IR "Regular Expressions in ex"
  5320. and
  5321. .IR "Replacement Strings in ex").
  5322. .SS "mesg"
  5323. .P
  5324. [Default \fIset\fR]
  5325. .P
  5326. If
  5327. .BR mesg
  5328. is set, the permission for others to use the
  5329. .BR write
  5330. or
  5331. .BR talk
  5332. commands to write to the terminal shall be turned on while in open or
  5333. visual mode. The shell-level command
  5334. .IR mesg
  5335. .BR n
  5336. shall take precedence over any setting of the
  5337. .IR ex
  5338. .BR mesg
  5339. option; that is, if
  5340. .BR "mesg y"
  5341. was issued before the editor started (or in a shell escape), such as:
  5342. .sp
  5343. .RS 4
  5344. .nf
  5345. :!mesg y
  5346. .fi
  5347. .P
  5348. .RE
  5349. .P
  5350. the
  5351. .BR mesg
  5352. option in
  5353. .IR ex
  5354. shall suppress incoming messages, but the
  5355. .BR mesg
  5356. option shall not enable incoming messages if
  5357. .BR "mesg n"
  5358. was issued.
  5359. .SS "number, nu"
  5360. .P
  5361. [Default \fIunset\fR]
  5362. .P
  5363. If
  5364. .BR number
  5365. is set, edit buffer lines written while in
  5366. .IR ex
  5367. command mode shall be written with line numbers, in the format
  5368. specified by the
  5369. .BR print
  5370. command with the
  5371. .BR #
  5372. flag specified. In
  5373. .IR ex
  5374. text input mode, each line shall be preceded by the line number it will
  5375. have in the file.
  5376. .P
  5377. In open or visual mode, each edit buffer line shall be displayed with a
  5378. preceding line number, in the format specified by the
  5379. .IR ex
  5380. .BR print
  5381. command with the
  5382. .BR #
  5383. flag specified. This line number shall not be considered part of the
  5384. line for the purposes of evaluating the current column; that is, column
  5385. position 1 shall be the first column position after the format
  5386. specified by the
  5387. .BR print
  5388. command.
  5389. .SS "paragraphs, para"
  5390. .P
  5391. [Default in the POSIX locale \fRIPLPPPQPP LIpplpipbp\fR]
  5392. .P
  5393. The
  5394. .BR paragraphs
  5395. edit option shall define additional paragraph boundaries for the open
  5396. and visual mode commands. The
  5397. .BR paragraphs
  5398. edit option can be set to a character string consisting of zero or more
  5399. character pairs. It shall be an error to set it to an odd number of
  5400. characters.
  5401. .SS "prompt"
  5402. .P
  5403. [Default \fIset\fR]
  5404. .P
  5405. If
  5406. .BR prompt
  5407. is set,
  5408. .IR ex
  5409. command mode input shall be prompted for with a
  5410. <colon>
  5411. (\c
  5412. .BR ':' );
  5413. when unset, no prompt shall be written.
  5414. .SS "readonly"
  5415. .P
  5416. [Default \fIsee text\fR]
  5417. .P
  5418. If the
  5419. .BR readonly
  5420. edit option is set, read-only mode shall be enabled (see
  5421. .IR "Write").
  5422. The
  5423. .BR readonly
  5424. edit option shall be initialized to set if either of the following
  5425. conditions are true:
  5426. .IP " *" 4
  5427. The command-line option
  5428. \-R
  5429. was specified.
  5430. .IP " *" 4
  5431. Performing actions equivalent to the
  5432. \fIaccess\fR()
  5433. function called with the following arguments indicates that the file
  5434. lacks write permission:
  5435. .RS 4
  5436. .IP " 1." 4
  5437. The current pathname is used as the
  5438. .IR path
  5439. argument.
  5440. .IP " 2." 4
  5441. The constant
  5442. .BR W_OK
  5443. is used as the
  5444. .IR amode
  5445. argument.
  5446. .RE
  5447. .P
  5448. The
  5449. .BR readonly
  5450. edit option may be initialized to set for other,
  5451. implementation-defined reasons. The
  5452. .BR readonly
  5453. edit option shall not be initialized to unset based on any special
  5454. privileges of the user or process. The
  5455. .BR readonly
  5456. edit option shall be reinitialized each time that the contents of the
  5457. edit buffer are replaced (for example, by an
  5458. .BR edit
  5459. or
  5460. .BR next
  5461. command) unless the user has explicitly set it, in which case it shall
  5462. remain set until the user explicitly unsets it. Once unset, it shall
  5463. again be reinitialized each time that the contents of the edit buffer
  5464. are replaced.
  5465. .SS "redraw"
  5466. .P
  5467. [Default \fIunset\fR]
  5468. .P
  5469. The editor simulates an intelligent terminal on a dumb terminal.
  5470. (Since this is likely to require a large amount of output to the
  5471. terminal, it is useful only at high transmission speeds.)
  5472. .SS "remap"
  5473. .P
  5474. [Default \fIset\fR]
  5475. .P
  5476. If
  5477. .BR remap
  5478. is set, map translation shall allow for maps defined in terms of other
  5479. maps; translation shall continue until a final product is obtained. If
  5480. unset, only a one-step translation shall be done.
  5481. .SS "report"
  5482. .P
  5483. [Default 5]
  5484. .P
  5485. The value of this
  5486. .BR report
  5487. edit option specifies what number of lines being added, copied,
  5488. deleted, or modified in the edit buffer will cause an informational
  5489. message to be written to the user. The following conditions shall cause
  5490. an informational message. The message shall contain the number of lines
  5491. added, copied, deleted, or modified, but is otherwise unspecified.
  5492. .IP " *" 4
  5493. An
  5494. .IR ex
  5495. or
  5496. .IR vi
  5497. editor command, other than
  5498. .BR open ,
  5499. .BR undo ,
  5500. or
  5501. .BR visual ,
  5502. that modifies at least the value of the
  5503. .BR report
  5504. edit option number of lines, and which is not part of an
  5505. .IR ex
  5506. .BR global
  5507. or
  5508. .BR v
  5509. command, or
  5510. .IR ex
  5511. or
  5512. .IR vi
  5513. buffer execution, shall cause an informational message to be written.
  5514. .IP " *" 4
  5515. An
  5516. .IR ex
  5517. .BR yank
  5518. or
  5519. .IR vi
  5520. .BR y
  5521. or
  5522. .BR Y
  5523. command, that copies at least the value of the
  5524. .BR report
  5525. edit option plus 1 number of lines, and which is not part of an
  5526. .IR ex
  5527. .BR global
  5528. or
  5529. .BR v
  5530. command, or
  5531. .IR ex
  5532. or
  5533. .IR vi
  5534. buffer execution, shall cause an informational message to be written.
  5535. .IP " *" 4
  5536. An
  5537. .IR ex
  5538. .BR global ,
  5539. .BR v ,
  5540. .BR open ,
  5541. .BR undo ,
  5542. or
  5543. .BR visual
  5544. command or
  5545. .IR ex
  5546. or
  5547. .IR vi
  5548. buffer execution, that adds or deletes a total of at least the value of
  5549. the
  5550. .BR report
  5551. edit option number of lines, and which is not part of an
  5552. .IR ex
  5553. .BR global
  5554. or
  5555. .BR v
  5556. command, or
  5557. .IR ex
  5558. or
  5559. .IR vi
  5560. buffer execution, shall cause an informational message to be written.
  5561. (For example, if 3 lines were added and 8 lines deleted during an
  5562. .IR ex
  5563. .BR visual
  5564. command, 5 would be the number compared against the
  5565. .BR report
  5566. edit option after the command completed.)
  5567. .SS "scroll, scr"
  5568. .P
  5569. [Default (number of lines in the display \-1)/2]
  5570. .P
  5571. The value of the
  5572. .BR scroll
  5573. edit option shall determine the number of lines scrolled by the
  5574. .IR ex
  5575. <control>\(hyD
  5576. and
  5577. .BR z
  5578. commands. For the
  5579. .IR vi
  5580. <control>\(hyD
  5581. and
  5582. <control>\(hyU
  5583. commands, it shall be the initial number of lines to scroll when no
  5584. previous
  5585. <control>\(hyD
  5586. or
  5587. <control>\(hyU
  5588. command has been executed.
  5589. .SS "sections"
  5590. .P
  5591. [Default in the POSIX locale \fRNHSHH HUnhsh\fR]
  5592. .P
  5593. The
  5594. .BR sections
  5595. edit option shall define additional section boundaries for the open and
  5596. visual mode commands. The
  5597. .BR sections
  5598. edit option can be set to a character string consisting of zero or more
  5599. character pairs; it shall be an error to set it to an odd number of
  5600. characters.
  5601. .SS "shell, sh"
  5602. .P
  5603. [Default from the environment variable
  5604. .IR SHELL ]
  5605. .P
  5606. The value of this option shall be a string. The default shall be taken
  5607. from the
  5608. .IR SHELL
  5609. environment variable. If the
  5610. .IR SHELL
  5611. environment variable is null or empty, the
  5612. .IR sh
  5613. (see
  5614. .IR "\fIsh\fR\^")
  5615. utility shall be the default.
  5616. .SS "shiftwidth, sw"
  5617. .P
  5618. [Default 8]
  5619. .P
  5620. The value of this option shall give the width in columns of an
  5621. indentation level used during autoindentation and by the shift commands
  5622. (\c
  5623. .BR <
  5624. and
  5625. .BR > ).
  5626. .SS "showmatch, sm"
  5627. .P
  5628. [Default \fIunset\fR]
  5629. .P
  5630. The functionality described for the
  5631. .BR showmatch
  5632. edit option need not be supported on block-mode terminals or terminals
  5633. with insufficient capabilities.
  5634. .P
  5635. If
  5636. .BR showmatch
  5637. is set, in open or visual mode, when a
  5638. .BR ')'
  5639. or
  5640. .BR '}'
  5641. is typed, if the matching
  5642. .BR '('
  5643. or
  5644. .BR '{'
  5645. is currently visible on the display, the matching
  5646. .BR '('
  5647. or
  5648. .BR '{'
  5649. shall be flagged moving the cursor to its location for an unspecified
  5650. amount of time.
  5651. .SS "showmode"
  5652. .P
  5653. [Default \fIunset\fP]
  5654. .P
  5655. If
  5656. .BR showmode
  5657. is set, in open or visual mode, the current mode that the editor is in
  5658. shall be displayed on the last line of the display. Command mode and
  5659. text input mode shall be differentiated; other unspecified modes and
  5660. implementation-defined information may be displayed.
  5661. .SS "slowopen"
  5662. .P
  5663. [Default \fIunset\fR]
  5664. .P
  5665. If
  5666. .BR slowopen
  5667. is set during open and visual text input modes, the editor shall not
  5668. update portions of the display other than those display line columns
  5669. that display the characters entered by the user (see
  5670. .IR "Input Mode Commands in vi").
  5671. .SS "tabstop, ts"
  5672. .P
  5673. [Default 8]
  5674. .P
  5675. The value of this edit option shall specify the column boundary used by
  5676. a
  5677. <tab>
  5678. in the display (see
  5679. .IR "autoprint" ", " "ap"
  5680. and
  5681. .IR "Input Mode Commands in vi").
  5682. .SS "taglength, tl"
  5683. .P
  5684. [Default zero]
  5685. .P
  5686. The value of this edit option shall specify the maximum number of
  5687. characters that are considered significant in the user-specified tag
  5688. name and in the tag name from the tags file. If the value is zero, all
  5689. characters in both tag names shall be significant.
  5690. .SS "tags"
  5691. .P
  5692. [Default \fIsee text\fP]
  5693. .P
  5694. The value of this edit option shall be a string of
  5695. <blank>-delimited
  5696. pathnames of files used by the
  5697. .BR tag
  5698. command. The default value is unspecified.
  5699. .SS "term"
  5700. .P
  5701. [Default from the environment variable
  5702. .IR TERM ]
  5703. .P
  5704. The value of this edit option shall be a string. The default shall be
  5705. taken from the
  5706. .IR TERM
  5707. variable in the environment. If the
  5708. .IR TERM
  5709. environment variable is empty or null, the default is unspecified. The
  5710. editor shall use the value of this edit option to determine the type of
  5711. the display device.
  5712. .P
  5713. The results are unspecified if the user changes the value of the term
  5714. edit option after editor initialization.
  5715. .SS "terse"
  5716. .P
  5717. [Default \fIunset\fR]
  5718. .P
  5719. If
  5720. .BR terse
  5721. is set, error messages may be less verbose. However, except for this
  5722. caveat, error messages are unspecified. Furthermore, not all error
  5723. messages need change for different settings of this option.
  5724. .SS "warn"
  5725. .P
  5726. [Default \fIset\fR]
  5727. .P
  5728. If
  5729. .BR warn
  5730. is set, and the contents of the edit buffer have been modified since
  5731. they were last completely written, the editor shall write a warning
  5732. message before certain
  5733. .BR !
  5734. commands (see
  5735. .IR "Escape").
  5736. .SS "window"
  5737. .P
  5738. [Default \fIsee text\fR]
  5739. .P
  5740. A value used in open and visual mode, by the
  5741. <control>\(hyB
  5742. and
  5743. <control>\(hyF
  5744. commands, and, in visual mode, to specify the number of lines displayed
  5745. when the screen is repainted.
  5746. .P
  5747. If the
  5748. .BR \-w
  5749. command-line option is not specified, the default value shall be set to
  5750. the value of the
  5751. .IR LINES
  5752. environment variable. If the
  5753. .IR LINES
  5754. environment variable is empty or null, the default shall be the number
  5755. of lines in the display minus 1.
  5756. .P
  5757. Setting the
  5758. .BR window
  5759. edit option to zero or to a value greater than the number of lines in
  5760. the display minus 1 (either explicitly or based on the
  5761. .BR \-w
  5762. option or the
  5763. .IR LINES
  5764. environment variable) shall cause the
  5765. .BR window
  5766. edit option to be set to the number of lines in the display minus 1.
  5767. .P
  5768. The baud rate of the terminal line may change the default in an
  5769. implementation-defined manner.
  5770. .SS "wrapmargin, wm"
  5771. .P
  5772. [Default 0]
  5773. .P
  5774. If the value of this edit option is zero, it shall have no effect.
  5775. .P
  5776. If not in the POSIX locale, the effect of this edit option is
  5777. implementation-defined.
  5778. .P
  5779. Otherwise, it shall specify a number of columns from the ending margin
  5780. of the terminal.
  5781. .P
  5782. During open and visual text input modes, for each character for which
  5783. any part of the character is displayed in a column that is less than
  5784. .BR wrapmargin
  5785. columns from the ending margin of the display line, the editor shall
  5786. behave as follows:
  5787. .IP " 1." 4
  5788. If the character triggering this event is a
  5789. <blank>,
  5790. it, and all immediately preceding
  5791. <blank>
  5792. characters on the current line entered during the execution of the
  5793. current text input command, shall be discarded, and the editor shall
  5794. behave as if the user had entered a single
  5795. <newline>
  5796. instead. In addition, if the next user-entered character is a
  5797. <space>,
  5798. it shall be discarded as well.
  5799. .IP " 2." 4
  5800. Otherwise, if there are one or more
  5801. <blank>
  5802. characters on the current line immediately preceding the last group of
  5803. inserted non-\c
  5804. <blank>
  5805. characters which was entered during the execution of the current text
  5806. input command, the
  5807. <blank>
  5808. characters shall be replaced as if the user had entered a single
  5809. <newline>
  5810. instead.
  5811. .P
  5812. If the
  5813. .BR autoindent
  5814. edit option is set, and the events described in 1. or 2. are performed,
  5815. any
  5816. <blank>
  5817. characters at or after the cursor in the current line shall be discarded.
  5818. .P
  5819. The ending margin shall be determined by the system or overridden by
  5820. the user, as described for
  5821. .IR COLUMNS
  5822. in the ENVIRONMENT VARIABLES section and the Base Definitions volume of POSIX.1\(hy2017,
  5823. .IR "Chapter 8" ", " "Environment Variables".
  5824. .SS "wrapscan, ws"
  5825. .P
  5826. [Default \fIset\fR]
  5827. .P
  5828. If
  5829. .BR wrapscan
  5830. is set, searches (the
  5831. .IR ex
  5832. .BR /
  5833. or
  5834. .BR ?
  5835. addresses, or open and visual mode
  5836. .BR / ,
  5837. .BR ? ,
  5838. .BR N ,
  5839. and
  5840. .BR n
  5841. commands) shall wrap around the beginning or end of the edit buffer;
  5842. when unset, searches shall stop at the beginning or end of the edit
  5843. buffer.
  5844. .SS "writeany, wa"
  5845. .P
  5846. [Default \fIunset\fR]
  5847. .P
  5848. If
  5849. .BR writeany
  5850. is set, some of the checks performed when executing the
  5851. .IR ex
  5852. .BR write
  5853. commands shall be inhibited, as described in editor option
  5854. .BR autowrite .
  5855. .SH "EXIT STATUS"
  5856. The following exit values shall be returned:
  5857. .IP "\00" 6
  5858. Successful completion.
  5859. .IP >0 6
  5860. An error occurred.
  5861. .SH "CONSEQUENCES OF ERRORS"
  5862. When any error is encountered and the standard input is not a terminal
  5863. device file,
  5864. .IR ex
  5865. shall not write the file or return to command or text input mode, and
  5866. shall terminate with a non-zero exit status.
  5867. .P
  5868. Otherwise, when an unrecoverable error is encountered, it shall be
  5869. equivalent to a SIGHUP asynchronous event.
  5870. .P
  5871. Otherwise, when an error is encountered, the editor shall behave as
  5872. specified in
  5873. .IR "Command Line Parsing in ex".
  5874. .LP
  5875. .IR "The following sections are informative."
  5876. .SH "APPLICATION USAGE"
  5877. If a SIGSEGV signal is received while
  5878. .IR ex
  5879. is saving a file, the file might not be successfully saved.
  5880. .P
  5881. The
  5882. .BR next
  5883. command can accept more than one file, so usage such as:
  5884. .sp
  5885. .RS 4
  5886. .nf
  5887. next `ls [abc]*`
  5888. .fi
  5889. .P
  5890. .RE
  5891. .P
  5892. is valid; it would not be valid for the
  5893. .BR edit
  5894. or
  5895. .BR read
  5896. commands, for example, because they expect only one file and
  5897. unspecified results occur.
  5898. .SH EXAMPLES
  5899. None.
  5900. .SH RATIONALE
  5901. The
  5902. .IR ex /\c
  5903. .IR vi
  5904. specification is based on the historical practice found in the 4 BSD and
  5905. System V implementations of
  5906. .IR ex
  5907. and
  5908. .IR vi .
  5909. .P
  5910. A
  5911. .IR "restricted editor"
  5912. (both the historical
  5913. .IR red
  5914. utility and modifications to
  5915. .IR ex )
  5916. were considered and rejected for inclusion. Neither option provided the
  5917. level of security that users might expect.
  5918. .P
  5919. It is recognized that
  5920. .IR ex
  5921. visual mode and related features would be difficult, if not impossible,
  5922. to implement satisfactorily on a block-mode terminal, or a terminal
  5923. without any form of cursor addressing; thus, it is not a mandatory
  5924. requirement that such features should work on all terminals. It is the
  5925. intention, however, that an
  5926. .IR ex
  5927. implementation should provide the full set of capabilities on all
  5928. terminals capable of supporting them.
  5929. .SS "Options"
  5930. .P
  5931. The
  5932. .BR \-c
  5933. replacement for
  5934. .BR + \c
  5935. .IR command
  5936. was inspired by the
  5937. .BR \-e
  5938. option of
  5939. .IR sed .
  5940. Historically, all such commands (see
  5941. .BR edit
  5942. and
  5943. .BR next
  5944. as well) were executed from the last line of the edit buffer. This
  5945. meant, for example, that
  5946. .BR \(dq+/pattern\(dq
  5947. would fail unless the
  5948. .BR wrapscan
  5949. option was set. POSIX.1\(hy2008 requires conformance to historical practice. The
  5950. .BR \(pl \c
  5951. .IR command
  5952. option is no longer specified by POSIX.1\(hy2008 but may be present in
  5953. some implementations. Historically, some implementations restricted the
  5954. .IR ex
  5955. commands that could be listed as part of the command line arguments.
  5956. For consistency, POSIX.1\(hy2008 does not permit these restrictions.
  5957. .P
  5958. In historical implementations of the editor, the
  5959. .BR \-R
  5960. option (and the
  5961. .BR readonly
  5962. edit option) only prevented overwriting of files; appending to files
  5963. was still permitted, mapping loosely into the
  5964. .IR csh
  5965. .BR noclobber
  5966. variable. Some implementations, however, have not followed this
  5967. semantic, and
  5968. .BR readonly
  5969. does not permit appending either. POSIX.1\(hy2008 follows the latter practice,
  5970. believing that it is a more obvious and intuitive meaning of
  5971. .BR readonly .
  5972. .P
  5973. The
  5974. .BR \-s
  5975. option suppresses all interactive user feedback and is useful for
  5976. editing scripts in batch jobs. The list of specific effects is
  5977. historical practice. The terminal type ``incapable of supporting open
  5978. and visual modes'' has historically been named ``dumb''.
  5979. .P
  5980. The
  5981. .BR \-t
  5982. option was required because the
  5983. .IR ctags
  5984. utility appears in POSIX.1\(hy2008 and the option is available in all historical
  5985. implementations of
  5986. .IR ex .
  5987. .P
  5988. Historically, the
  5989. .IR ex
  5990. and
  5991. .IR vi
  5992. utilities accepted a
  5993. .BR \-x
  5994. option, which did encryption based on the algorithm found in the
  5995. historical
  5996. .IR crypt
  5997. utility. The
  5998. .BR \-x
  5999. option for encryption, and the associated
  6000. .IR crypt
  6001. utility, were omitted because the algorithm used was not specifiable
  6002. and the export control laws of some nations make it difficult to export
  6003. cryptographic technology. In addition, it did not historically provide
  6004. the level of security that users might expect.
  6005. .SS "Standard Input"
  6006. .P
  6007. An end-of-file condition is not equivalent to an end-of-file character.
  6008. A common end-of-file character,
  6009. <control>\(hyD,
  6010. is historically an
  6011. .IR ex
  6012. command.
  6013. .P
  6014. There was no maximum line length in historical implementations of
  6015. .IR ex .
  6016. Specifically, as it was parsed in chunks, the addresses had a different
  6017. maximum length than the filenames. Further, the maximum line buffer
  6018. size was declared as BUFSIZ, which was different lengths on different
  6019. systems. This version selected the value of
  6020. {LINE_MAX}
  6021. to impose a reasonable restriction on portable usage of
  6022. .IR ex
  6023. and to aid test suite writers in their development of realistic tests
  6024. that exercise this limit.
  6025. .SS "Input Files"
  6026. .P
  6027. It was an explicit decision by the standard developers that a
  6028. <newline>
  6029. be added to any file lacking one. It was believed that this feature of
  6030. .IR ex
  6031. and
  6032. .IR vi
  6033. was relied on by users in order to make text files lacking a trailing
  6034. <newline>
  6035. more portable. It is recognized that this will require a user-specified
  6036. option or extension for implementations that permit
  6037. .IR ex
  6038. and
  6039. .IR vi
  6040. to edit files of type other than text if such files are not otherwise
  6041. identified by the system. It was agreed that the ability to edit files
  6042. of arbitrary type can be useful, but it was not considered necessary to
  6043. mandate that an
  6044. .IR ex
  6045. or
  6046. .IR vi
  6047. implementation be required to handle files other than text files.
  6048. .P
  6049. The paragraph in the INPUT FILES section, ``By default, .\|.\|.'', is
  6050. intended to close a long-standing security problem in
  6051. .IR ex
  6052. and
  6053. .IR vi ;
  6054. that of the ``modeline'' or ``modelines'' edit option. This feature
  6055. allows any line in the first or last five lines of the file containing
  6056. the strings
  6057. .BR \(dqex:\(dq
  6058. or
  6059. .BR \(dqvi:\(dq
  6060. (and, apparently,
  6061. .BR \(dqei:\(dq
  6062. or
  6063. .BR \(dqvx:\(dq )
  6064. to be a line containing editor commands, and
  6065. .IR ex
  6066. interprets all the text up to the next
  6067. .BR ':'
  6068. or
  6069. <newline>
  6070. as a command. Consider the consequences, for example, of an
  6071. unsuspecting user using
  6072. .IR ex
  6073. or
  6074. .IR vi
  6075. as the editor when replying to a mail message in which a line such as:
  6076. .sp
  6077. .RS 4
  6078. .nf
  6079. ex:! rm -rf :
  6080. .fi
  6081. .P
  6082. .RE
  6083. .P
  6084. appeared in the signature lines. The standard developers believed
  6085. strongly that an editor should not by default interpret any lines of a
  6086. file. Vendors are strongly urged to delete this feature from their
  6087. implementations of
  6088. .IR ex
  6089. and
  6090. .IR vi .
  6091. .SS "Asynchronous Events"
  6092. .P
  6093. The intention of the phrase ``complete write'' is that the entire edit
  6094. buffer be written to stable storage. The note regarding temporary files
  6095. is intended for implementations that use temporary files to back edit
  6096. buffers unnamed by the user.
  6097. .P
  6098. Historically, SIGQUIT was ignored by
  6099. .IR ex ,
  6100. but was the equivalent of the
  6101. .BR Q
  6102. command in visual mode; that is, it exited visual mode and entered
  6103. .IR ex
  6104. mode. POSIX.1\(hy2008 permits, but does not require, this behavior. Historically,
  6105. SIGINT was often used by
  6106. .IR vi
  6107. users to terminate text input mode (\c
  6108. <control>\(hyC
  6109. is often easier to enter than
  6110. <ESC>).
  6111. Some implementations of
  6112. .IR vi
  6113. alerted the terminal on this event, and some did not. POSIX.1\(hy2008 requires
  6114. that SIGINT behave identically to
  6115. <ESC>,
  6116. and that the terminal not be alerted.
  6117. .P
  6118. Historically, suspending the
  6119. .IR ex
  6120. editor during text input mode was similar to SIGINT, as completed lines
  6121. were retained, but any partial line discarded, and the editor returned
  6122. to command mode. POSIX.1\(hy2008 is silent on this issue; implementations are
  6123. encouraged to follow historical practice, where possible.
  6124. .P
  6125. Historically, the
  6126. .IR vi
  6127. editor did not treat SIGTSTP as an asynchronous event, and it was
  6128. therefore impossible to suspend the editor in visual text input mode.
  6129. There are two major reasons for this. The first is that SIGTSTP is a
  6130. broadcast signal on UNIX systems, and the chain of events where the
  6131. shell
  6132. .IR exec s
  6133. an application that then
  6134. .IR exec s
  6135. .IR vi
  6136. usually caused confusion for the terminal state if SIGTSTP was delivered
  6137. to the process group in the default manner. The second was that most
  6138. implementations of the UNIX
  6139. .IR curses
  6140. package did not handle SIGTSTP safely, and the receipt of SIGTSTP at
  6141. the wrong time would cause them to crash. POSIX.1\(hy2008 is silent on this issue;
  6142. implementations are encouraged to treat suspension as an asynchronous
  6143. event if possible.
  6144. .P
  6145. Historically, modifications to the edit buffer made before SIGINT
  6146. interrupted an operation were retained; that is, anywhere from zero to
  6147. all of the lines to be modified might have been modified by the time
  6148. the SIGINT arrived. These changes were not discarded by the arrival of
  6149. SIGINT. POSIX.1\(hy2008 permits this behavior, noting that the
  6150. .BR undo
  6151. command is required to be able to undo these partially completed
  6152. commands.
  6153. .P
  6154. The action taken for signals other than SIGINT, SIGCONT, SIGHUP, and
  6155. SIGTERM is unspecified because some implementations attempt to save the
  6156. edit buffer in a useful state when other signals are received.
  6157. .SS "Standard Error"
  6158. .P
  6159. For
  6160. .IR ex /\c
  6161. .IR vi ,
  6162. diagnostic messages are those messages reported as a result of a failed
  6163. attempt to invoke
  6164. .IR ex
  6165. or
  6166. .IR vi ,
  6167. such as invalid options or insufficient resources, or an abnormal
  6168. termination condition. Diagnostic messages should not be confused with
  6169. the error messages generated by inappropriate or illegal user
  6170. commands.
  6171. .SS "Initialization in ex and vi"
  6172. .P
  6173. If an
  6174. .IR ex
  6175. command (other than
  6176. .BR cd ,
  6177. .BR chdir ,
  6178. or
  6179. .BR source )
  6180. has a filename argument, one or both of the alternate and current
  6181. pathnames will be set. Informally, they are set as follows:
  6182. .IP " 1." 4
  6183. If the
  6184. .IR ex
  6185. command is one that replaces the contents of the edit buffer, and it
  6186. succeeds, the current pathname will be set to the filename argument
  6187. (the first filename argument in the case of the
  6188. .BR next
  6189. command) and the alternate pathname will be set to the previous
  6190. current pathname, if there was one.
  6191. .IP " 2." 4
  6192. In the case of the file read/write forms of the
  6193. .BR read
  6194. and
  6195. .BR write
  6196. commands, if there is no current pathname, the current pathname will
  6197. be set to the filename argument.
  6198. .IP " 3." 4
  6199. Otherwise, the alternate pathname will be set to the filename
  6200. argument.
  6201. .P
  6202. For example,
  6203. .BR ":edit foo"
  6204. and
  6205. .BR ":recover foo" ,
  6206. when successful, set the current pathname, and, if there was a
  6207. previous current pathname, the alternate pathname. The commands
  6208. .BR :write ,
  6209. .BR !command ,
  6210. and
  6211. .BR :edit
  6212. set neither the current or alternate pathnames. If the
  6213. .BR ":edit foo"
  6214. command were to fail for some reason, the alternate pathname would be
  6215. set. The
  6216. .BR read
  6217. and
  6218. .BR write
  6219. commands set the alternate pathname to their
  6220. .IR file
  6221. argument, unless the current pathname is not set, in which case they
  6222. set the current pathname to their
  6223. .IR file
  6224. arguments. The alternate pathname was not historically set by the
  6225. .BR :source
  6226. command. POSIX.1\(hy2008 requires conformance to historical practice.
  6227. Implementations adding commands that take filenames as arguments are
  6228. encouraged to set the alternate pathname as described here.
  6229. .P
  6230. Historically,
  6231. .IR ex
  6232. and
  6233. .IR vi
  6234. read the
  6235. .BR .exrc
  6236. file in the
  6237. .IR $HOME
  6238. directory twice, if the editor was executed in the
  6239. .IR $HOME
  6240. directory. POSIX.1\(hy2008 prohibits this behavior.
  6241. .P
  6242. Historically, the 4 BSD
  6243. .IR ex
  6244. and
  6245. .IR vi
  6246. read the
  6247. .IR $HOME
  6248. and local
  6249. .BR .exrc
  6250. files if they were owned by the real ID of the user, or the
  6251. .BR sourceany
  6252. option was set, regardless of other considerations. This was a security
  6253. problem because it is possible to put normal UNIX system commands
  6254. inside a
  6255. .BR .exrc
  6256. file. POSIX.1\(hy2008 does not specify the
  6257. .BR sourceany
  6258. option, and historical implementations are encouraged to delete it.
  6259. .P
  6260. The
  6261. .BR .exrc
  6262. files must be owned by the real ID of the user, and not writable by
  6263. anyone other than the owner. The appropriate privileges exception is
  6264. intended to permit users to acquire special privileges, but continue to
  6265. use the
  6266. .BR .exrc
  6267. files in their home directories.
  6268. .P
  6269. System V Release 3.2 and later
  6270. .IR vi
  6271. implementations added the option
  6272. .BR [no]exrc .
  6273. The behavior is that local
  6274. .BR .exrc
  6275. files are read-only if the
  6276. .BR exrc
  6277. option is set. The default for the
  6278. .BR exrc
  6279. option was off, so by default, local
  6280. .BR .exrc
  6281. files were not read. The problem this was intended to solve was that
  6282. System V permitted users to give away files, so there is no possible
  6283. ownership or writeability test to ensure that the file is safe. This is
  6284. still a security problem on systems where users can give away files,
  6285. but there is nothing additional that POSIX.1\(hy2008 can do. The
  6286. implementation-defined exception is intended to permit groups to have
  6287. local
  6288. .BR .exrc
  6289. files that are shared by users, by creating pseudo-users to own the
  6290. shared files.
  6291. .P
  6292. POSIX.1\(hy2008 does not mention system-wide
  6293. .IR ex
  6294. and
  6295. .IR vi
  6296. start-up files. While they exist in several implementations of
  6297. .IR ex
  6298. and
  6299. .IR vi ,
  6300. they are not present in any implementations considered historical
  6301. practice by POSIX.1\(hy2008. Implementations that have such files should use them
  6302. only if they are owned by the real user ID or an appropriate user (for
  6303. example, root on UNIX systems) and if they are not writable by any
  6304. user other than their owner. System-wide start-up files should be read
  6305. before the
  6306. .IR EXINIT
  6307. variable,
  6308. .BR $HOME/.exrc ,
  6309. or local
  6310. .BR .exrc
  6311. files are evaluated.
  6312. .P
  6313. Historically, any
  6314. .IR ex
  6315. command could be entered in the
  6316. .IR EXINIT
  6317. variable or the
  6318. .BR .exrc
  6319. file, although ones requiring that the edit buffer already contain
  6320. lines of text generally caused historical implementations of the editor
  6321. to drop
  6322. .BR core .
  6323. POSIX.1\(hy2008 requires that any
  6324. .IR ex
  6325. command be permitted in the
  6326. .IR EXINIT
  6327. variable and
  6328. .BR .exrc
  6329. files, for simplicity of specification and consistency, although many
  6330. of them will obviously fail under many circumstances.
  6331. .P
  6332. The initialization of the contents of the edit buffer uses the phrase
  6333. ``the effect shall be'' with regard to various
  6334. .IR ex
  6335. commands. The intent of this phrase is that edit buffer contents loaded
  6336. during the initialization phase not be lost; that is, loading the edit
  6337. buffer should fail if the
  6338. .BR .exrc
  6339. file read in the contents of a file and did not subsequently write the
  6340. edit buffer. An additional intent of this phrase is to specify that the
  6341. initial current line and column is set as specified for the individual
  6342. .IR ex
  6343. commands.
  6344. .P
  6345. Historically, the
  6346. .BR \-t
  6347. option behaved as if the tag search were a
  6348. .BR + \c
  6349. .IR command ;
  6350. that is, it was executed from the last line of the file specified by
  6351. the tag. This resulted in the search failing if the pattern was a
  6352. forward search pattern and the
  6353. .BR wrapscan
  6354. edit option was not set. POSIX.1\(hy2008 does not permit this behavior, requiring
  6355. that the search for the tag pattern be performed on the entire file,
  6356. and, if not found, that the current line be set to a more reasonable
  6357. location in the file.
  6358. .P
  6359. Historically, the empty edit buffer presented for editing when a file
  6360. was not specified by the user was unnamed. This is permitted by POSIX.1\(hy2008;
  6361. however, implementations are encouraged to provide users a temporary
  6362. filename for this buffer because it permits them the use of
  6363. .IR ex
  6364. commands that use the current pathname during temporary edit
  6365. sessions.
  6366. .P
  6367. Historically, the file specified using the
  6368. .BR \-t
  6369. option was not part of the current argument list. This practice is
  6370. permitted by POSIX.1\(hy2008; however, implementations are encouraged to include
  6371. its name in the current argument list for consistency.
  6372. .P
  6373. Historically, the
  6374. .BR \-c
  6375. command was generally not executed until a file that already exists was
  6376. edited. POSIX.1\(hy2008 requires conformance to this historical practice.
  6377. Commands that could cause the
  6378. .BR \-c
  6379. command to be executed include the
  6380. .IR ex
  6381. commands
  6382. .BR edit ,
  6383. .BR next ,
  6384. .BR recover ,
  6385. .BR rewind ,
  6386. and
  6387. .BR tag ,
  6388. and the
  6389. .IR vi
  6390. commands
  6391. <control>\(hy^
  6392. and
  6393. <control>\(hy].
  6394. Historically, reading a file into an edit buffer did not cause the
  6395. .BR \-c
  6396. command to be executed (even though it might set the current pathname)
  6397. with the exception that it did cause the
  6398. .BR \-c
  6399. command to be executed if: the editor was in
  6400. .IR ex
  6401. mode, the edit buffer had no current pathname, the edit buffer was
  6402. empty, and no read commands had yet been attempted. For consistency and
  6403. simplicity of specification, POSIX.1\(hy2008 does not permit this behavior.
  6404. .P
  6405. Historically, the
  6406. .BR \-r
  6407. option was the same as a normal edit session if there was no recovery
  6408. information available for the file. This allowed users to enter:
  6409. .sp
  6410. .RS 4
  6411. .nf
  6412. vi -r *.c
  6413. .fi
  6414. .P
  6415. .RE
  6416. .P
  6417. and recover whatever files were recoverable. In some implementations,
  6418. recovery was attempted only on the first file named, and the file was
  6419. not entered into the argument list; in others, recovery was attempted
  6420. for each file named. In addition, some historical implementations
  6421. ignored
  6422. .BR \-r
  6423. if
  6424. .BR \-t
  6425. was specified or did not support command line
  6426. .IR file
  6427. arguments with the
  6428. .BR \-t
  6429. option. For consistency and simplicity of specification, POSIX.1\(hy2008
  6430. disallows these special cases, and requires that recovery be attempted
  6431. the first time each file is edited.
  6432. .P
  6433. Historically,
  6434. .IR vi
  6435. initialized the
  6436. .BR `
  6437. and
  6438. .BR \(aq
  6439. marks, but
  6440. .IR ex
  6441. did not. This meant that if the first command in
  6442. .IR ex
  6443. mode was
  6444. .BR visual
  6445. or if an
  6446. .IR ex
  6447. command was executed first (for example,
  6448. .IR vi
  6449. +10
  6450. .IR file ),
  6451. .IR vi
  6452. was entered without the marks being initialized. Because the standard
  6453. developers believed the marks to be generally useful, and for
  6454. consistency and simplicity of specification, POSIX.1\(hy2008 requires that they
  6455. always be initialized if in open or visual mode, or if in
  6456. .IR ex
  6457. mode and the edit buffer is not empty. Not initializing it in
  6458. .IR ex
  6459. mode if the edit buffer is empty is historical practice; however, it
  6460. has always been possible to set (and use) marks in empty edit buffers
  6461. in open and visual mode edit sessions.
  6462. .SS "Addressing"
  6463. .P
  6464. Historically,
  6465. .IR ex
  6466. and
  6467. .IR vi
  6468. accepted the additional addressing forms
  6469. .BR '\e/'
  6470. and
  6471. .BR '\e?' .
  6472. They were equivalent to
  6473. .BR \(dq//\(dq
  6474. and
  6475. .BR \(dq??\(dq ,
  6476. respectively. They are not required by POSIX.1\(hy2008, mostly because nobody can
  6477. remember whether they ever did anything different historically.
  6478. .P
  6479. Historically,
  6480. .IR ex
  6481. and
  6482. .IR vi
  6483. permitted an address of zero for several commands, and permitted the
  6484. .BR %
  6485. address in empty files for others. For consistency, POSIX.1\(hy2008 requires
  6486. support for the former in the few commands where it makes sense, and
  6487. disallows it otherwise. In addition, because POSIX.1\(hy2008 requires that
  6488. .BR %
  6489. be logically equivalent to
  6490. .BR \(dq1,$\(dq ,
  6491. it is also supported where it makes sense and disallowed otherwise.
  6492. .P
  6493. Historically, the
  6494. .BR %
  6495. address could not be followed by further addresses. For consistency and
  6496. simplicity of specification, POSIX.1\(hy2008 requires that additional addresses
  6497. be supported.
  6498. .P
  6499. All of the following are valid
  6500. .IR addresses :
  6501. .IP "\fR+++\fP" 10
  6502. Three lines after the current line.
  6503. .IP "\fR/\fIre\fR/\-\fR" 10
  6504. One line before the next occurrence of
  6505. .IR re .
  6506. .IP "\fR\-2\fR" 10
  6507. Two lines before the current line.
  6508. .IP "\fR3\0\-\|\-\|\-\|\-\02\fR" 10
  6509. Line one (note intermediate negative address).
  6510. .IP "\fR1\02\03\fR" 10
  6511. Line six.
  6512. .P
  6513. Any number of addresses can be provided to commands taking addresses;
  6514. for example,
  6515. .BR \(dq1,2,3,4,5p\(dq
  6516. prints lines 4 and 5, because two is the greatest valid number of
  6517. addresses accepted by the
  6518. .BR print
  6519. command. This, in combination with the
  6520. <semicolon>
  6521. delimiter, permits users to create commands based on ordered patterns
  6522. in the file. For example, the command
  6523. .BR "3;/foo/;+2print"
  6524. will display the first line after line 3 that contains the pattern
  6525. .IR foo ,
  6526. plus the next two lines. Note that the address
  6527. .BR "3;"
  6528. must be evaluated before being discarded because the search origin for
  6529. the
  6530. .BR /foo/
  6531. command depends on this.
  6532. .P
  6533. Historically, values could be added to addresses by including them
  6534. after one or more
  6535. <blank>
  6536. characters; for example,
  6537. .BR "3\0\-\05p"
  6538. wrote the seventh line of the file, and
  6539. .BR "/foo/\05"
  6540. was the same as
  6541. .BR "/foo/+5" .
  6542. However, only absolute values could be added; for example,
  6543. .BR "5\0/foo/"
  6544. was an error. POSIX.1\(hy2008 requires conformance to historical practice.
  6545. Address offsets are separately specified from addresses because they
  6546. could historically be provided to visual mode search commands.
  6547. .P
  6548. Historically, any missing addresses defaulted to the current line. This
  6549. was true for leading and trailing
  6550. <comma>-delimited
  6551. addresses, and for trailing
  6552. <semicolon>-delimited
  6553. addresses. For consistency, POSIX.1\(hy2008 requires it for leading
  6554. <semicolon>
  6555. addresses as well.
  6556. .P
  6557. Historically,
  6558. .IR ex
  6559. and
  6560. .IR vi
  6561. accepted the
  6562. .BR '\(ha'
  6563. character as both an address and as a flag offset for commands. In both
  6564. cases it was identical to the
  6565. .BR '\-'
  6566. character. POSIX.1\(hy2008 does not require or prohibit this behavior.
  6567. .P
  6568. Historically, the enhancements to basic regular expressions could be
  6569. used in addressing; for example,
  6570. .BR '\(ti' ,
  6571. .BR '\e<' ,
  6572. and
  6573. .BR '\e>' .
  6574. POSIX.1\(hy2008 requires conformance to historical practice; that is, that
  6575. regular expression usage be consistent, and that regular expression
  6576. enhancements be supported wherever regular expressions are used.
  6577. .SS "Command Line Parsing in ex"
  6578. .P
  6579. Historical
  6580. .IR ex
  6581. command parsing was even more complex than that described here. POSIX.1\(hy2008
  6582. requires the subset of the command parsing that the standard developers
  6583. believed was documented and that users could reasonably be expected to
  6584. use in a portable fashion, and that was historically consistent between
  6585. implementations. (The discarded functionality is obscure, at best.)
  6586. Historical implementations will require changes in order to comply with
  6587. POSIX.1\(hy2008; however, users are not expected to notice any of these changes.
  6588. Most of the complexity in
  6589. .IR ex
  6590. parsing is to handle three special termination cases:
  6591. .IP " 1." 4
  6592. The
  6593. .BR ! ,
  6594. .BR global ,
  6595. .BR v ,
  6596. and the filter versions of the
  6597. .BR read
  6598. and
  6599. .BR write
  6600. commands are delimited by
  6601. <newline>
  6602. characters (they can contain
  6603. <vertical-line>
  6604. characters that are usually shell pipes).
  6605. .IP " 2." 4
  6606. The
  6607. .BR ex ,
  6608. .BR edit ,
  6609. .BR next ,
  6610. and
  6611. .BR visual
  6612. in open and visual mode commands all take
  6613. .IR ex
  6614. commands, optionally containing
  6615. <vertical-line>
  6616. characters, as their first arguments.
  6617. .IP " 3." 4
  6618. The
  6619. .BR s
  6620. command takes a regular expression as its first argument, and uses the
  6621. delimiting characters to delimit the command.
  6622. .P
  6623. Historically,
  6624. <vertical-line>
  6625. characters in the
  6626. .BR + \c
  6627. .IR command
  6628. argument of the
  6629. .BR ex ,
  6630. .BR edit ,
  6631. .BR next ,
  6632. .BR vi ,
  6633. and
  6634. .BR visual
  6635. commands, and in the
  6636. .IR pattern
  6637. and
  6638. .IR replacement
  6639. parts of the
  6640. .BR s
  6641. command, did not delimit the command, and in the filter cases for
  6642. .BR read
  6643. and
  6644. .BR write ,
  6645. and the
  6646. .BR ! ,
  6647. .BR global ,
  6648. and
  6649. .BR v
  6650. commands, they did not delimit the command at all. For example, the
  6651. following commands are all valid:
  6652. .sp
  6653. .RS 4
  6654. .nf
  6655. \fB:\fRedit +25 | s/abc/ABC/ file.c
  6656. \fB:\fRs/ | /PIPE/
  6657. \fB:\fRread !spell % | columnate
  6658. \fB:\fRglobal/pattern/p | l
  6659. \fB:\fRs/a/b/ | s/c/d | set
  6660. .fi
  6661. .P
  6662. .RE
  6663. .P
  6664. Historically, empty or
  6665. <blank>
  6666. filled lines in
  6667. .BR .exrc
  6668. files and
  6669. .BR source d
  6670. files (as well as
  6671. .IR EXINIT
  6672. variables and
  6673. .IR ex
  6674. command scripts) were treated as default commands; that is,
  6675. .BR print
  6676. commands. POSIX.1\(hy2008 specifically requires that they be ignored when
  6677. encountered in
  6678. .BR .exrc
  6679. and
  6680. .BR source d
  6681. files to eliminate a common source of new user error.
  6682. .P
  6683. Historically,
  6684. .IR ex
  6685. commands with multiple adjacent (or
  6686. <blank>-separated)
  6687. vertical lines were handled oddly when executed from
  6688. .IR ex
  6689. mode. For example, the command
  6690. .BR "|||"
  6691. <carriage-return>,
  6692. when the cursor was on line 1, displayed lines 2, 3, and 5 of the file.
  6693. In addition, the command
  6694. .BR |
  6695. would only display the line after the next line, instead of the next
  6696. two lines. The former worked more logically when executed from
  6697. .IR vi
  6698. mode, and displayed lines 2, 3, and 4. POSIX.1\(hy2008 requires the
  6699. .IR vi
  6700. behavior; that is, a single default command and line number increment
  6701. for each command separator, and trailing
  6702. <newline>
  6703. characters after
  6704. <vertical-line>
  6705. separators are discarded.
  6706. .P
  6707. Historically,
  6708. .IR ex
  6709. permitted a single extra
  6710. <colon>
  6711. as a leading command character; for example,
  6712. .BR ":g/pattern/:p"
  6713. was a valid command. POSIX.1\(hy2008 generalizes this to require that any number
  6714. of leading
  6715. <colon>
  6716. characters be stripped.
  6717. .P
  6718. Historically, any prefix of the
  6719. .BR delete
  6720. command could be followed without intervening
  6721. <blank>
  6722. characters by a flag character because in the command
  6723. .BR "d\0p" ,
  6724. .IR p
  6725. is interpreted as the buffer
  6726. .IR p .
  6727. POSIX.1\(hy2008 requires conformance to historical practice.
  6728. .P
  6729. Historically, the
  6730. .BR k
  6731. command could be followed by the mark name without intervening
  6732. <blank>
  6733. characters. POSIX.1\(hy2008 requires conformance to historical practice.
  6734. .P
  6735. Historically, the
  6736. .BR s
  6737. command could be immediately followed by flag and option characters;
  6738. for example,
  6739. .BR "s/e/E/|s|sgc3p"
  6740. was a valid command. However, flag characters could not stand alone;
  6741. for example, the commands
  6742. .BR sp
  6743. and
  6744. .BR s\0l
  6745. would fail, while the command
  6746. .BR sgp
  6747. and
  6748. .BR "s\0gl"
  6749. would succeed. (Obviously, the
  6750. .BR '#'
  6751. flag character was used as a delimiter character if it followed the
  6752. command.) Another issue was that option characters had to precede flag
  6753. characters even when the command was fully specified; for example, the
  6754. command
  6755. .BR s/e/E/pg
  6756. would fail, while the command
  6757. .BR s/e/E/gp
  6758. would succeed. POSIX.1\(hy2008 requires conformance to historical practice.
  6759. .P
  6760. Historically, the first command name that had a prefix matching the
  6761. input from the user was the executed command; for example,
  6762. .BR ve ,
  6763. .BR ver ,
  6764. and
  6765. .BR vers
  6766. all executed the
  6767. .BR version
  6768. command. Commands were in a specific order, however, so that
  6769. .BR a
  6770. matched
  6771. .BR append ,
  6772. not
  6773. .BR abbreviate .
  6774. POSIX.1\(hy2008 requires conformance to historical practice. The restriction on
  6775. command search order for implementations with extensions is to avoid
  6776. the addition of commands such that the historical prefixes would fail
  6777. to work portably.
  6778. .P
  6779. Historical implementations of
  6780. .IR ex
  6781. and
  6782. .IR vi
  6783. did not correctly handle multiple
  6784. .IR ex
  6785. commands, separated by
  6786. <vertical-line>
  6787. characters, that entered or exited visual mode or the editor. Because
  6788. implementations of
  6789. .IR vi
  6790. exist that do not exhibit this failure mode, POSIX.1\(hy2008 does not permit it.
  6791. .P
  6792. The requirement that alphabetic command names consist of all following
  6793. alphabetic characters up to the next non-alphabetic character means
  6794. that alphabetic command names must be separated from their arguments by
  6795. one or more non-alphabetic characters, normally a
  6796. <blank>
  6797. or
  6798. .BR '!'
  6799. character, except as specified for the exceptions, the
  6800. .BR delete ,
  6801. .BR k ,
  6802. and
  6803. .BR s
  6804. commands.
  6805. .P
  6806. Historically, the repeated execution of the
  6807. .IR ex
  6808. default
  6809. .BR print
  6810. commands (\c
  6811. <control>\(hyD,
  6812. .IR eof ,
  6813. <newline>,
  6814. <carriage-return>)
  6815. erased any prompting character and displayed the next lines without
  6816. scrolling the terminal; that is, immediately below any previously
  6817. displayed lines. This provided a cleaner presentation of the lines in
  6818. the file for the user. POSIX.1\(hy2008 does not require this behavior because it
  6819. may be impossible in some situations; however, implementations are
  6820. strongly encouraged to provide this semantic if possible.
  6821. .P
  6822. Historically, it was possible to change files in the middle of a command,
  6823. and have the rest of the command executed in the new file; for example:
  6824. .sp
  6825. .RS 4
  6826. .nf
  6827. :edit +25 file.c | s/abc/ABC/ | 1
  6828. .fi
  6829. .P
  6830. .RE
  6831. .P
  6832. was a valid command, and the substitution was attempted in the newly
  6833. edited file. POSIX.1\(hy2008 requires conformance to historical practice. The
  6834. following commands are examples that exercise the
  6835. .IR ex
  6836. parser:
  6837. .sp
  6838. .RS 4
  6839. .nf
  6840. echo \(aqfoo | bar\(aq > file1; echo \(aqfoo/bar\(aq > file2;
  6841. vi
  6842. :edit +1 | s/|/PIPE/ | w file1 | e file2 | 1 | s/\e//SLASH/ | wq
  6843. .fi
  6844. .P
  6845. .RE
  6846. .P
  6847. Historically, there was no protection in editor implementations to
  6848. avoid
  6849. .IR ex
  6850. .BR global ,
  6851. .BR v ,
  6852. .BR @ ,
  6853. or
  6854. .BR *
  6855. commands changing edit buffers during execution of their associated
  6856. commands. Because this would almost invariably result in catastrophic
  6857. failure of the editor, and implementations exist that do exhibit these
  6858. problems, POSIX.1\(hy2008 requires that changing the edit buffer during a
  6859. .BR global
  6860. or
  6861. .BR v
  6862. command, or during a
  6863. .BR @
  6864. or
  6865. .BR *
  6866. command for which there will be more than a single execution, be an
  6867. error. Implementations supporting multiple edit buffers simultaneously
  6868. are strongly encouraged to apply the same semantics to switching
  6869. between buffers as well.
  6870. .P
  6871. The
  6872. .IR ex
  6873. command quoting required by POSIX.1\(hy2008 is a superset of the quoting in
  6874. historical implementations of the editor. For example, it was not
  6875. historically possible to escape a
  6876. <blank>
  6877. in a filename; for example,
  6878. .BR ":edit\0foo\e\e\e\0bar"
  6879. would report that too many filenames had been entered for the edit
  6880. command, and there was no method of escaping a
  6881. <blank>
  6882. in the first argument of an
  6883. .BR edit ,
  6884. .BR ex ,
  6885. .BR next ,
  6886. or
  6887. .BR visual
  6888. command at all. POSIX.1\(hy2008 extends historical practice, requiring that
  6889. quoting behavior be made consistent across all
  6890. .IR ex
  6891. commands, except for the
  6892. .BR map ,
  6893. .BR unmap ,
  6894. .BR abbreviate ,
  6895. and
  6896. .BR unabbreviate
  6897. commands, which historically used
  6898. <control>\(hyV
  6899. instead of
  6900. <backslash>
  6901. characters for quoting. For those four commands, POSIX.1\(hy2008 requires
  6902. conformance to historical practice.
  6903. .P
  6904. Backslash quoting in
  6905. .IR ex
  6906. is non-intuitive.
  6907. <backslash>-escapes
  6908. are ignored unless they escape a special character; for example, when
  6909. performing
  6910. .IR file
  6911. argument expansion, the string
  6912. .BR \(dq\e\e%\(dq
  6913. is equivalent to
  6914. .BR '\e%' ,
  6915. not \fR"\e<\fIcurrent\ pathname\fR>"\fR.
  6916. This can be confusing for users because
  6917. <backslash>
  6918. is usually one of the characters that causes shell expansion to
  6919. be performed, and therefore shell quoting rules must be taken into
  6920. consideration. Generally, quoting characters are only considered if they
  6921. escape a special character, and a quoting character must be provided
  6922. for each layer of parsing for which the character is special. As another
  6923. example, only a single
  6924. <backslash>
  6925. is necessary for the
  6926. .BR '\el'
  6927. sequence in substitute replacement patterns, because the character
  6928. .BR 'l'
  6929. is not special to any parsing layer above it.
  6930. .P
  6931. <control>\(hyV
  6932. quoting in
  6933. .IR ex
  6934. is slightly different from backslash quoting. In the four commands
  6935. where
  6936. <control>\(hyV
  6937. quoting applies (\c
  6938. .BR abbreviate ,
  6939. .BR unabbreviate ,
  6940. .BR map ,
  6941. and
  6942. .BR unmap ),
  6943. any character may be escaped by a
  6944. <control>\(hyV
  6945. whether it would have a special meaning or not. POSIX.1\(hy2008 requires
  6946. conformance to historical practice.
  6947. .P
  6948. Historical implementations of the editor did not require delimiters
  6949. within character classes to be escaped; for example, the command
  6950. .BR ":s/[/]//"
  6951. on the string
  6952. .BR \(dqxxx/yyy\(dq
  6953. would delete the
  6954. .BR '/'
  6955. from the string. POSIX.1\(hy2008 disallows this historical practice for
  6956. consistency and because it places a large burden on implementations by
  6957. requiring that knowledge of regular expressions be built into the
  6958. editor parser.
  6959. .P
  6960. Historically, quoting
  6961. <newline>
  6962. characters in
  6963. .IR ex
  6964. commands was handled inconsistently. In most cases, the
  6965. <newline>
  6966. character always terminated the command, regardless of any preceding
  6967. escape character, because
  6968. <backslash>
  6969. characters did not escape
  6970. <newline>
  6971. characters for most
  6972. .IR ex
  6973. commands. However, some
  6974. .IR ex
  6975. commands (for example,
  6976. .BR s ,
  6977. .BR map ,
  6978. and
  6979. .BR abbreviation )
  6980. permitted
  6981. <newline>
  6982. characters to be escaped (although in the case of
  6983. .BR map
  6984. and
  6985. .BR abbreviation ,
  6986. <control>\(hyV
  6987. characters escaped them instead of
  6988. <backslash>
  6989. characters). This was true in not only the command line, but also
  6990. .BR .exrc
  6991. and
  6992. .BR source d
  6993. files. For example, the command:
  6994. .sp
  6995. .RS 4
  6996. .nf
  6997. map = foo<control-V><newline>bar
  6998. .fi
  6999. .P
  7000. .RE
  7001. .P
  7002. would succeed, although it was sometimes difficult to get the
  7003. <control>\(hyV
  7004. and the inserted
  7005. <newline>
  7006. passed to the
  7007. .IR ex
  7008. parser. For consistency and simplicity of specification, POSIX.1\(hy2008 requires
  7009. that it be possible to escape
  7010. <newline>
  7011. characters in
  7012. .IR ex
  7013. commands at all times, using
  7014. <backslash>
  7015. characters for most
  7016. .IR ex
  7017. commands, and using
  7018. <control>\(hyV
  7019. characters for the
  7020. .BR map
  7021. and
  7022. .BR abbreviation
  7023. commands. For example, the command
  7024. .BR print \c
  7025. <newline>\c
  7026. .BR list
  7027. is required to be parsed as the single command
  7028. .BR print \c
  7029. <newline>\c
  7030. .BR list .
  7031. While this differs from historical practice, POSIX.1\(hy2008 developers believed
  7032. it unlikely that any script or user depended on the historical
  7033. behavior.
  7034. .P
  7035. Historically, an error in a command specified using the
  7036. .BR \-c
  7037. option did not cause the rest of the
  7038. .BR \-c
  7039. commands to be discarded. POSIX.1\(hy2008 disallows this for consistency with
  7040. mapped keys, the
  7041. .BR @ ,
  7042. .BR global ,
  7043. .BR source ,
  7044. and
  7045. .BR v
  7046. commands, the
  7047. .IR EXINIT
  7048. environment variable, and the
  7049. .BR .exrc
  7050. files.
  7051. .SS "Input Editing in ex"
  7052. .P
  7053. One of the common uses of the historical
  7054. .IR ex
  7055. editor is over slow network connections. Editors that run in canonical
  7056. mode can require far less traffic to and from, and far less processing
  7057. on, the host machine, as well as more easily supporting block-mode
  7058. terminals. For these reasons, POSIX.1\(hy2008 requires that
  7059. .IR ex
  7060. be implemented using canonical mode input processing, as was done
  7061. historically.
  7062. .P
  7063. POSIX.1\(hy2008 does not require the historical 4 BSD input editing characters
  7064. ``word erase'' or ``literal next''. For this reason, it is unspecified
  7065. how they are handled by
  7066. .IR ex ,
  7067. although they must have the required effect. Implementations that
  7068. resolve them after the line has been ended using a
  7069. <newline>
  7070. or
  7071. <control>\(hyM
  7072. character, and implementations that rely on the underlying system
  7073. terminal support for this processing, are both conforming.
  7074. Implementations are strongly urged to use the underlying system
  7075. functionality, if at all possible, for compatibility with other system
  7076. text input interfaces.
  7077. .P
  7078. Historically, when the
  7079. .IR eof
  7080. character was used to decrement the
  7081. .BR autoindent
  7082. level, the cursor moved to display the new end of the
  7083. .BR autoindent
  7084. characters, but did not move the cursor to a new line, nor did it erase
  7085. the
  7086. <control>\(hyD
  7087. character from the line. POSIX.1\(hy2008 does not specify that the cursor remain
  7088. on the same line or that the rest of the line is erased; however,
  7089. implementations are strongly encouraged to provide the best possible
  7090. user interface; that is, the cursor should remain on the same line, and
  7091. any
  7092. <control>\(hyD
  7093. character on the line should be erased.
  7094. .P
  7095. POSIX.1\(hy2008 does not require the historical 4 BSD input editing character
  7096. ``reprint'', traditionally
  7097. <control>\(hyR,
  7098. which redisplayed the current input from the user. For this reason, and
  7099. because the functionality cannot be implemented after the line has been
  7100. terminated by the user, POSIX.1\(hy2008 makes no requirements about this
  7101. functionality. Implementations are strongly urged to make this
  7102. historical functionality available, if possible.
  7103. .P
  7104. Historically,
  7105. <control>\(hyQ
  7106. did not perform a literal next function in
  7107. .IR ex ,
  7108. as it did in
  7109. .IR vi .
  7110. POSIX.1\(hy2008 requires conformance to historical practice to avoid breaking
  7111. historical
  7112. .IR ex
  7113. scripts and
  7114. .BR .exrc
  7115. files.
  7116. .SS "eof"
  7117. .P
  7118. Whether the
  7119. .IR eof
  7120. character immediately modifies the
  7121. .BR autoindent
  7122. characters in the prompt is left unspecified so that implementations
  7123. can conform in the presence of systems that do not support this
  7124. functionality. Implementations are encouraged to modify the line and
  7125. redisplay it immediately, if possible.
  7126. .P
  7127. The specification of the handling of the
  7128. .IR eof
  7129. character differs from historical practice only in that
  7130. .IR eof
  7131. characters are not discarded if they follow normal characters in the
  7132. text input. Historically, they were always discarded.
  7133. .SS "Command Descriptions in ex"
  7134. .P
  7135. Historically, several commands (for example,
  7136. .BR global ,
  7137. .BR v ,
  7138. .BR visual ,
  7139. .BR s ,
  7140. .BR write ,
  7141. .BR wq ,
  7142. .BR yank ,
  7143. .BR ! ,
  7144. .BR < ,
  7145. .BR > ,
  7146. .BR & ,
  7147. and
  7148. .BR ~ )
  7149. were executable in empty files (that is, the default address(es) were
  7150. 0), or permitted explicit addresses of 0 (for example, 0 was a valid
  7151. address, or 0,0 was a valid range). Addresses of 0, or command
  7152. execution in an empty file, make sense only for commands that add new
  7153. text to the edit buffer or write commands (because users may wish to
  7154. write empty files). POSIX.1\(hy2008 requires this behavior for such commands and
  7155. disallows it otherwise, for consistency and simplicity of
  7156. specification.
  7157. .P
  7158. A count to an
  7159. .IR ex
  7160. command has been historically corrected to be no greater than the last
  7161. line in a file; for example, in a five-line file, the command
  7162. .BR "1,6print"
  7163. would fail, but the command
  7164. .BR "1print300"
  7165. would succeed. POSIX.1\(hy2008 requires conformance to historical practice.
  7166. .P
  7167. Historically, the use of flags in
  7168. .IR ex
  7169. commands could be obscure. General historical practice was as described
  7170. by POSIX.1\(hy2008, but there were some special cases. For instance, the
  7171. .BR list ,
  7172. .BR number ,
  7173. and
  7174. .BR print
  7175. commands ignored trailing address offsets; for example,
  7176. .BR "3p\0+++#"
  7177. would display line 3, and 3 would be the current line after the
  7178. execution of the command. The
  7179. .BR open
  7180. and
  7181. .BR visual
  7182. commands ignored both the trailing offsets and the trailing flags.
  7183. Also, flags specified to the
  7184. .BR open
  7185. and
  7186. .BR visual
  7187. commands interacted badly with the
  7188. .BR list
  7189. edit option, and setting and then unsetting it during the open/visual
  7190. session would cause
  7191. .IR vi
  7192. to stop displaying lines in the specified format. For consistency and
  7193. simplicity of specification, POSIX.1\(hy2008 does not permit any of these
  7194. exceptions to the general rule.
  7195. .P
  7196. POSIX.1\(hy2008 uses the word
  7197. .IR copy
  7198. in several places when discussing buffers. This is not intended to
  7199. imply implementation.
  7200. .P
  7201. Historically,
  7202. .IR ex
  7203. users could not specify numeric buffers because of the ambiguity this
  7204. would cause; for example, in the command
  7205. .BR "3\0delete\02" ,
  7206. it is unclear whether 2 is a buffer name or a
  7207. .IR count .
  7208. POSIX.1\(hy2008 requires conformance to historical practice by default, but does
  7209. not preclude extensions.
  7210. .P
  7211. Historically, the contents of the unnamed buffer were frequently
  7212. discarded after commands that did not explicitly affect it; for
  7213. example, when using the
  7214. .BR edit
  7215. command to switch files. For consistency and simplicity of
  7216. specification, POSIX.1\(hy2008 does not permit this behavior.
  7217. .P
  7218. The
  7219. .IR ex
  7220. utility did not historically have access to the numeric buffers, and,
  7221. furthermore, deleting lines in
  7222. .IR ex
  7223. did not modify their contents. For example, if, after doing a delete in
  7224. .IR vi ,
  7225. the user switched to
  7226. .IR ex ,
  7227. did another delete, and then switched back to
  7228. .IR vi ,
  7229. the contents of the numeric buffers would not have changed. POSIX.1\(hy2008
  7230. requires conformance to historical practice. Numeric buffers are
  7231. described in the
  7232. .IR ex
  7233. utility in order to confine the description of buffers to a single
  7234. location in POSIX.1\(hy2008.
  7235. .P
  7236. The metacharacters that trigger shell expansion in
  7237. .IR file
  7238. arguments match historical practice, as does the method for doing shell
  7239. expansion. Implementations wishing to provide users with the
  7240. flexibility to alter the set of metacharacters are encouraged to
  7241. provide a
  7242. .BR shellmeta
  7243. string edit option.
  7244. .P
  7245. Historically,
  7246. .IR ex
  7247. commands executed from
  7248. .IR vi
  7249. refreshed the screen when it did not strictly need to do so; for
  7250. example,
  7251. .BR ":!date\0>\0/dev/null"
  7252. does not require a screen refresh because the output of the UNIX
  7253. .IR date
  7254. command requires only a single line of the screen. POSIX.1\(hy2008 requires that
  7255. the screen be refreshed if it has been overwritten, but makes no
  7256. requirements as to how an implementation should make that
  7257. determination. Implementations may prompt and refresh the screen
  7258. regardless.
  7259. .SS "Abbreviate"
  7260. .P
  7261. Historical practice was that characters that were entered as part of an
  7262. abbreviation replacement were subject to
  7263. .BR map
  7264. expansions, the
  7265. .BR showmatch
  7266. edit option, further abbreviation expansions, and so on; that is, they
  7267. were logically pushed onto the terminal input queue, and were not a
  7268. simple replacement. POSIX.1\(hy2008 requires conformance to historical practice.
  7269. Historical practice was that whenever a non-word character (that had
  7270. not been escaped by a
  7271. <control>\(hyV)
  7272. was entered after a word character,
  7273. .IR vi
  7274. would check for abbreviations. The check was based on the type of the
  7275. character entered before the word character of the word/non-word pair
  7276. that triggered the check. The word character of the word/non-word pair
  7277. that triggered the check and all characters entered before the trigger
  7278. pair that were of that type were included in the check, with the
  7279. exception of
  7280. <blank>
  7281. characters, which always delimited the abbreviation.
  7282. .P
  7283. This means that, for the abbreviation to work, the
  7284. .IR lhs
  7285. must end with a word character, there can be no transitions from word
  7286. to non-word characters (or \fIvice versa\fP) other than between the
  7287. last and next-to-last characters in the
  7288. .IR lhs ,
  7289. and there can be no
  7290. <blank>
  7291. characters in the
  7292. .IR lhs .
  7293. In addition, because of the historical quoting rules, it was impossible
  7294. to enter a literal
  7295. <control>\(hyV
  7296. in the
  7297. .IR lhs .
  7298. POSIX.1\(hy2008 requires conformance to historical practice. Historical
  7299. implementations did not inform users when abbreviations that could
  7300. never be used were entered; implementations are strongly encouraged to
  7301. do so.
  7302. .br
  7303. .P
  7304. For example, the following abbreviations will work:
  7305. .sp
  7306. .RS 4
  7307. .nf
  7308. :ab (p REPLACE
  7309. :ab p REPLACE
  7310. :ab ((p REPLACE
  7311. .fi
  7312. .P
  7313. .RE
  7314. .P
  7315. The following abbreviations will not work:
  7316. .sp
  7317. .RS 4
  7318. .nf
  7319. :ab ( REPLACE
  7320. :ab (pp REPLACE
  7321. .fi
  7322. .P
  7323. .RE
  7324. .P
  7325. Historical practice is that words on the
  7326. .IR vi
  7327. colon command line were subject to abbreviation expansion, including
  7328. the arguments to the
  7329. .BR abbrev
  7330. (and more interestingly) the
  7331. .BR unabbrev
  7332. command. Because there are implementations that do not do abbreviation
  7333. expansion for the first argument to those commands, this is permitted,
  7334. but not required, by POSIX.1\(hy2008. However, the following sequence:
  7335. .sp
  7336. .RS 4
  7337. .nf
  7338. :ab foo bar
  7339. :ab foo baz
  7340. .fi
  7341. .P
  7342. .RE
  7343. .P
  7344. resulted in the addition of an abbreviation of
  7345. .BR \(dqbaz\(dq
  7346. for the string
  7347. .BR \(dqbar\(dq
  7348. in historical
  7349. .IR ex /\c
  7350. .IR vi ,
  7351. and the sequence:
  7352. .sp
  7353. .RS 4
  7354. .nf
  7355. :ab foo1 bar
  7356. :ab foo2 bar
  7357. :unabbreviate foo2
  7358. .fi
  7359. .P
  7360. .RE
  7361. .P
  7362. deleted the abbreviation
  7363. .BR \(dqfoo1\(dq ,
  7364. not
  7365. .BR \(dqfoo2\(dq .
  7366. These behaviors are not permitted by POSIX.1\(hy2008 because they clearly violate
  7367. the expectations of the user.
  7368. .P
  7369. It was historical practice that
  7370. <control>\(hyV,
  7371. not
  7372. <backslash>,
  7373. characters be interpreted as escaping subsequent characters in the
  7374. .BR abbreviate
  7375. command. POSIX.1\(hy2008 requires conformance to historical practice; however, it
  7376. should be noted that an abbreviation containing a
  7377. <blank>
  7378. will never work.
  7379. .SS "Append"
  7380. .P
  7381. Historically, any text following a
  7382. <vertical-line>
  7383. command separator after an
  7384. .BR append ,
  7385. .BR change ,
  7386. or
  7387. .BR insert
  7388. command became part of the insert text. For example, in the command:
  7389. .sp
  7390. .RS 4
  7391. .nf
  7392. :g/pattern/append|stuff1
  7393. .fi
  7394. .P
  7395. .RE
  7396. .P
  7397. a line containing the text
  7398. .BR \(dqstuff1\(dq
  7399. would be appended to each line matching pattern. It was also
  7400. historically valid to enter:
  7401. .sp
  7402. .RS 4
  7403. .nf
  7404. :append|stuff1
  7405. stuff2
  7406. \&.
  7407. .fi
  7408. .P
  7409. .RE
  7410. .P
  7411. and the text on the
  7412. .IR ex
  7413. command line would be appended along with the text inserted after it.
  7414. There was an historical bug, however, that the user had to enter two
  7415. terminating lines (the
  7416. .BR '.'
  7417. lines) to terminate text input mode in this case. POSIX.1\(hy2008 requires
  7418. conformance to historical practice, but disallows the historical need
  7419. for multiple terminating lines.
  7420. .SS "Change"
  7421. .P
  7422. See the RATIONALE for the
  7423. .BR append
  7424. command. Historical practice for cursor positioning after the change
  7425. command when no text is input, is as described in POSIX.1\(hy2008. However, one
  7426. System V implementation is known to have been modified such that the
  7427. cursor is positioned on the first address specified, and not on the
  7428. line before the first address. POSIX.1\(hy2008 disallows this modification for
  7429. consistency.
  7430. .P
  7431. Historically, the
  7432. .BR change
  7433. command did not support buffer arguments, although some implementations
  7434. allow the specification of an optional buffer. This behavior is neither
  7435. required nor disallowed by POSIX.1\(hy2008.
  7436. .SS "Change Directory"
  7437. .P
  7438. A common extension in
  7439. .IR ex
  7440. implementations is to use the elements of a
  7441. .BR cdpath
  7442. edit option as prefix directories for
  7443. .IR path
  7444. arguments to
  7445. .BR chdir
  7446. that are relative pathnames and that do not have
  7447. .BR '.'
  7448. or
  7449. .BR \(dq..\(dq
  7450. as their first component. Elements in the
  7451. .BR cdpath
  7452. edit option are
  7453. <colon>-separated.
  7454. The initial value of the
  7455. .BR cdpath
  7456. edit option is the value of the shell
  7457. .IR CDPATH
  7458. environment variable. This feature was not included in POSIX.1\(hy2008 because it
  7459. does not exist in any of the implementations considered historical
  7460. practice.
  7461. .SS "Copy"
  7462. .P
  7463. Historical implementations of
  7464. .IR ex
  7465. permitted copies to lines inside of the specified range; for example,
  7466. .BR ":2,5copy3"
  7467. was a valid command. POSIX.1\(hy2008 requires conformance to historical
  7468. practice.
  7469. .SS "Delete"
  7470. .P
  7471. POSIX.1\(hy2008 requires support for the historical parsing of a
  7472. .BR delete
  7473. command followed by flags, without any intervening
  7474. <blank>
  7475. characters. For example:
  7476. .IP "\fB1dp\fP" 8
  7477. Deletes the first line and prints the line that was second.
  7478. .IP "\fB1delep\fP" 8
  7479. As for
  7480. .BR 1dp .
  7481. .IP "\fB1d\fP" 8
  7482. Deletes the first line, saving it in buffer
  7483. .IR p .
  7484. .IP "\fB1d\0p1l\fP" 8
  7485. (Pee-one-ell.) Deletes the first line, saving it in buffer
  7486. .IR p ,
  7487. and listing the line that was second.
  7488. .SS "Edit"
  7489. .P
  7490. Historically, any
  7491. .IR ex
  7492. command could be entered as a
  7493. .BR + \c
  7494. .IR command
  7495. argument to the
  7496. .BR edit
  7497. command, although some (for example,
  7498. .BR insert
  7499. and
  7500. .BR append )
  7501. were known to confuse historical implementations. For consistency and
  7502. simplicity of specification, POSIX.1\(hy2008 requires that any command be
  7503. supported as an argument to the
  7504. .BR edit
  7505. command.
  7506. .P
  7507. Historically, the command argument was executed with the current line
  7508. set to the last line of the file, regardless of whether the
  7509. .BR edit
  7510. command was executed from visual mode or not. POSIX.1\(hy2008 requires
  7511. conformance to historical practice.
  7512. .P
  7513. Historically, the
  7514. .BR + \c
  7515. .IR command
  7516. specified to the
  7517. .BR edit
  7518. and
  7519. .BR next
  7520. commands was delimited by the first
  7521. <blank>,
  7522. and there was no way to quote them. For consistency, POSIX.1\(hy2008 requires
  7523. that the usual
  7524. .IR ex
  7525. backslash quoting be provided.
  7526. .P
  7527. Historically, specifying the
  7528. .BR + \c
  7529. .IR command
  7530. argument to the edit command required a filename to be specified as
  7531. well; for example,
  7532. .BR ":edit\0+100"
  7533. would always fail. For consistency and simplicity of specification,
  7534. POSIX.1\(hy2008 does not permit this usage to fail for that reason.
  7535. .P
  7536. Historically, only the cursor position of the last file edited was
  7537. remembered by the editor. POSIX.1\(hy2008 requires that this be supported;
  7538. however, implementations are permitted to remember and restore the
  7539. cursor position for any file previously edited.
  7540. .SS "File"
  7541. .P
  7542. Historical versions of the
  7543. .IR ex
  7544. editor
  7545. .BR file
  7546. command displayed a current line and number of lines in the edit buffer
  7547. of 0 when the file was empty, while the
  7548. .IR vi
  7549. <control>\(hyG
  7550. command displayed a current line and number of lines in the edit buffer
  7551. of 1 in the same situation. POSIX.1\(hy2008 does not permit this discrepancy,
  7552. instead requiring that a message be displayed indicating that the file
  7553. is empty.
  7554. .SS "Global"
  7555. .P
  7556. The two-pass operation of the
  7557. .BR global
  7558. and
  7559. .BR v
  7560. commands is not intended to imply implementation, only the required
  7561. result of the operation.
  7562. .P
  7563. The current line and column are set as specified for the individual
  7564. .IR ex
  7565. commands. This requirement is cumulative; that is, the current line and
  7566. column must track across all the commands executed by the
  7567. .BR global
  7568. or
  7569. .BR v
  7570. commands.
  7571. .SS "Insert"
  7572. .P
  7573. See the RATIONALE for the
  7574. .BR append
  7575. command.
  7576. .P
  7577. Historically,
  7578. .BR insert
  7579. could not be used with an address of zero; that is, not when the edit
  7580. buffer was empty. POSIX.1\(hy2008 requires that this command behave consistently
  7581. with the
  7582. .BR append
  7583. command.
  7584. .SS "Join"
  7585. .P
  7586. The action of the
  7587. .BR join
  7588. command in relation to the special characters is only defined for the
  7589. POSIX locale because the correct amount of white space after a period
  7590. varies; in Japanese none is required, in French only a single space,
  7591. and so on.
  7592. .SS "List"
  7593. .P
  7594. The historical output of the
  7595. .BR list
  7596. command was potentially ambiguous. The standard developers believed
  7597. correcting this to be more important than adhering to historical
  7598. practice, and POSIX.1\(hy2008 requires unambiguous output.
  7599. .SS "Map"
  7600. .P
  7601. Historically, command mode maps only applied to command names; for
  7602. example, if the character
  7603. .BR 'x'
  7604. was mapped to
  7605. .BR 'y' ,
  7606. the command
  7607. .BR fx
  7608. searched for the
  7609. .BR 'x'
  7610. character, not the
  7611. .BR 'y'
  7612. character. POSIX.1\(hy2008 requires this behavior. Historically, entering
  7613. <control>\(hyV
  7614. as the first character of a
  7615. .IR vi
  7616. command was an error. Several implementations have extended the
  7617. semantics of
  7618. .IR vi
  7619. such that
  7620. <control>\(hyV
  7621. means that the subsequent command character is not mapped. This is
  7622. permitted, but not required, by POSIX.1\(hy2008. Regardless, using
  7623. <control>\(hyV
  7624. to escape the second or later character in a sequence of characters
  7625. that might match a
  7626. .BR map
  7627. command, or any character in text input mode, is historical practice,
  7628. and stops the entered keys from matching a map. POSIX.1\(hy2008 requires
  7629. conformance to historical practice.
  7630. .P
  7631. Historical implementations permitted digits to be used as a
  7632. .BR map
  7633. command
  7634. .IR lhs ,
  7635. but then ignored the map. POSIX.1\(hy2008 requires that the mapped digits not be
  7636. ignored.
  7637. .P
  7638. The historical implementation of the
  7639. .BR map
  7640. command did not permit
  7641. .BR map
  7642. commands that were more than a single character in length if the first
  7643. character was printable. This behavior is permitted, but not required,
  7644. by POSIX.1\(hy2008.
  7645. .P
  7646. Historically, mapped characters were remapped unless the
  7647. .BR remap
  7648. edit option was not set, or the prefix of the mapped characters matched
  7649. the mapping characters; for example, in the
  7650. .BR map :
  7651. .sp
  7652. .RS 4
  7653. .nf
  7654. :map ab abcd
  7655. .fi
  7656. .P
  7657. .RE
  7658. .P
  7659. the characters
  7660. .BR \(dqab\(dq
  7661. were used as is and were not remapped, but the characters
  7662. .BR \(dqcd\(dq
  7663. were mapped if appropriate. This can cause infinite loops in the
  7664. .IR vi
  7665. mapping mechanisms. POSIX.1\(hy2008 requires conformance to historical practice,
  7666. and that such loops be interruptible.
  7667. .P
  7668. Text input maps had the same problems with expanding the
  7669. .IR lhs
  7670. for the
  7671. .IR ex
  7672. .BR map!
  7673. and
  7674. .BR unmap!
  7675. command as did the
  7676. .IR ex
  7677. .BR abbreviate
  7678. and
  7679. .BR unabbreviate
  7680. commands. See the RATIONALE for the
  7681. .IR ex
  7682. .BR abbreviate
  7683. command. POSIX.1\(hy2008 requires similar modification of some historical
  7684. practice for the
  7685. .BR map
  7686. and
  7687. .BR unmap
  7688. commands, as described for the
  7689. .BR abbreviate
  7690. and
  7691. .BR unabbreviate
  7692. commands.
  7693. .P
  7694. Historically,
  7695. .BR map s
  7696. that were subsets of other
  7697. .BR map s
  7698. behaved differently depending on the order in which they were defined.
  7699. For example:
  7700. .sp
  7701. .RS 4
  7702. .nf
  7703. :map! ab short
  7704. :map! abc long
  7705. .fi
  7706. .P
  7707. .RE
  7708. .P
  7709. would always translate the characters
  7710. .BR \(dqab\(dq
  7711. to
  7712. .BR \(dqshort\(dq ,
  7713. regardless of how fast the characters
  7714. .BR \(dqabc\(dq
  7715. were entered. If the entry order was reversed:
  7716. .sp
  7717. .RS 4
  7718. .nf
  7719. :map! abc long
  7720. :map! ab short
  7721. .fi
  7722. .P
  7723. .RE
  7724. .P
  7725. the characters
  7726. .BR \(dqab\(dq
  7727. would cause the editor to pause, waiting for the completing
  7728. .BR 'c'
  7729. character, and the characters might never be mapped to
  7730. .BR \(dqshort\(dq .
  7731. For consistency and simplicity of specification, POSIX.1\(hy2008 requires that
  7732. the shortest match be used at all times.
  7733. .P
  7734. The length of time the editor spends waiting for the characters to
  7735. complete the
  7736. .IR lhs
  7737. is unspecified because the timing capabilities of systems are often
  7738. inexact and variable, and it may depend on other factors such as the
  7739. speed of the connection. The time should be long enough for the user to
  7740. be able to complete the sequence, but not long enough for the user to
  7741. have to wait. Some implementations of
  7742. .IR vi
  7743. have added a
  7744. .BR keytime
  7745. option, which permits users to set the number of 0,1 seconds the editor
  7746. waits for the completing characters. Because mapped terminal function
  7747. and cursor keys tend to start with an
  7748. <ESC>
  7749. character, and
  7750. <ESC>
  7751. is the key ending
  7752. .IR vi
  7753. text input mode,
  7754. .BR map s
  7755. starting with
  7756. <ESC>
  7757. characters are generally exempted from this timeout period, or, at
  7758. least timed out differently.
  7759. .SS "Mark"
  7760. .P
  7761. Historically, users were able to set the ``previous context'' marks
  7762. explicitly. In addition, the
  7763. .IR ex
  7764. commands
  7765. .BR \(aq\(aq
  7766. and
  7767. .BR \(aq`
  7768. and the
  7769. .IR vi
  7770. commands
  7771. .BR \(aq\(aq ,
  7772. .BR `` ,
  7773. .BR `\(aq ,
  7774. and
  7775. .BR \(aq`
  7776. all referred to the same mark. In addition, the previous context marks
  7777. were not set if the command, with which the address setting the mark
  7778. was associated, failed. POSIX.1\(hy2008 requires conformance to historical
  7779. practice. Historically, if marked lines were deleted, the mark was also
  7780. deleted, but would reappear if the change was undone. POSIX.1\(hy2008 requires
  7781. conformance to historical practice.
  7782. .P
  7783. The description of the special events that set the
  7784. .BR `
  7785. and
  7786. .BR \(aq
  7787. marks matches historical practice. For example, historically the
  7788. command
  7789. .BR "/a/,/b/"
  7790. did not set the
  7791. .BR `
  7792. and
  7793. .BR \(aq
  7794. marks, but the command
  7795. .BR "/a/,/b/delete"
  7796. did.
  7797. .SS "Next"
  7798. .P
  7799. Historically, any
  7800. .IR ex
  7801. command could be entered as a
  7802. .BR + \c
  7803. .IR command
  7804. argument to the
  7805. .BR next
  7806. command, although some (for example,
  7807. .BR insert
  7808. and
  7809. .BR append )
  7810. were known to confuse historical implementations. POSIX.1\(hy2008 requires that
  7811. any command be permitted and that it behave as specified. The
  7812. .BR next
  7813. command can accept more than one file, so usage such as:
  7814. .sp
  7815. .RS 4
  7816. .nf
  7817. next `ls [abc] `
  7818. .fi
  7819. .P
  7820. .RE
  7821. .P
  7822. is valid; it need not be valid for the
  7823. .BR edit
  7824. or
  7825. .BR read
  7826. commands, for example, because they expect only one filename.
  7827. .P
  7828. Historically, the
  7829. .BR next
  7830. command behaved differently from the
  7831. .BR :rewind
  7832. command in that it ignored the force flag if the
  7833. .BR autowrite
  7834. flag was set. For consistency, POSIX.1\(hy2008 does not permit this behavior.
  7835. .P
  7836. Historically, the
  7837. .BR next
  7838. command positioned the cursor as if the file had never been edited
  7839. before, regardless. POSIX.1\(hy2008 does not permit this behavior, for
  7840. consistency with the
  7841. .BR edit
  7842. command.
  7843. .P
  7844. Implementations wanting to provide a counterpart to the
  7845. .BR next
  7846. command that edited the previous file have used the command
  7847. .BR prev[ious],
  7848. which takes no
  7849. .IR file
  7850. argument. POSIX.1\(hy2008 does not require this command.
  7851. .SS "Open"
  7852. .P
  7853. Historically, the
  7854. .BR open
  7855. command would fail if the
  7856. .BR open
  7857. edit option was not set. POSIX.1\(hy2008 does not mention the
  7858. .BR open
  7859. edit option and does not require this behavior. Some historical
  7860. implementations do not permit entering open mode from open or visual
  7861. mode, only from
  7862. .IR ex
  7863. mode. For consistency, POSIX.1\(hy2008 does not permit this behavior.
  7864. .P
  7865. Historically, entering open mode from the command line (that is,
  7866. .IR vi
  7867. .BR +open )
  7868. resulted in anomalous behaviors; for example, the
  7869. .IR ex
  7870. file and
  7871. .IR set
  7872. commands, and the
  7873. .IR vi
  7874. command
  7875. <control>\(hyG
  7876. did not work. For consistency, POSIX.1\(hy2008 does not permit this behavior.
  7877. .P
  7878. Historically, the
  7879. .BR open
  7880. command only permitted
  7881. .BR '/'
  7882. characters to be used as the search pattern delimiter. For consistency,
  7883. POSIX.1\(hy2008 requires that the search delimiters used by the
  7884. .BR s ,
  7885. .BR global ,
  7886. and
  7887. .BR v
  7888. commands be accepted as well.
  7889. .SS "Preserve"
  7890. .P
  7891. The
  7892. .BR preserve
  7893. command does not historically cause the file to be considered
  7894. unmodified for the purposes of future commands that may exit the
  7895. editor. POSIX.1\(hy2008 requires conformance to historical practice.
  7896. .P
  7897. Historical documentation stated that mail was not sent to the user when
  7898. preserve was executed; however, historical implementations did send
  7899. mail in this case. POSIX.1\(hy2008 requires conformance to the historical
  7900. implementations.
  7901. .SS "Print"
  7902. .P
  7903. The writing of NUL by the
  7904. .BR print
  7905. command is not specified as a special case because the standard
  7906. developers did not want to require
  7907. .IR ex
  7908. to support NUL characters. Historically, characters were displayed
  7909. using the ARPA standard mappings, which are as follows:
  7910. .IP " 1." 4
  7911. Printable characters are left alone.
  7912. .IP " 2." 4
  7913. Control characters less than \e177 are represented as
  7914. .BR '\(ha'
  7915. followed by the character offset from the
  7916. .BR '@'
  7917. character in the ASCII map; for example, \e007 is represented as
  7918. .BR '\(haG' .
  7919. .IP " 3." 4
  7920. \e177 is represented as
  7921. .BR '\(ha'
  7922. followed by
  7923. .BR '?' .
  7924. .P
  7925. The display of characters having their eighth bit set was less
  7926. standard. Existing implementations use hex (0x00), octal (\e000), and a
  7927. meta-bit display. (The latter displayed bytes that had their eighth bit
  7928. set as the two characters
  7929. .BR \(dqM-\(dq
  7930. followed by the seven-bit display as described above.) The latter
  7931. probably has the best claim to historical practice because it was used
  7932. for the
  7933. .BR \-v
  7934. option of 4 BSD and 4 BSD-derived versions of the
  7935. .IR cat
  7936. utility since 1980.
  7937. .P
  7938. No specific display format is required by POSIX.1\(hy2008.
  7939. .P
  7940. Explicit dependence on the ASCII character set has been avoided where
  7941. possible, hence the use of the phrase an ``implementation-defined
  7942. multi-character sequence'' for the display of non-printable characters
  7943. in preference to the historical usage of, for instance,
  7944. .BR \(dq\(haI\(dq
  7945. for the
  7946. <tab>.
  7947. Implementations are encouraged to conform to historical practice in the
  7948. absence of any strong reason to diverge.
  7949. .P
  7950. Historically, all
  7951. .IR ex
  7952. commands beginning with the letter
  7953. .BR 'p'
  7954. could be entered using capitalized versions of the commands; for
  7955. example,
  7956. .BR P[rint] ,
  7957. .BR Pre[serve] ,
  7958. and
  7959. .BR Pu[t]
  7960. were all valid command names. POSIX.1\(hy2008 permits, but does not require, this
  7961. historical practice because capital forms of the commands are used by
  7962. some implementations for other purposes.
  7963. .SS "Put"
  7964. .P
  7965. Historically, an
  7966. .IR ex
  7967. .BR put
  7968. command, executed from open or visual mode, was the same as the open or
  7969. visual mode
  7970. .BR P
  7971. command, if the buffer was named and was cut in character mode, and the
  7972. same as the
  7973. .BR p
  7974. command if the buffer was named and cut in line mode. If the unnamed
  7975. buffer was the source of the text, the entire line from which the text
  7976. was taken was usually
  7977. .BR put ,
  7978. and the buffer was handled as if in line mode, but it was possible to
  7979. get extremely anomalous behavior. In addition, using the
  7980. .BR Q
  7981. command to switch into
  7982. .IR ex
  7983. mode, and then doing a
  7984. .BR put
  7985. often resulted in errors as well, such as appending text that was
  7986. unrelated to the (supposed) contents of the buffer. For consistency and
  7987. simplicity of specification, POSIX.1\(hy2008 does not permit these behaviors. All
  7988. .IR ex
  7989. .BR put
  7990. commands are required to operate in line mode, and the contents of the
  7991. buffers are not altered by changing the mode of the editor.
  7992. .SS "Read"
  7993. .P
  7994. Historically, an
  7995. .IR ex
  7996. .BR read
  7997. command executed from open or visual mode, executed in an empty file,
  7998. left an empty line as the first line of the file. For consistency and
  7999. simplicity of specification, POSIX.1\(hy2008 does not permit this behavior.
  8000. Historically, a
  8001. .BR read
  8002. in open or visual mode from a program left the cursor at the last line
  8003. read in, not the first. For consistency, POSIX.1\(hy2008 does not permit this
  8004. behavior.
  8005. .P
  8006. Historical implementations of
  8007. .IR ex
  8008. were unable to undo
  8009. .BR read
  8010. commands that read from the output of a program. For consistency, POSIX.1\(hy2008
  8011. does not permit this behavior.
  8012. .P
  8013. Historically, the
  8014. .IR ex
  8015. and
  8016. .IR vi
  8017. message after a successful
  8018. .BR read
  8019. or
  8020. .BR write
  8021. command specified ``characters'', not ``bytes''. POSIX.1\(hy2008 requires that
  8022. the number of bytes be displayed, not the number of characters, because
  8023. it may be difficult in multi-byte implementations to determine the
  8024. number of characters read. Implementations are encouraged to clarify
  8025. the message displayed to the user.
  8026. .P
  8027. Historically, reads were not permitted on files other than type
  8028. regular, except that FIFO files could be read (probably only because
  8029. they did not exist when
  8030. .IR ex
  8031. and
  8032. .IR vi
  8033. were originally written). Because the historical
  8034. .IR ex
  8035. evaluated
  8036. .BR read!
  8037. and
  8038. .BR read\0!
  8039. equivalently, there can be no optional way to force the read. POSIX.1\(hy2008
  8040. permits, but does not require, this behavior.
  8041. .SS "Recover"
  8042. .P
  8043. Some historical implementations of the editor permitted users to
  8044. recover the edit buffer contents from a previous edit session, and then
  8045. exit without saving those contents (or explicitly discarding them). The
  8046. intent of POSIX.1\(hy2008 in requiring that the edit buffer be treated as already
  8047. modified is to prevent this user error.
  8048. .SS "Rewind"
  8049. .P
  8050. Historical implementations supported the
  8051. .BR rewind
  8052. command when the user was editing the first file in the list; that is,
  8053. the file that the
  8054. .BR rewind
  8055. command would edit. POSIX.1\(hy2008 requires conformance to historical practice.
  8056. .SS "Substitute"
  8057. .P
  8058. Historically,
  8059. .IR ex
  8060. accepted an
  8061. .BR r
  8062. option to the
  8063. .BR s
  8064. command. The effect of the
  8065. .BR r
  8066. option was to use the last regular expression used in any command as
  8067. the pattern, the same as the
  8068. .BR ~
  8069. command. The
  8070. .BR r
  8071. option is not required by POSIX.1\(hy2008. Historically, the
  8072. .BR c
  8073. and
  8074. .BR g
  8075. options were toggled; for example, the command
  8076. .BR ":s/abc/def/"
  8077. was the same as
  8078. .BR "s/abc/def/ccccgggg" .
  8079. For simplicity of specification, POSIX.1\(hy2008 does not permit this behavior.
  8080. .P
  8081. The tilde command is often used to replace the last search RE. For
  8082. example, in the sequence:
  8083. .sp
  8084. .RS 4
  8085. .nf
  8086. s/red/blue/
  8087. /green
  8088. \(ti
  8089. .fi
  8090. .P
  8091. .RE
  8092. .P
  8093. the
  8094. .BR ~
  8095. command is equivalent to:
  8096. .sp
  8097. .RS 4
  8098. .nf
  8099. s/green/blue/
  8100. .fi
  8101. .P
  8102. .RE
  8103. .P
  8104. Historically,
  8105. .IR ex
  8106. accepted all of the following forms:
  8107. .sp
  8108. .RS 4
  8109. .nf
  8110. s/abc/def/
  8111. s/abc/def
  8112. s/abc/
  8113. s/abc
  8114. .fi
  8115. .P
  8116. .RE
  8117. .P
  8118. POSIX.1\(hy2008 requires conformance to this historical practice.
  8119. .P
  8120. The
  8121. .BR s
  8122. command presumes that the
  8123. .BR '\(ha'
  8124. character only occupies a single column in the display. Much of the
  8125. .IR ex
  8126. and
  8127. .IR vi
  8128. specification presumes that the
  8129. <space>
  8130. only occupies a single column in the display. There are no known
  8131. character sets for which this is not true.
  8132. .P
  8133. Historically, the final column position for the substitute commands was
  8134. based on previous column movements; a search for a pattern followed by
  8135. a substitution would leave the column position unchanged, while a 0
  8136. command followed by a substitution would change the column position to
  8137. the first non-\c
  8138. <blank>.
  8139. For consistency and simplicity of specification, POSIX.1\(hy2008 requires that
  8140. the final column position always be set to the first non-\c
  8141. <blank>.
  8142. .SS "Set"
  8143. .P
  8144. Historical implementations redisplayed all of the options for each
  8145. occurrence of the
  8146. .BR all
  8147. keyword. POSIX.1\(hy2008 permits, but does not require, this behavior.
  8148. .SS "Tag"
  8149. .P
  8150. No requirement is made as to where
  8151. .IR ex
  8152. and
  8153. .IR vi
  8154. shall look for the file referenced by the tag entry. Historical
  8155. practice has been to look for the path found in the
  8156. .BR tags
  8157. file, based on the current directory. A useful extension found in some
  8158. implementations is to look based on the directory containing the tags
  8159. file that held the entry, as well. No requirement is made as to which
  8160. reference for the tag in the tags file is used. This is deliberate, in
  8161. order to permit extensions such as multiple entries in a tags file for
  8162. a tag.
  8163. .P
  8164. Because users often specify many different tags files, some of which
  8165. need not be relevant or exist at any particular time, POSIX.1\(hy2008 requires
  8166. that error messages about problem tags files be displayed only if the
  8167. requested tag is not found, and then, only once for each time that the
  8168. .BR tag
  8169. edit option is changed.
  8170. .P
  8171. The requirement that the current edit buffer be unmodified is only
  8172. necessary if the file indicated by the tag entry is not the same as the
  8173. current file (as defined by the current pathname). Historically, the
  8174. file would be reloaded if the filename had changed, as well as if the
  8175. filename was different from the current pathname. For consistency and
  8176. simplicity of specification, POSIX.1\(hy2008 does not permit this behavior,
  8177. requiring that the name be the only factor in the decision.
  8178. .P
  8179. Historically,
  8180. .IR vi
  8181. only searched for tags in the current file from the current cursor to
  8182. the end of the file, and therefore, if the
  8183. .BR wrapscan
  8184. option was not set, tags occurring before the current cursor were not
  8185. found. POSIX.1\(hy2008 considers this a bug, and implementations are required to
  8186. search for the first occurrence in the file, regardless.
  8187. .SS "Undo"
  8188. .P
  8189. The
  8190. .BR undo
  8191. description deliberately uses the word ``modified''. The
  8192. .BR undo
  8193. command is not intended to undo commands that replace the contents of
  8194. the edit buffer, such as
  8195. .BR edit ,
  8196. .BR next ,
  8197. .BR tag ,
  8198. or
  8199. .BR recover .
  8200. .P
  8201. Cursor positioning after the
  8202. .BR undo
  8203. command was inconsistent in the historical
  8204. .IR vi ,
  8205. sometimes attempting to restore the original cursor position (\c
  8206. .BR global ,
  8207. .BR undo ,
  8208. and
  8209. .BR v
  8210. commands), and sometimes, in the presence of maps, placing the cursor
  8211. on the last line added or changed instead of the first. POSIX.1\(hy2008 requires
  8212. a simplified behavior for consistency and simplicity of specification.
  8213. .SS "Version"
  8214. .P
  8215. The
  8216. .BR version
  8217. command cannot be exactly specified since there is no widely-accepted
  8218. definition of what the version information should contain.
  8219. Implementations are encouraged to do something reasonably intelligent.
  8220. .SS "Write"
  8221. .P
  8222. Historically, the
  8223. .IR ex
  8224. and
  8225. .IR vi
  8226. message after a successful
  8227. .BR read
  8228. or
  8229. .BR write
  8230. command specified ``characters'', not ``bytes''. POSIX.1\(hy2008 requires that
  8231. the number of bytes be displayed, not the number of characters because
  8232. it may be difficult in multi-byte implementations to determine the
  8233. number of characters written. Implementations are encouraged to clarify
  8234. the message displayed to the user.
  8235. .P
  8236. Implementation-defined tests are permitted so that implementations
  8237. can make additional checks; for example, for locks or file modification
  8238. times.
  8239. .P
  8240. Historically, attempting to append to a nonexistent file caused an
  8241. error. It has been left unspecified in POSIX.1\(hy2008 to permit implementations
  8242. to let the
  8243. .BR write
  8244. succeed, so that the append semantics are similar to those of the
  8245. historical
  8246. .IR csh .
  8247. .P
  8248. Historical
  8249. .IR vi
  8250. permitted empty edit buffers to be written. However, since the way
  8251. .IR vi
  8252. got around dealing with ``empty'' files was to always have a line in
  8253. the edit buffer, no matter what, it wrote them as files of a single,
  8254. empty line. POSIX.1\(hy2008 does not permit this behavior.
  8255. .P
  8256. Historically,
  8257. .IR ex
  8258. restored standard output and standard error to their values as of when
  8259. .IR ex
  8260. was invoked, before writes to programs were performed. This could
  8261. disturb the terminal configuration as well as be a security issue for
  8262. some terminals. POSIX.1\(hy2008 does not permit this, requiring that the program
  8263. output be captured and displayed as if by the
  8264. .IR ex
  8265. .BR print
  8266. command.
  8267. .SS "Adjust Window"
  8268. .P
  8269. Historically, the line count was set to the value of the
  8270. .BR scroll
  8271. option if the type character was end-of-file. This feature was broken
  8272. on most historical implementations long ago, however, and is not
  8273. documented anywhere. For this reason, POSIX.1\(hy2008 is resolutely silent.
  8274. .P
  8275. Historically, the
  8276. .BR z
  8277. command was
  8278. <blank>-sensitive
  8279. and
  8280. .BR z\0+
  8281. and
  8282. .BR z\0\-
  8283. did different things than
  8284. .BR z+
  8285. and
  8286. .BR z\-
  8287. because the type could not be distinguished from a flag. (The commands
  8288. .BR z\0.
  8289. and
  8290. .BR z\0=
  8291. were historically invalid.) POSIX.1\(hy2008 requires conformance to this
  8292. historical practice.
  8293. .P
  8294. Historically, the
  8295. .BR z
  8296. command was further
  8297. <blank>-sensitive
  8298. in that the
  8299. .IR count
  8300. could not be
  8301. <blank>-delimited;
  8302. for example, the commands
  8303. .BR z=\05
  8304. and
  8305. .BR z\-\05
  8306. were also invalid. Because the
  8307. .IR count
  8308. is not ambiguous with respect to either the type character or the
  8309. flags, this is not permitted by POSIX.1\(hy2008.
  8310. .SS "Escape"
  8311. .P
  8312. Historically,
  8313. .IR ex
  8314. filter commands only read the standard output of the commands, letting
  8315. standard error appear on the terminal as usual. The
  8316. .IR vi
  8317. utility, however, read both standard output and standard error. POSIX.1\(hy2008
  8318. requires the latter behavior for both
  8319. .IR ex
  8320. and
  8321. .IR vi ,
  8322. for consistency.
  8323. .SS "Shift Left and Shift Right"
  8324. .P
  8325. Historically, it was possible to add shift characters to increase the
  8326. effect of the command; for example,
  8327. .BR <<<
  8328. outdented (or
  8329. .BR >>>
  8330. indented) the lines 3 levels of indentation instead of the default 1.
  8331. POSIX.1\(hy2008 requires conformance to historical practice.
  8332. .SS "<control>\(hyD"
  8333. .P
  8334. Historically, the
  8335. <control>\(hyD
  8336. command erased the prompt, providing the user with an unbroken
  8337. presentation of lines from the edit buffer. This is not required by
  8338. POSIX.1\(hy2008; implementations are encouraged to provide it if possible.
  8339. Historically, the
  8340. <control>\(hyD
  8341. command took, and then ignored, a
  8342. .IR count .
  8343. POSIX.1\(hy2008 does not permit this behavior.
  8344. .SS "Write Line Number"
  8345. .P
  8346. Historically, the
  8347. .IR ex
  8348. .BR =
  8349. command, when executed in
  8350. .IR ex
  8351. mode in an empty edit buffer, reported 0, and from open or visual mode,
  8352. reported 1. For consistency and simplicity of specification, POSIX.1\(hy2008 does
  8353. not permit this behavior.
  8354. .SS "Execute"
  8355. .P
  8356. Historically,
  8357. .IR ex
  8358. did not correctly handle the inclusion of text input commands (that is,
  8359. .BR append ,
  8360. .BR insert ,
  8361. and
  8362. .BR change )
  8363. in executed buffers. POSIX.1\(hy2008 does not permit this exclusion for
  8364. consistency.
  8365. .P
  8366. Historically, the logical contents of the buffer being executed did not
  8367. change if the buffer itself were modified by the commands being
  8368. executed; that is, buffer execution did not support self-modifying
  8369. code. POSIX.1\(hy2008 requires conformance to historical practice.
  8370. .P
  8371. Historically, the
  8372. .BR @
  8373. command took a range of lines, and the
  8374. .BR @
  8375. buffer was executed once per line, with the current line (\c
  8376. .BR '.' )
  8377. set to each specified line. POSIX.1\(hy2008 requires conformance to historical
  8378. practice.
  8379. .P
  8380. Some historical implementations did not notice if errors occurred
  8381. during buffer execution. This, coupled with the ability to specify a
  8382. range of lines for the
  8383. .IR ex
  8384. .BR @
  8385. command, makes it trivial to cause them to drop
  8386. .BR core .
  8387. POSIX.1\(hy2008 requires that implementations stop buffer execution if any error
  8388. occurs, if the specified line doesn't exist, or if the contents of the
  8389. edit buffer itself are replaced (for example, the buffer executes the
  8390. .IR ex
  8391. .BR :edit
  8392. command).
  8393. .SS "Regular Expressions in ex"
  8394. .P
  8395. Historical practice is that the characters in the replacement part of
  8396. the last
  8397. .BR s
  8398. command\(emthat is, those matched by entering a
  8399. .BR '\(ti'
  8400. in the regular expression\(emwere not further expanded by the regular
  8401. expression engine. So, if the characters contained the string
  8402. .BR \(dqa.,\(dq
  8403. they would match
  8404. .BR 'a'
  8405. followed by
  8406. .BR \(dq.,\(dq
  8407. and not
  8408. .BR 'a'
  8409. followed by any character. POSIX.1\(hy2008 requires conformance to historical
  8410. practice.
  8411. .SS "Edit Options in ex"
  8412. .P
  8413. The following paragraphs describe the historical behavior of some edit
  8414. options that were not, for whatever reason, included in POSIX.1\(hy2008.
  8415. Implementations are strongly encouraged to only use these names if the
  8416. functionality described here is fully supported.
  8417. .IP "\fBextended\fP" 10
  8418. The
  8419. .BR extended
  8420. edit option has been used in some implementations of
  8421. .IR vi
  8422. to provide extended regular expressions instead of basic regular
  8423. expressions This option was omitted from POSIX.1\(hy2008 because it is not
  8424. widespread historical practice.
  8425. .IP "\fBflash\fP" 10
  8426. The
  8427. .BR flash
  8428. edit option historically caused the screen to flash instead of beeping
  8429. on error. This option was omitted from POSIX.1\(hy2008 because it is not found in
  8430. some historical implementations.
  8431. .IP "\fBhardtabs\fP" 10
  8432. The
  8433. .BR hardtabs
  8434. edit option historically defined the number of columns between hardware
  8435. tab settings. This option was omitted from POSIX.1\(hy2008 because it was
  8436. believed to no longer be generally useful.
  8437. .IP "\fBmodeline\fP" 10
  8438. The
  8439. .BR modeline
  8440. (sometimes named
  8441. .BR modelines )
  8442. edit option historically caused
  8443. .IR ex
  8444. or
  8445. .IR vi
  8446. to read the five first and last lines of the file for editor commands.
  8447. This option is a security problem, and vendors are strongly encouraged
  8448. to delete it from historical implementations.
  8449. .IP "\fBopen\fP" 10
  8450. The
  8451. .BR open
  8452. edit option historically disallowed the
  8453. .IR ex
  8454. .BR open
  8455. and
  8456. .BR visual
  8457. commands. This edit option was omitted because these commands are
  8458. required by POSIX.1\(hy2008.
  8459. .IP "\fBoptimize\fP" 10
  8460. The
  8461. .BR optimize
  8462. edit option historically expedited text throughput by setting the
  8463. terminal to not do automatic
  8464. <carriage-return>
  8465. characters when printing more than one logical line of output. This
  8466. option was omitted from POSIX.1\(hy2008 because it was intended for terminals
  8467. without addressable cursors, which are rarely, if ever, still used.
  8468. .IP "\fBruler\fP" 10
  8469. The
  8470. .BR ruler
  8471. edit option has been used in some implementations of
  8472. .IR vi
  8473. to present a current row/column ruler for the user. This option was
  8474. omitted from POSIX.1\(hy2008 because it is not widespread historical practice.
  8475. .IP "\fBsourceany\fP" 10
  8476. The
  8477. .BR sourceany
  8478. edit option historically caused
  8479. .IR ex
  8480. or
  8481. .IR vi
  8482. to source start-up files that were owned by users other than the user
  8483. running the editor. This option is a security problem, and vendors are
  8484. strongly encouraged to remove it from their implementations.
  8485. .IP "\fBtimeout\fP" 10
  8486. The
  8487. .BR timeout
  8488. edit option historically enabled the (now standard) feature of only
  8489. waiting for a short period before returning keys that could be part of
  8490. a macro. This feature was omitted from POSIX.1\(hy2008 because its behavior is
  8491. now standard, it is not widely useful, and it was rarely documented.
  8492. .IP "\fBverbose\fP" 10
  8493. The
  8494. .BR verbose
  8495. edit option has been used in some implementations of
  8496. .IR vi
  8497. to cause
  8498. .IR vi
  8499. to output error messages for common errors; for example, attempting to
  8500. move the cursor past the beginning or end of the line instead of only
  8501. alerting the screen. (The historical
  8502. .IR vi
  8503. only alerted the terminal and presented no message for such errors. The
  8504. historical editor option
  8505. .BR terse
  8506. did not select when to present error messages, it only made existing
  8507. error messages more or less verbose.) This option was omitted from
  8508. POSIX.1\(hy2008 because it is not widespread historical practice; however,
  8509. implementors are encouraged to use it if they wish to provide error
  8510. messages for naive users.
  8511. .IP "\fBwraplen\fP" 10
  8512. The
  8513. .BR wraplen
  8514. edit option has been used in some implementations of
  8515. .IR vi
  8516. to specify an automatic margin measured from the left margin instead of
  8517. from the right margin. This is useful when multiple screen sizes are
  8518. being used to edit a single file. This option was omitted from POSIX.1\(hy2008
  8519. because it is not widespread historical practice; however, implementors
  8520. are encouraged to use it if they add this functionality.
  8521. .SS "autoindent, ai"
  8522. .P
  8523. Historically, the command
  8524. .BR 0a
  8525. did not do any autoindentation, regardless of the current indentation
  8526. of line 1. POSIX.1\(hy2008 requires that any indentation present in line 1 be
  8527. used.
  8528. .SS "autoprint, ap"
  8529. .P
  8530. Historically, the
  8531. .BR autoprint
  8532. edit option was not completely consistent or based solely on
  8533. modifications to the edit buffer. Exceptions were the
  8534. .BR read
  8535. command (when reading from a file, but not from a filter), the
  8536. .BR append ,
  8537. .BR change ,
  8538. .BR insert ,
  8539. .BR global ,
  8540. and
  8541. .BR v
  8542. commands, all of which were not affected by
  8543. .BR autoprint ,
  8544. and the
  8545. .BR tag
  8546. command, which was affected by
  8547. .BR autoprint .
  8548. POSIX.1\(hy2008 requires conformance to historical practice.
  8549. .P
  8550. Historically, the
  8551. .BR autoprint
  8552. option only applied to the last of multiple commands entered using
  8553. <vertical-line>
  8554. delimiters; for example,
  8555. .BR delete
  8556. <newline>
  8557. was affected by
  8558. .BR autoprint ,
  8559. but
  8560. .BR delete|version
  8561. <newline>
  8562. was not. POSIX.1\(hy2008 requires conformance to historical practice.
  8563. .SS "autowrite, aw"
  8564. .P
  8565. Appending the
  8566. .BR '!'
  8567. character to the
  8568. .IR ex
  8569. .BR next
  8570. command to avoid performing an automatic write was not supported in
  8571. historical implementations. POSIX.1\(hy2008 requires that the behavior match the
  8572. other
  8573. .IR ex
  8574. commands for consistency.
  8575. .SS "ignorecase, ic"
  8576. .P
  8577. Historical implementations of case-insensitive matching (the
  8578. .BR ignorecase
  8579. edit option) lead to counter-intuitive situations when uppercase
  8580. characters were used in range expressions. Historically, the process
  8581. was as follows:
  8582. .IP " 1." 4
  8583. Take a line of text from the edit buffer.
  8584. .IP " 2." 4
  8585. Convert uppercase to lowercase in text line.
  8586. .IP " 3." 4
  8587. Convert uppercase to lowercase in regular expressions, except in
  8588. character class specifications.
  8589. .IP " 4." 4
  8590. Match regular expressions against text.
  8591. .P
  8592. This would mean that, with
  8593. .BR ignorecase
  8594. in effect, the text:
  8595. .sp
  8596. .RS 4
  8597. .nf
  8598. The cat sat on the mat
  8599. .fi
  8600. .P
  8601. .RE
  8602. .P
  8603. would be matched by
  8604. .sp
  8605. .RS 4
  8606. .nf
  8607. /\(hathe/
  8608. .fi
  8609. .P
  8610. .RE
  8611. .P
  8612. but not by:
  8613. .sp
  8614. .RS 4
  8615. .nf
  8616. /\(ha[A-Z]he/
  8617. .fi
  8618. .P
  8619. .RE
  8620. .P
  8621. For consistency with other commands implementing regular expressions,
  8622. POSIX.1\(hy2008 does not permit this behavior.
  8623. .SS "paragraphs, para"
  8624. .P
  8625. The ISO\ POSIX\(hy2:\|1993 standard made the default
  8626. .BR paragraphs
  8627. and
  8628. .BR sections
  8629. edit options implementation-defined, arguing they were historically
  8630. oriented to the UNIX system
  8631. .IR troff
  8632. text formatter, and a ``portable user'' could use the
  8633. .BR { ,
  8634. .BR } ,
  8635. .BR [[ ,
  8636. .BR ]] ,
  8637. .BR ( ,
  8638. and
  8639. .BR )
  8640. commands in open or visual mode and have the cursor stop in unexpected
  8641. places. POSIX.1\(hy2008 specifies their values in the POSIX locale because the
  8642. unusual grouping (they only work when grouped into two characters at a
  8643. time) means that they cannot be used for general-purpose movement,
  8644. regardless.
  8645. .SS "readonly"
  8646. .P
  8647. Implementations are encouraged to provide the best possible information
  8648. to the user as to the read-only status of the file, with the exception
  8649. that they should not consider the current special privileges of the
  8650. process. This provides users with a safety net because they must force
  8651. the overwrite of read-only files, even when running with additional
  8652. privileges.
  8653. .P
  8654. The
  8655. .BR readonly
  8656. edit option specification largely conforms to historical practice. The
  8657. only difference is that historical implementations did not notice that
  8658. the user had set the
  8659. .BR readonly
  8660. edit option in cases where the file was already marked read-only for
  8661. some reason, and would therefore reinitialize the
  8662. .BR readonly
  8663. edit option the next time the contents of the edit buffer were
  8664. replaced. This behavior is disallowed by POSIX.1\(hy2008.
  8665. .SS "report"
  8666. .P
  8667. The requirement that lines copied to a buffer interact differently than
  8668. deleted lines is historical practice. For example, if the
  8669. .BR report
  8670. edit option is set to 3, deleting 3 lines will cause a report to be
  8671. written, but 4 lines must be copied before a report is written.
  8672. .P
  8673. The requirement that the
  8674. .IR ex
  8675. .BR global ,
  8676. .BR v ,
  8677. .BR open ,
  8678. .BR undo ,
  8679. and
  8680. .BR visual
  8681. commands present reports based on the total number of lines added or
  8682. deleted during the command execution, and that commands executed by the
  8683. .BR global
  8684. and
  8685. .BR v
  8686. commands not present reports, is historical practice. POSIX.1\(hy2008 extends
  8687. historical practice by requiring that buffer execution be treated
  8688. similarly. The reasons for this are two-fold. Historically, only the
  8689. report by the last command executed from the buffer would be seen by
  8690. the user, as each new report would overwrite the last. In addition, the
  8691. standard developers believed that buffer execution had more in common
  8692. with
  8693. .BR global
  8694. and
  8695. .BR v
  8696. commands than it did with other
  8697. .IR ex
  8698. commands, and should behave similarly, for consistency and simplicity
  8699. of specification.
  8700. .SS "showmatch, sm"
  8701. .P
  8702. The length of time the cursor spends on the matching character is
  8703. unspecified because the timing capabilities of systems are often
  8704. inexact and variable. The time should be long enough for the user to
  8705. notice, but not long enough for the user to become annoyed. Some
  8706. implementations of
  8707. .IR vi
  8708. have added a
  8709. .BR matchtime
  8710. option that permits users to set the number of 0,1 second intervals the
  8711. cursor pauses on the matching character.
  8712. .SS "showmode"
  8713. .P
  8714. The
  8715. .BR showmode
  8716. option has been used in some historical implementations of
  8717. .IR ex
  8718. and
  8719. .IR vi
  8720. to display the current editing mode when in open or visual mode. The
  8721. editing modes have generally included ``command'' and ``input'', and
  8722. sometimes other modes such as ``replace'' and ``change''. The string
  8723. was usually displayed on the bottom line of the screen at the far
  8724. right-hand corner. In addition, a preceding
  8725. .BR '*'
  8726. character often denoted whether the contents of the edit buffer had
  8727. been modified. The latter display has sometimes been part of the
  8728. .BR showmode
  8729. option, and sometimes based on another option. This option was not
  8730. available in the 4 BSD historical implementation of
  8731. .IR vi ,
  8732. but was viewed as generally useful, particularly to novice users, and
  8733. is required by POSIX.1\(hy2008.
  8734. .P
  8735. The
  8736. .BR smd
  8737. shorthand for the
  8738. .BR showmode
  8739. option was not present in all historical implementations of the editor.
  8740. POSIX.1\(hy2008 requires it, for consistency.
  8741. .P
  8742. Not all historical implementations of the editor displayed a mode
  8743. string for command mode, differentiating command mode from text input
  8744. mode by the absence of a mode string. POSIX.1\(hy2008 permits this behavior for
  8745. consistency with historical practice, but implementations are
  8746. encouraged to provide a display string for both modes.
  8747. .SS "slowopen"
  8748. .P
  8749. Historically, the
  8750. .BR slowopen
  8751. option was automatically set if the terminal baud rate was less than
  8752. 1\|200 baud, or if the baud rate was 1\|200 baud and the
  8753. .BR redraw
  8754. option was not set. The
  8755. .BR slowopen
  8756. option had two effects. First, when inserting characters in the middle
  8757. of a line, characters after the cursor would not be pushed ahead, but
  8758. would appear to be overwritten. Second, when creating a new line of
  8759. text, lines after the current line would not be scrolled down, but
  8760. would appear to be overwritten. In both cases, ending text input mode
  8761. would cause the screen to be refreshed to match the actual contents of
  8762. the edit buffer. Finally, terminals that were sufficiently intelligent
  8763. caused the editor to ignore the
  8764. .BR slowopen
  8765. option. POSIX.1\(hy2008 permits most historical behavior, extending historical
  8766. practice to require
  8767. .BR slowopen
  8768. behaviors if the edit option is set by the user.
  8769. .SS "tags"
  8770. .P
  8771. The default path for tags files is left unspecified as implementations
  8772. may have their own
  8773. .BR tags
  8774. implementations that do not correspond to the historical ones. The
  8775. default
  8776. .BR tags
  8777. option value should probably at least include the file
  8778. .BR ./tags .
  8779. .SS "term"
  8780. .P
  8781. Historical implementations of
  8782. .IR ex
  8783. and
  8784. .IR vi
  8785. ignored changes to the
  8786. .BR term
  8787. edit option after the initial terminal information was loaded. This is
  8788. permitted by POSIX.1\(hy2008; however, implementations are encouraged to permit
  8789. the user to modify their terminal type at any time.
  8790. .SS "terse"
  8791. .P
  8792. Historically, the
  8793. .BR terse
  8794. edit option optionally provided a shorter, less descriptive error
  8795. message, for some error messages. This is permitted, but not required,
  8796. by POSIX.1\(hy2008. Historically, most common visual mode errors (for example,
  8797. trying to move the cursor past the end of a line) did not result in an
  8798. error message, but simply alerted the terminal. Implementations wishing
  8799. to provide messages for novice users are urged to do so based on the
  8800. .BR edit
  8801. option
  8802. .BR verbose ,
  8803. and not
  8804. .BR terse .
  8805. .SS "window"
  8806. .P
  8807. In historical implementations, the default for the
  8808. .BR window
  8809. edit option was based on the baud rate as follows:
  8810. .IP " 1." 4
  8811. If the baud rate was less than 1\|200, the
  8812. .BR edit
  8813. option
  8814. .BR w300
  8815. set the window value; for example, the line:
  8816. .RS 4
  8817. .sp
  8818. .RS 4
  8819. .nf
  8820. set w300=12
  8821. .fi
  8822. .P
  8823. .RE
  8824. .P
  8825. would set the window option to 12 if the baud rate was less than
  8826. 1\|200.
  8827. .RE
  8828. .IP " 2." 4
  8829. If the baud rate was equal to 1\|200, the
  8830. .BR edit
  8831. option
  8832. .BR w1200
  8833. set the window value.
  8834. .IP " 3." 4
  8835. If the baud rate was greater than 1\|200, the
  8836. .BR edit
  8837. option
  8838. .BR w9600
  8839. set the window value.
  8840. .P
  8841. The
  8842. .BR w300 ,
  8843. .BR w1200 ,
  8844. and
  8845. .BR w9600
  8846. options do not appear in POSIX.1\(hy2008 because of their dependence on specific
  8847. baud rates.
  8848. .P
  8849. In historical implementations, the size of the window displayed by
  8850. various commands was related to, but not necessarily the same as, the
  8851. .BR window
  8852. edit option. For example, the size of the window was set by the
  8853. .IR ex
  8854. command
  8855. .BR "visual 10" ,
  8856. but it did not change the value of the
  8857. .BR window
  8858. edit option. However, changing the value of the
  8859. .BR window
  8860. edit option did change the number of lines that were displayed when the
  8861. screen was repainted. POSIX.1\(hy2008 does not permit this behavior in the
  8862. interests of consistency and simplicity of specification, and requires
  8863. that all commands that change the number of lines that are displayed do
  8864. it by setting the value of the
  8865. .BR window
  8866. edit option.
  8867. .SS "wrapmargin, wm"
  8868. .P
  8869. Historically, the
  8870. .BR wrapmargin
  8871. option did not affect maps inserting characters that also had
  8872. associated
  8873. .IR count s;
  8874. for example
  8875. .BR ":map\0K\05aABC\0DEF" .
  8876. Unfortunately, there are widely used maps that depend on this behavior.
  8877. For consistency and simplicity of specification, POSIX.1\(hy2008 does not permit
  8878. this behavior.
  8879. .P
  8880. Historically,
  8881. .BR wrapmargin
  8882. was calculated using the column display width of all characters on the
  8883. screen. For example, an implementation using
  8884. .BR \(dq\(haI\(dq
  8885. to represent
  8886. <tab>
  8887. characters when the
  8888. .BR list
  8889. edit option was set, where
  8890. .BR '\(ha'
  8891. and
  8892. .BR 'I'
  8893. each took up a single column on the screen, would calculate the
  8894. .BR wrapmargin
  8895. based on a value of 2 for each
  8896. <tab>.
  8897. The
  8898. .BR number
  8899. edit option similarly changed the effective length of the line as well.
  8900. POSIX.1\(hy2008 requires conformance to historical practice.
  8901. .P
  8902. Earlier versions of this standard allowed for implementations
  8903. with bytes other than eight bits, but this has been modified in this
  8904. version.
  8905. .SH "FUTURE DIRECTIONS"
  8906. None.
  8907. .SH "SEE ALSO"
  8908. .IR "Section 2.9.1.1" ", " "Command Search and Execution",
  8909. .IR "\fIctags\fR\^",
  8910. .IR "\fIed\fR\^",
  8911. .IR "\fIsed\fR\^",
  8912. .IR "\fIsh\fR\^",
  8913. .IR "\fIstty\fR\^",
  8914. .IR "\fIvi\fR\^"
  8915. .P
  8916. The Base Definitions volume of POSIX.1\(hy2017,
  8917. .IR "Table 5-1" ", " "Escape Sequences and Associated Actions",
  8918. .IR "Chapter 8" ", " "Environment Variables",
  8919. .IR "Section 9.3" ", " "Basic Regular Expressions",
  8920. .IR "Section 12.2" ", " "Utility Syntax Guidelines"
  8921. .P
  8922. The System Interfaces volume of POSIX.1\(hy2017,
  8923. .IR "\fIaccess\fR\^(\|)"
  8924. .\"
  8925. .SH COPYRIGHT
  8926. Portions of this text are reprinted and reproduced in electronic form
  8927. from IEEE Std 1003.1-2017, Standard for Information Technology
  8928. -- Portable Operating System Interface (POSIX), The Open Group Base
  8929. Specifications Issue 7, 2018 Edition,
  8930. Copyright (C) 2018 by the Institute of
  8931. Electrical and Electronics Engineers, Inc and The Open Group.
  8932. In the event of any discrepancy between this version and the original IEEE and
  8933. The Open Group Standard, the original IEEE and The Open Group Standard
  8934. is the referee document. The original Standard can be obtained online at
  8935. http://www.opengroup.org/unix/online.html .
  8936. .PP
  8937. Any typographical or formatting errors that appear
  8938. in this page are most likely
  8939. to have been introduced during the conversion of the source files to
  8940. man page format. To report such errors, see
  8941. https://www.kernel.org/doc/man-pages/reporting_bugs.html .