NAME
	ed - the built-in editor

DESCRIPTION
	Contents
	1 ... Introduction
	2 ... Commands available in command mode
	3 ... Substitutions in ed
	4 ... Searching in ed
	5 ... Some rumours	


	_1._Introduction_

	The line editor is very similar to the UNIX editors 'ed' and 'ex', and
	just as powerful. We have been spoiled by full screen editors like
	'emacs' and 'vi', but remember that the first versions of UNIX were
	written using 'ed'. It might take a while to get used to, but it is
	well worth it. Some features:

	+ Simple and regular structure of commands.
	+ One command per line.
	+ Easy and powerful search feature.
	+ Indentation possibility.
	+ Very powerful replacement feature.
	+ Single-line commands easily extended to multiple lines.

	Commands to ed have zero, one or two addresses followed by single
	character command. Possibly, the command is followed by parameters to
	that command. The addresses specify one or more lines in the buffer;
	every command that requires an address has default addresses. Thus,
	the addresses can often be omitted.

	ed has two modes, command mode and input mode. In command mode, ed will
	display a prompt: the single character ':'. In input mode, none will
	be shown and all input si collected. You leave the input mode by typing
	a period, '.', first on a line followed by an immediate carriage
	return. Now some reminders and examples.

	input mode:	no prompt.
	command mode:	prompt is : .

	X,Ycmd		General command form.
	1,10p		Will print line 1 to 10.
	1,5d		Will delete line 1 to 5.
	8p		Will print line 8.

	In command mode, a '.' is the "current line". The current line is the
	last line referenced. If you want to print last line + 10 more, the
	command is:
	.,.+10p


	_2._Commands_available_in_command_mode_

	This group of commands accept line addresses. If none is given, the
	command is applied to the current line. '.' refers to the current line,
	and '$' to the last line of the file. Thus, '1,$p' will print the
	entire file.
	
		Print current line, step forward one line.
	=	prints current line
	c	change, that is, delete, then insert.
	d	Delete line.
	l	Print line with control characters.
	p	Print line.
	P	The same as 'p'.
	r file	Read in a file after the line specified. If no adress is given,
		insert at the last insert position, if also nothing was
		inserted, at the end of the buffer.
	s	Substitute patterns. See special documentation.
	z	Print 10 lines.
	a	Start insert mode after specified line (appending).
		Exit with '.' first on a line immediatly followed by .
	i	Start insert mode before specified line (inserting).
		Exit with '.' first on a line immediatly followed by .
	j	Join lines. If no addresses given , join this line and next,
		if addresses given, join that range.
	k char	set mark 'char' to current line. 'char' must be in the range
		[a-z]. The mark can be used thereafter as a line address, with
		a leading slash (e.g. ka to set mark a, /ap to print marked
		line).
	l	print line with control characters.
	m	Move lines. With no address prepended, move cirrent line to
		after line . If a single address is prepended, move that
		line. If two addresses are given, that range of lines are
		 moved.
	t	Copy lines to after . If no address is given, copy the
		current line. If one address is given, copy that line. If two
		addresses are given, copy that range of lines.

	
	This group of commands are used without line specification.
	
	!cmd	Give a game command. For example "say Wait, I am busy".
	E file	Discard current buffer and start editing 'file'.
	e file	As E, but refuse if file has been changed but not saved.
	f	Print current filename.
	f file	Set filename of the buffer.
	I	INDENT the file. Highly recommended!
	n	Toggle line numbering. Doesn't work; use 'set number on' and
		'set number off'. The last does not always work.
	q	Quit. Won't work if file is changed.
	Q	Quit and discard all changes if not saved.
	w	Write the file to disc.
	w file	Write the file to disc with the name 'file'.
	W	The same as w.
	x       Write the file and exit.
	z	Show 10 lines.


	_3._Substitutions_in_ed_

	Substitutions are very advanced and powerful. Here follow some
	examples:

	s/pattern/replacement/
	  Replaces FIRST occurence of pattern on this line with replacement.
	  Pattern may be a regular expression as detailed in the help file
	  for the efun regexp. There might be some differences, if so, ed will
	  tell you when you overstep the boundaries. The separator '/' can be
	  replaced with any other character. See below for examples.

	s/pattern/replacement/g
	  Replaces ALL occurences of pattern in the current line with
	  replacement.

	s/apa/bepa/
	  This will substitue the 'apa' in current line to 'bepa'.

	s/apa/bepa/p
	  This will substitue the 'apa' in current line to 'bepa', and show
	  the result.

	1,$s/apa/bepa/
	  Replace first occurence of 'apa' with 'bepa' on all lines in the
	  file.

	s!apa!bepa!
	  Here '!' is used instead of '/'.

	s/[0-9][0-9]*/(&)/g
	  The text matched by pattern may be used in replacement with the
	  character '&'. The example above will put parentheses around every
	   number on a line.

	s/really big nasty dog/&s/
	  This time saver pluralizes only the really big nasty dogs.


	_4._Searching_in_ed_

	Searching is done with the expression operator, //. Examples:

	/pattern/
	  Find first occurence of pattern in the current line. The patter obeys
	  about the same rules as a regular expression, and you might want to
	  refer to the documentation for the efun regexp. Some basics are shown
	  here:

	  .	Match any one character.
	  x*	Match any numbers of x (0 or more).
	  [abc]	Match 'a', 'b' or 'c'.
	  [0-9]	Match any digit 0 - 9.
	  [a-z]	Match any lowercase letter.
	  \x	Match 'x' where 'x' can be any character except '(' and ')'.

	//
	  Repeat the last search.

	/ab.d/p
	  Find, and print, the line which match the pattern. For example,
	  'abcd', 'ab_d', 'abJd' and 'ab*d' will be matched.

	_5._Some_rumours_

	This is the list of extended ed commands by the lore...

	a) never use 1,$p to print out an editfile, because you will
	  be thrown out 'cause of too much text transfereed to you.

	b) $: jump to end of file.

	c) ?anything? and ?? : search from bottom to up. (like '/'
	   from beginning to end of file. (also with substitutions,
	   try out..)

	d) ( g/xxx/p search global xxx and print corresponding lines,
	   /xxx/s/new/old/p : search xxx, substitute new to old in this
	   line and print out. (try this concatenations with other
	   commands)

	f) x,y w name : save lines x to y to file name (if you don't
	   know the line numbers : '=' current line number)

	g) s/$/text/p : append text to the end of current LINE and
	   print line

	h) s/^/text/p : insert text at beginning og current LINE and
	   print line

	i) Earendil's trick to comment and uncomment a line of code:
	   To comment:
	     s/.*/\/* & *\/
	   To uncomment (two commands):
	     s/^...//
	     s/...$//
	   If you use a mud client, make a macro for it.  Very useful.

	j) To save a piece fo your file, you can do:
	     a,bw filename
	   Where a and b are line numbers, and filename is the name of the
	   file where you want it saved.

Help topics available:
COPYRIGHT README banish castle door
ed feelings genders general hook
key mapsystem prices properties rooms
style/ termcap tourist_info water_room_old

[START|BACK ]




[ NannyMuds main page | FAQ | Contact us ]

You are guest number 193 since November 2019.
This file was last modified: June 2000.