editing 102 eds big brother ex - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

editing 102 eds big brother ex

Description:

... buffers back into editing buffer to perform a 'cut and paste' ... The copy co command duplicates one or more lines after the ... command with a bang ... – PowerPoint PPT presentation

Number of Views:70
Avg rating:3.0/5.0
Slides: 32
Provided by: richardg66
Category:
Tags: and | bang | brother | copy | editing | eds | paste

less

Transcript and Presenter's Notes

Title: editing 102 eds big brother ex


1
Chapter 6
  • editing 102 eds big brother ex

2
The Origins of ex
  • Bill Joy hated (hates?) the ed editor
  • He and Chuck Haley were using the em (editor for
    mortals) editor
  • Joy started working on em
  • first built en (editor new)
  • evolved through several iterations
  • ended up with ex

3
How ex is like ed
  • Its a line editor
  • It has two modes
  • command
  • text entry
  • They share many of the same commands
  • Both use buffers to hold data to be edited

4
Differences between ed and ex
  • Joy thinks ex is more user friendly
  • ed has two buffers ex has the following
  • editing, undo, and anonymous buffers
  • 26 named buffers
  • ex commands can be full words
  • cant change the command mode prompt
  • ex has a full screen mode (vi)

5
Starting ex
  • The ed editor has several command line options
  • -r (recover from an editor crash)
  • -R (read only)
  • -s (suppress normal standard output messages)
  • -v (start in visual mode) This is the same as
    using the vi command
  • -x or -C (encrypt the file being edited)

6
General command formataddress1,address2
command argument(s) option(s)
  • No address the command works on the current line
  • one address the command works on that line
  • two addresses the command works on that range
  • the range must be positive and start at or after
    the first line of the buffer
  • the range must end at or before the last line of
    the buffer

7
Addressing modes in ex
  • . the current line
  • last line in the file
  • n the nth line in the file
  • c the line marked c
  • n or n- line above or below n
  • -5 or 5 5 lines above or below current line
  • n-m or nm m lines above or below line n
  • /pat/ search forward for next line containing pat
  • ?pat? like / but search backwards
  • all the lines in the buffer (very useful!)

8
Error Messages
  • Longer than eds
  • Thought to be more useful than eds

9
Bidding ex Adieu
  • Cant quit without saving the buffer with q must
    use q!
  • Can temporarily suspend ex with sus or st

10
Saving your work
  • write is most common way to write buffer
    changes to disk
  • wq asks ex to write then quit
  • xit asks ex to write if the buffer has been
    changed, and then quit. This is the most
    efficient way to exit while saving your work.

11
Finding or Changing the Associated File Name
  • File lets you see the associated file
  • file also allows you to change the file
    associated with the buffer

12
Displaying the Contents of a File
  • The display tools look like eds
  • l (ell) show lines with special characters
  • nu show lines and line numbers Note difference
    from eds command n.
  • p show lines unadorned
  • commands also have a count option instead of a
    range of lines in the address

13
Displaying the Contents of a File (cont.)
  • The display commands also take a flags option
  • act line nu and put out line numbers
  • l show non-printing characters line l (ell) does
  • p display the lines as they were typed with no
    special characters

14
Adding Text to a File
  • Append a acts like append in ed
  • append appends after the line specified
  • Insert i acts like insert in ed
  • insert inserts before the line specified
  • Change c used to replace one or more lines
  • enter a . (dot) as the only character to go to
    command mode

15
Deleting a Line From a File
  • Delete d deletes lines, use substitute to delete
    words
  • can put deleted text in anonymous (the default)
    buffer or a named buffer
  • can put text from any of the buffers back into
    editing buffer to perform a cut and paste
  • if you use change to delete, the lines are lost

16
Buffers
  • Joy built two types of buffers into ex
  • anonymous buffer (the unnamed buffer where
    deleted or yanked lines are tucked away)
  • named buffers (a - z) which hold the deleted text
    until replaced

17
Putting Lines Back
  • The put p command takes the contents of the
    anonymous buffer (by default) or a named buffer
    and places it after the line specified

18
Copying Lines
  • The copy co command duplicates one or more lines
    after the line specified.
  • If you want several copies consider yanking and
    putting rather than copying.

19
Yanking lines
  • The yank y command copies one or more lines to
    the anonymous or named buffer.
  • Lines that are yanked remain in the buffer
    unchanged.
  • You need to put the yanked lines back into the
    buffer (with the put command).

20
Moving Lines
  • The move m command moves a line from one place to
    another in the buffer.
  • It is faster to move a line than to delete and
    put it in most cases
  • You can move a line or range of lines only one
    time (since it isnt there anymore!)

21
Combining Lines
  • The join j command works like eds join
  • However it is a little smarter, it adds spaces if
    necessary!
  • Bang (!) prevents adding spaces

22
Substitution, Your Best Friend
  • As with ed, substitute allows you to change parts
    of a line.

23
Global
  • The global g command acts like a super range
    designator
  • can use different characters to enclose the
    search string
  • the v version finds lines that dont match the
    pattern

24
Using Shell Commands
  • Precede the shell command with a bang (!)
  • can capture the output in the editing buffer if
    you precede the bang with a line number

25
Reading other files
  • The read r command reads another file into the
    editing buffer, combining two files.
  • If you dont specify a file name, read will read
    the file associated with the buffer!
  • Useful to
  • put in a standard heading
  • put in a standard footer

26
Editing Other Files
  • If you want to edit other files while still in ex
    you can
  • next n to read in the next file from the list of
    files on the command line
  • edit e to read a new file you specify (not from
    the command line)

27
Oops
  • To reverse the last change to the buffer, use the
    undo u command
  • Substantial differences between vi and vim!
  • In vi the undo undoes up to the last write
  • In vim the undo undoes the last change to the
    buffer

28
Marking and Returning to Places in a File
  • The mark ma command marks a place in the buffer.
  • You can put 26 marks in a buffer (a - z)
  • The tick mark () sends control to the marked
    line.
  • j would send control to the line marked j
  • Marks exist only for an editing session they are
    not preserved with the file.

29
Setting Options for the Ex Editor
  • There are a number of options you can set to make
    your life easier
  • Use the set se command to set these options
  • autoindent ai keeps the same level of indention
  • number nu numbers the lines
  • tabstop ts sets the tab width default 8, 4 works
  • terse shortens some error messages

30
Other ex commands
  • There are a number of lesser used commands that
    may be handy
  • chdir change the current working directory
  • preserve grab a copy of the buffer just as if
    the editor crashed
  • recover a file from an editing crash
  • gt shift the line(s) specified shiftwidth right
  • lt shift the line(s) specified shiftwidth left

31
Other ex commands (cont.)
  • shell drop out to the command line to perform
    some task
  • when you finish, type exit to return to ex
  • source execute a series of ex commands stored
    in a file. You can also store commands in a
    buffer and execute them from that buffer!
  • Open go to vi for one command.
  • visual switch from command line to visual (vi)
    mode.
Write a Comment
User Comments (0)
About PowerShow.com