EExx//EEddiitt CCoommmmaanndd SSuummmmaarryy ((VVeerrssiioonn 22..00)) _E_x and _e_d_i_t are text edi- During an editing session tors, used for creating and there are two usual modes of modifying files of text on the operation: _c_o_m_m_a_n_d mode and UNIX computer system. _E_d_i_t is _t_e_x_t _i_n_p_u_t mode. (This disre- a variant of _e_x with features gards, for the moment, _o_p_e_n designed to make it less com- and _v_i_s_u_a_l modes, discussed plicated to learn and use. In below.) In command mode, the terms of command syntax and editor issues a colon prompt effect the editors are essen- (:) to show that it is ready tially identical, and this to accept and execute a com- command summary applies to mand. In text input mode, on both. the other hand, there is no The summary is meant as a prompt and the editor merely quick reference for users accepts text to be added to already acquainted with _e_d_i_t the buffer. Text input mode or _e_x. Fuller explanations of is initiated by the commands the editors are available in _a_p_p_e_n_d, _i_n_s_e_r_t, and _c_h_a_n_g_e, the documents _E_d_i_t_: _A _T_u_t_o_r_i_a_l and is terminated by typing a (a self-teaching introduction) period as the first and only and the _E_x _R_e_f_e_r_e_n_c_e _M_a_n_u_a_l character on a line. (the comprehensive reference LLiinnee NNuummbbeerrss aanndd CCoommmmaanndd SSyynn-- source for both _e_d_i_t and _e_x). ttaaxx Both of these writeups are The editor keeps track of available in the Computing lines of text in the buffer by Services Library. numbering them consecutively In the examples included starting with 1 and renumber- with the summary, commands and ing as lines are added or text entered by the user are deleted. At any given time printed in bboollddffaaccee to distin- the editor is positioned at guish them from responses one of these lines; this posi- printed by the computer. tion is called the _c_u_r_r_e_n_t TThhee EEddiittoorr BBuuffffeerr _l_i_n_e. Generally, commands In order to perform its that change the contents of tasks the editor sets aside a the buffer print the new cur- temporary work space, called a rent line at the end of their _b_u_f_f_e_r, separate from the execution. user's permanent file. Before Most commands can be pre- starting to work on an exist- ceded by one or two line-num- ing file the editor makes a ber addresses which indicate copy of it in the buffer, the lines to be affected. If leaving the original one number is given the com- untouched. All editing mand operates on that line changes are made to the buffer only; if two, on an inclusive copy, which must then be writ- range of lines. Commands that ten back to the permanent file can take line-number prefixes in order to update the old also assume default prefixes version. The buffer disap- if none are given. The pears at the end of the edit- default assumed by each com- ing session. mand is designed to make it EEddiittiinngg:: CCoommmmaanndd aanndd TTeexxtt convenient to use in many IInnppuutt MMooddeess instances without any line- number prefix. For the most Computing Services, U.C. Berkeley April 3, 1979 part, a command used without a following additional special prefix operates on the current characters: line, though exceptions to .. && ** [[ ]] ~~ this rule should be noted. To use one of the special The _p_r_i_n_t command by itself, characters as its simple for instance, causes one line, graphic representation rather the current line, to be than with its special meaning, printed at the terminal. precede it by a backslash (\). The summary shows the num- The backslash always has a ber of line addresses that can special meaning. be prefixed to each command as well as the defaults assumed if they are omitted. For example, _(_._,_._) means that up to 2 line-numbers may be given, and that if none is given the command operates on the current line. (In the address prefix notation, ``.'' stands for the current line and ``$'' stands for the last line of the buffer.) If no such notation appears, no line-number prefix may be used. Some commands take trailing information; only the more important instances of this are mentioned in the summary. OOppeenn aanndd VViissuuaall MMooddeess Besides command and text input modes, _e_x and _e_d_i_t pro- vide on some CRT terminals other modes of editing, _o_p_e_n and _v_i_s_u_a_l. In these modes the cursor can be moved to individual words or characters in a line. The commands then given are very different from the standard editor commands; most do not appear on the screen when typed. _A_n _I_n_t_r_o_- _d_u_c_t_i_o_n _t_o _D_i_s_p_l_a_y _E_d_i_t_i_n_g _w_i_t_h _V_i provides a full dis- cussion. SSppeecciiaall CChhaarraacctteerrss Some characters take on special meanings when used in context searches and in pat- terns given to the _s_u_b_s_t_i_t_u_t_e command. For _e_d_i_t, these are ``^'' and ``$'', meaning the beginning and end of a line, respectively. _E_x has the Computing Services, U.C. Berkeley April 3, 1979 Name Abbr Description Examples (.)aappppeenndd aa Begins text input mode, adding :aa lines to the buffer after the TThhrreeee lliinneess ooff tteexxtt line specified. Appending con- aarree aaddddeedd ttoo tthhee bbuuffffeerr tinues until ``.'' is typed aafftteerr tthhee ccuurrrreenntt lliinnee.. alone at the beginning of a .. new line, followed by a car- : riage return. _0_a places lines at the beginning of the buffer. (.,.)cchhaannggee cc Deletes indicated line(s) and :55,,66cc initiates text input mode to LLiinneess 55 aanndd 66 aarree replace them with new text ddeelleetteedd aanndd rreeppllaacceedd bbyy which follows. New text is tthheessee tthhrreeee lliinneess.. terminated the same way as .. with _a_p_p_e_n_d. : (.,.)ccooppyy _a_d_d_r ccoo Places a copy of the specified :88,,1122ccoo 2255 lines after the line indicated Last line copied is printed by _a_d_d_r. The example places a : copy of lines 8 through 12, inclusive, after line 25. (.,.)ddeelleettee dd Removes lines from the buffer :1133,,1155dd and prints the current line New current line is printed after the deletion. : eeddiitt _f_i_l_e ee Clears the editor buffer and :ee cchh1100 eeddiitt!! _f_i_l_e ee!! then copies into it the named No write since last change _f_i_l_e, which becomes the cur- :ee!! cchh1100 rent file. This is a way of "ch10" 3 lines, 62 characters shifting to a different file : without leaving the editor. The editor issues a warning message if this command is used before saving changes made to the file already in the buffer; using the form ee!! overrides this protective mechanism. ffiillee _n_a_m_e ff If followed by a _n_a_m_e, renames :ff cchh99 the current file to _n_a_m_e. If "ch9" [Modified] 3 lines ... used without _n_a_m_e, prints the :ff name of the current file. "ch9" [Modified] 3 lines ... : Computing Services, U.C. Berkeley April 3, 1979 (1,$)gglloobbaall gg gglloobbaall//_p_a_t_t_e_r_n//_c_o_m_m_a_n_d_s :gg//nnoonnsseennssee//dd (1,$)gglloobbaall!! gg!! or vv Searches the entire buffer : (unless a smaller range is specified by line-number pre- fixes) and executes _c_o_m_m_a_n_d_s on every line with an expres- sion matching _p_a_t_t_e_r_n. The second form, abbreviated either gg!! or vv, executes _c_o_m_- _m_a_n_d_s on lines that _d_o _n_o_t contain the expression _p_a_t_- _t_e_r_n. (.)iinnsseerrtt ii Inserts new lines of text :11ii immediately before the speci- TThheessee lliinneess ooff tteexxtt wwiillll fied line. Differs from bbee aaddddeedd pprriioorr ttoo lliinnee 11.. _a_p_p_e_n_d only in that text is .. placed before, rather than : after, the indicated line. In other words, 11ii has the same effect as 00aa. (.,.+1)jjooiinn jj Join lines together, adjusting :22,,55jj white space (spaces and tabs) Resulting line is printed as necessary. : Computing Services, U.C. Berkeley April 3, 1979 Name Abbr Description Examples (.,.)lliisstt ll Prints lines in a more unam- :99ll biguous way than the _p_r_i_n_t This is line 9$ command does. The end of a : line, for example, is marked with a ``$'', and tabs printed as ``^I''. (.,.)mmoovvee _a_d_d_r mm Moves the specified lines to a :1122,,1155mm 2255 position after the line indi- New current line is printed cated by _a_d_d_r. : (.,.)nnuummbbeerr nnuu Prints each line preceded by :nnuu its buffer line number. 10 This is line 10 : (.)ooppeenn oo Too involved to discuss here, but if you enter open mode accidentally, press the ESC key followed by qq to get back into normal editor command mode. _E_d_i_t is designed to prevent accidental use of the open command. pprreesseerrvvee pprree Saves a copy of the current :pprreesseerrvvee buffer contents as though the File preserved. system had just crashed. This : is for use in an emergency when a _w_r_i_t_e command has failed and you don't know how else to save your work.|- (.,.)pprriinntt pp Prints the text of line(s). :++22,,++33pp The second and third lines after the current line : ----------- |- You should seek assistance from a system administrator as soon as possible after saving a file with the _p_r_e_s_e_r_v_e command, because the preserved copy of the file is saved in a directory used to store temporary files, and thus, the preserved copy may only be available for a short period of time. Computing Services, U.C. Berkeley April 3, 1979 qquuiitt qq Ends the editing session. You :qq qquuiitt!! qq!! will receive a warning if you No write since last change have changed the buffer since :qq!! last writing its contents to % the file. In this event you must either type ww to write, or type qq!! to exit from the editor without saving your changes. (.)rreeaadd _f_i_l_e rr Places a copy of _f_i_l_e in the :00rr nneewwffiillee buffer after the specified "newfile" 5 lines, 86 characters line. Address 0 is permissi- : ble and causes the copy of _f_i_l_e to be placed at the beginning of the buffer. The _r_e_a_d command does not erase any text already in the buffer. If no line number is specified, _f_i_l_e is placed after the current line. rreeccoovveerr _f_i_l_e rreecc Retrieves a copy of the editor buffer after a system crash, editor crash, phone line dis- connection, or _p_r_e_s_e_r_v_e com- mand. (.,.)ssuubbssttiittuuttee ss ssuubbssttiittuuttee//_p_a_t_t_e_r_n//_r_e_p_l_a_c_e_m_e_n_t// :33pp ssuubbssttiittuuttee//_p_a_t_t_e_r_n//_r_e_p_l_a_c_e_m_e_n_t//ggcc Line 3 contains a misstake Replaces the first occurrence :ss//mmiissssttaakkee//mmiissttaakkee// of _p_a_t_t_e_r_n on a line with Line 3 contains a mistake _r_e_p_l_a_c_e_m_e_n_t. Including a gg : after the command changes all occurrences of _p_a_t_t_e_r_n on the line. The cc option allows the user to confirm each substitu- tion before it is made; see the manual for details. Computing Services, U.C. Berkeley April 3, 1979 Name Abbr Description Examples uunnddoo uu Reverses the changes made in :11,,1155dd the buffer by the last buffer- 15 lines deleted editing command. Note that new line number 1 is printed this example contains a noti- :uu fication about the number of 15 more lines in file ... lines affected. old line number 1 is printed : (1,$)wwrriittee _f_i_l_e ww Copies data from the buffer :ww (1,$)wwrriittee!! _f_i_l_e ww!! onto a permanent file. If no "file7" 64 lines, 1122 characters _f_i_l_e is named, the current :ww ffiillee88 filename is used. The file is "file8" File exists ... automatically created if it :ww!! ffiillee88 does not yet exist. A "file8" 64 lines, 1122 characters response containing the number : of lines and characters in the file indicates that the write has been completed success- fully. The editor's built-in protections against overwrit- ing existing files will in some circumstances inhibit a write. The form ww!! forces the write, confirming that an existing file is to be over- written. (.)zz _c_o_u_n_t zz Prints a screen full of text starting with the line indi- cated; or, if _c_o_u_n_t is speci- fied, prints that number of lines. Variants of the _z com- mand are described in the man- ual. !!_c_o_m_m_a_n_d Executes the remainder of the :!!ddaattee line after !! as a UNIX com- Fri Jun 9 12:15:11 PDT 1978 mand. The buffer is unchanged ! by this, and control is : returned to the editor when the execution of _c_o_m_m_a_n_d is complete. control-d Prints the next _s_c_r_o_l_l of text, normally half of a screen. See the manual for details of the _s_c_r_o_l_l option. Computing Services, U.C. Berkeley April 3, 1979 (.+1) An address alone followed by a : carriage return causes the the line after the current line line to be printed. A car- : riage return by itself prints the line following the current line. //_p_a_t_t_e_r_n// Searches for the next line in ://TThhiiss ppaatttteerrnn// which _p_a_t_t_e_r_n occurs and This pattern next occurs here. prints it. : //// Repeats the most recent search. ://// This pattern also occurs here. : ??_p_a_t_t_e_r_n?? Searches in the reverse direction for _p_a_t_t_e_r_n. ???? Repeats the most recent search, moving in the reverse direction through the buffer. Computing Services, U.C. Berkeley April 3, 1979