Linux and Unix ex command

ex commandAbout ex
ex syntax
ex examples
Related commands
Linux and Unix main page

About ex

ex is a text editor, and the line-editor mode of vi. It is the basis of vim, one of the most popular text editors in the world. ex was written by Bill Joy in 1976, based on an earlier program written by Charles Haley.

"ex" stands for extended, because it was originally an extension of the simple line editor ed. Similarly, "vi" stands for visual, because vi is the "visual" (full-screen) editing mode, which was eventually added to ex.

The commands ex and vi point to the same program, started in different modes. You can start ex by running vi -e, or you can start vi by running ex -v. Additionally, from within ex, you can start vi with the visual command (or vi for short). From inside vi, you can start ex with the command Q.

If you are familiar with vi, you can think of the ex command prompt as being the same as vi's command prompt after you type a colon (":"). For instance, the ex command "w" will write your changes to disk, just as ":w" will write changes to disk in vi.

For more in-depth information about using a line editor, see our documentation of ed, which contains extensive examples and a tutorial.

ex syntax

ex [ -| -s ] [ -l ] [ -L ] [ -R ] [ -r [ file ] ] [ -t tag ] [ -v ] [ -V ] 
   [ -x ] [ -wn ] [ -C ] [ +command | -c command ] file

Options

-, -s Suppress all interactive user feedback. This is useful when processing editor scripts.
-l Set up for editing LISP programs.
-L List the name of all files saved as the result of an editor or system crash.
-R Readonly mode; the readonly flag is set, preventing accidental overwriting of the file.
-r file Edit file after an editor or system crash. (Recovers the version of file that was in the buffer when the crash occurred.)
-t tag Edit the file containing the tag and position the editor at its definition.
-v Start up in display editing state using vi. You can achieve the same effect by typing the vi command itself.
-V Verbose. When ex commands are read by means of standard input, the input will be echoed to standard error. This may be useful when processing ex commands within shell scripts.
-x Encryption option. Simulates the X command and prompts the user for a key. This key is used to encrypt and decrypt text using the algorithm of the crypt command. The X command makes an educated guess to determine whether text read in is encrypted or not. The temporary buffer file is encrypted also, using a transformed version of the key typed in for the -x option.
-wn Set the default window size to n. This is useful when using the editor over a slow speed line.
-C Encryption option. Same as the -x option, except simulates the C command. The C command is like the X command, except that all text read in is assumed to have been encrypted.
+command, -c command Begin editing by executing the specified editor command (usually a search or positioning command).
file The name of a file to be edited.

ex examples

ex myfile.txt

Edits the file myfile.txt.

ed — A simple text editor.
edit — A text editor.
grep — Filter text which matches a regular expression.
sed — A utility for filtering and transforming text.
sort — Sort the lines in a text file.
vi — Text editor based on the visual mode of ex.
vim — An advanced version of vi.