To Index

 Documented in Volume 1 of the UNIX Programmers Manual.

 See /usr/doc/ex/ on 4.2 BSD systems for additional online documentation on this.


  :1,$s/^left/right/

  will change, for lines 1 to the end, any line which starts with
  "left" (the caret means the start of line). The string "right"
  will replace the string found.


  :.,.+10s/$/ 0000/

  will change, for the current line through the next 10 lines, the
  end of a line ($ means the end of a line). The string " 0000" will
  be appended to the right of each line.


  :/first/;/next/;/final/

  will search for the next occurrence of 'first', then for the next
  occurrence of 'next', and leave the cursor on the next line which
  contains 'final'.


  :source fname

  will cause the contents of fname to be read as if they were being typed
  in as : (ex) commands. This effectively allows you to generate a command
  file of ex commands and invoke it. 


  :g/junk/d

  will, for all lines, delete any line which contains the string "junk".


  :g!/\\/d

  will, for all lines, delete any line which does NOT (! means not)
  contain a backslash. Note that the backslash is escaped with a backslash.


  :read !date

  will insert the output of the date command after the current line.


  :15,$!expand

  will take lines 15 through the end and pass them to expand to replace
  tabs with the appropriate number of spaces. The output will then
  replace lines 15 through the end.


  :1,$s/[A-Z]/\l&/g

  will change all the characters in a file to lower case.


 % ( echo 'g/^/m0' ; echo '%p' ) | ex N*
  will list file Nfile to stdout with the order of lines reversed (i.e. the
 last line will be listed first).


		       ----- Ex commands -----

  ab	abbrev		n 	next		una	unabbrev
  a 	append		nu	number		u	undo
  ar	args		o 	open		unm	unmap
  c 	change		pre	preserve	ve	version
  co	copy		p 	print		vi	visual
  d 	delete		pu	put		w	write
  e 	edit		q 	quit		x	xit
  f 	file		re	read		ya	yank
  g 	global		rec	recover		z	window
  i 	insert		rew	rewind		!	escape
  j 	join		se 	set		<	lshift
  l 	list		sh 	shell		RETURN	print next
    	map		so	source		&	resubst
  ma	mark		st 	stop		>	rshift
  m 	move		s 	substitute	CTRL-D	scroll


  #! /bin/csh 				# execute ex commands from a file
  ex - filename << 'EOF'
  1,$s/^[ ]*//
  w
  q
  'EOF'

    This csh script runs the editor to delete leading blanks from the
  lines in the file 'filename'.
    The notation << 'EOF' means that the standard input for the ex command
  is to come from the text in the shell script file up to the next line
  consisting of exactly 'EOF'.
    The fact that the `EOF' is enclosed in `' characters, i.e. quoted,
  causes the shell to not perform variable substitution on the intervening
  lines.
    In general, if any part of the word following the `<<' which the shell
  uses to terminate the text to be given to the command is quoted then
  these substitutions will not be performed.
    In this case since we used the form `1,$' in our editor script we
  needed to insure that this `$' was not variable substituted. We could
  also have insured this by preceding the `$' here with a `\', i.e.:

                 1,\$s/^[ ]*//

  but quoting the `EOF' terminator is a more reliable way of achieving the
  same thing.

  From: mark@cbosgd.UUCP (Mark Horton)

    In article <1705@umcp-cs.UUCP> chris@umcp-cs.UUCP (Chris Torek) writes:
  >It may either be considered a bug or a feature that running ``vi''
  >in your home directory causes it to read your .exrc twice.

     This is true.  What really happens is that if you don't have an
  EXINIT in your environment, vi sources ~/.exrc and
  also	./.exrc, in case you have local options for the current directory.
  If you're in your home directory, it will source the same file twice.
     If you have an EXINIT in your environment instead of a ~/.exrc file,
  you won't have this problem.  Since .exrc files have other problems
  (speed and funny characters like CTRL-D stripped) it is strongly
  recommended that you use EXINIT instead of ~/.exrc.
     Since .exrc and EXINIT normally contain set and map and abbr commands,
  it's usually harmless for the .exrc file to be sourced twice.

To Index