





Ex/Edit Command Summary (Version 2.0)

                                      During an  editing  session
   Ex  and  edit are text edi-     there  are  two usual modes of
tors, used  for  creating  and     operation:  command  mode  and
modifying files of text on the     text input mode.  (This disre-
UNIX computer system.  Edit is     gards, for  the  moment,  open
a  variant of ex with features     and  visual  modes,  discussed
designed to make it less  com-     below.)  In command mode,  the
plicated to learn and use.  In     editor  issues  a colon prompt
terms of  command  syntax  and     (:) to show that it  is  ready
effect  the editors are essen-     to  accept  and execute a com-
tially  identical,  and   this     mand.  In text input mode,  on
command   summary  applies  to     the  other  hand,  there is no
both.                              prompt and the  editor  merely
   The summary is meant  as  a     accepts  text  to  be added to
quick   reference   for  users     the buffer.  Text  input  mode
already acquainted  with  edit     is  initiated  by the commands
or ex.  Fuller explanations of     append,  insert,  and  change,
the editors are  available  in     and  is terminated by typing a
the documents Edit: A Tutorial     period as the first  and  only
(a self-teaching introduction)     character on a line.
and  the  Ex  Reference Manual     Line  Numbers and Command Syn-
(the  comprehensive  reference     tax
source  for both edit and ex).        The editor keeps  track  of
Both  of  these  writeups  are     lines of text in the buffer by
available   in  the  Computing     numbering  them  consecutively
Services Library.                  starting  with 1 and renumber-
   In  the  examples  included     ing  as  lines  are  added  or
with the summary, commands and     deleted.   At  any  given time
text entered by the  user  are     the editor  is  positioned  at
printed in boldface to distin-     one of these lines; this posi-
guish  them   from   responses     tion  is  called  the  current
printed by the computer.           line.    Generally,   commands
The Editor Buffer                  that change  the  contents  of
   In  order  to  perform  its     the  buffer print the new cur-
tasks the editor sets aside  a     rent line at the end of  their
temporary work space, called a     execution.
buffer,  separate   from   the        Most  commands  can be pre-
user's permanent file.  Before     ceded by one or two  line-num-
starting to work on an  exist-     ber  addresses  which indicate
ing  file  the  editor makes a     the lines to be affected.   If
copy  of  it  in  the  buffer,     one  number  is given the com-
leaving      the      original     mand  operates  on  that  line
untouched.     All     editing     only;  if two, on an inclusive
changes are made to the buffer     range of lines.  Commands that
copy, which must then be writ-     can  take line-number prefixes
ten back to the permanent file     also assume  default  prefixes
in order  to  update  the  old     if   none   are   given.   The
version.   The  buffer  disap-     default assumed by  each  com-
pears at the end of the  edit-     mand  is  designed  to make it
ing session.                       convenient  to  use  in   many
Editing:   Command   and  Text     instances  without  any  line-
Input Modes                        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  print  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.
Open and Visual Modes
   Besides  command  and  text
input  modes, ex and edit pro-
vide  on  some  CRT  terminals
other  modes  of editing, open
and visual.   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.  An Intro-
duction  to  Display   Editing
with  Vi  provides a full dis-
cussion.
Special Characters
   Some  characters  take   on
special  meanings when used in
context searches and  in  pat-
terns  given to the substitute
command.  For edit, these  are
``^''  and  ``$'', meaning the
beginning and end of  a  line,
respectively.    Ex   has  the



Computing Services, U.C. Berkeley                   April 3, 1979










     Name        Abbr           Description                      Examples


(.)append        a     Begins text input mode, adding   :a
                       lines to the buffer after  the   Three lines of text
                       line specified. Appending con-   are added to the buffer
                       tinues until  ``.''  is  typed   after the current line.
                       alone  at  the  beginning of a   .
                       new line, followed by  a  car-   :
                       riage  return. 0a places lines
                       at  the   beginning   of   the
                       buffer.

(.,.)change      c     Deletes  indicated line(s) and   :5,6c
                       initiates text input  mode  to   Lines 5 and 6 are
                       replace  them  with  new  text   deleted and replaced by
                       which follows.   New  text  is   these three lines.
                       terminated  the  same  way  as   .
                       with append.                     :

(.,.)copy addr   co    Places a copy of the specified   :8,12co 25
                       lines after the line indicated   Last line copied is printed
                       by addr.  The example places a   :
                       copy  of  lines  8 through 12,
                       inclusive, after line 25.

(.,.)delete      d     Removes lines from the  buffer   :13,15d
                       and  prints  the  current line   New current line is printed
                       after the deletion.              :


edit file      e        Clears the editor  buffer  and   :e ch10
edit! file     e!       then  copies into it the named   No write since last change
                        file, which becomes  the  cur-   :e! ch10
                        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  e!
                        overrides    this   protective
                        mechanism.

file name      f        If followed by a name, renames   :f ch9
                        the  current file to name.  If   "ch9" [Modified] 3 lines ...
                        used without name, prints  the   :f
                        name of the current file.        "ch9" [Modified] 3 lines ...
                                                         :





Computing Services, U.C. Berkeley                   April 3, 1979








(1,$)global    g        global/pattern/commands          :g/nonsense/d
(1,$)global!   g! or v  Searches   the  entire  buffer   :
                        (unless  a  smaller  range  is
                        specified  by line-number pre-
                        fixes) and  executes  commands
                        on  every line with an expres-
                        sion  matching  pattern.   The
                        second    form,    abbreviated
                        either g! or v, executes  com-
                        mands  on  lines  that  do not
                        contain  the  expression  pat-
                        tern.

(.)insert      i        Inserts   new  lines  of  text   :1i
                        immediately before the  speci-   These lines of text will
                        fied   line.    Differs   from   be added prior to line 1.
                        append only in  that  text  is   .
                        placed   before,  rather  than   :
                        after, the indicated line.  In
                        other  words,  1i has the same
                        effect as 0a.

(.,.+1)join    j        Join lines together, adjusting   :2,5j
                        white  space (spaces and tabs)   Resulting line is printed
                        as necessary.                    :
































Computing Services, U.C. Berkeley                   April 3, 1979








   Name      Abbr           Description                  Examples


(.,.)list    l     Prints lines in a  more  unam-   :9l
                   biguous  way  than  the  print   This is line 9$
                   command does.  The  end  of  a   :
                   line,  for  example, is marked
                   with a ``$'', and tabs printed
                   as ``^I''.


(.,.)move addr   m     Moves the specified lines to a   :12,15m 25
                       position after the line  indi-   New current line is printed
                       cated by addr.                   :

(.,.)number      nu    Prints  each  line preceded by   :nu
                       its buffer line number.            10  This is line 10
                                                        :

(.)open          o     Too involved to discuss  here,
                       but  if  you  enter  open mode
                       accidentally,  press  the  ESC
                       key  followed by q to get back
                       into  normal  editor   command
                       mode.   Edit  is  designed  to
                       prevent accidental use of  the
                       open command.

preserve         pre   Saves  a  copy  of the current   :preserve
                       buffer contents as though  the   File preserved.
                       system had just crashed.  This   :
                       is for  use  in  an  emergency
                       when   a   write  command  has
                       failed and you don't know  how
                       else to save your work.

(.,.)print       p     Prints the text of line(s).      :+2,+3p
                                                        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  preserve  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








quit              q     Ends the editing session.  You      :q
quit!             q!    will receive a warning if  you      No write since last change
                        have  changed the buffer since      :q!
                        last writing its  contents  to      %
                        the  file.  In  this event you
                        must either type w  to  write,
                        or  type  q!  to exit from the
                        editor  without  saving   your
                        changes.

(.)read file      r     Places  a  copy of file in the      :0r newfile
                        buffer  after  the   specified      "newfile" 5 lines, 86 characters
                        line.   Address 0 is permissi-      :
                        ble and  causes  the  copy  of
                        file   to  be  placed  at  the
                        beginning of the buffer.   The
                        read  command  does  not erase
                        any  text   already   in   the
                        buffer.   If no line number is
                        specified,  file   is   placed
                        after the current line.

recover file      rec   Retrieves a copy of the editor
                        buffer after a  system  crash,
                        editor  crash, phone line dis-
                        connection, or  preserve  com-
                        mand.

(.,.)substitute   s     substitute/pattern/replacement/     :3p
                        substitute/pattern/replacement/gc   Line 3 contains a misstake
                        Replaces  the first occurrence      :s/misstake/mistake/
                        of  pattern  on  a  line  with      Line 3 contains a mistake
                        replacement.   Including  a  g      :
                        after the command changes  all
                        occurrences  of pattern on the
                        line.  The c 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


undo               u     Reverses  the  changes made in   :1,15d
                         the buffer by the last buffer-   15 lines deleted
                         editing  command.   Note  that   new line number 1 is printed
                         this example contains a  noti-   :u
                         fication  about  the number of   15 more lines in file ...
                         lines affected.                  old line number 1 is printed
                                                          :

(1,$)write file    w     Copies data  from  the  buffer   :w
(1,$)write! file   w!    onto  a  permanent file. If no   "file7" 64 lines, 1122 characters
                         file  is  named,  the  current   :w file8
                         filename is used.  The file is   "file8" File exists ...
                         automatically  created  if  it   :w! file8
                         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 w! forces the
                         write,   confirming   that  an
                         existing file is to  be  over-
                         written.


(.)z count   z     Prints  a  screen full of text
                   starting with the  line  indi-
                   cated;  or, if count is speci-
                   fied, prints  that  number  of
                   lines.  Variants of the z com-
                   mand are described in the man-
                   ual.

!command           Executes  the remainder of the   :!date
                   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  command  is
                   complete.

control-d          Prints   the  next  scroll  of
                   text,  normally  half   of   a
                   screen.  See  the  manual  for
                   details of the scroll  option.






Computing Services, U.C. Berkeley                   April 3, 1979








(.+1)<cr>          An address alone followed by a   :<cr>
                   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.


/pattern/          Searches for the next line  in      :/This pattern/
                   which   pattern   occurs   and      This pattern next occurs here.
                   prints it.                          :

//                 Repeats the most recent search.     ://
                                                       This pattern also occurs here.
                                                       :

?pattern?          Searches in the reverse direction
                   for pattern.

??                 Repeats the most recent search,
                   moving in the reverse direction
                   through the buffer.



































Computing Services, U.C. Berkeley                   April 3, 1979


