Edmund A. Hajim  School of Engineering and Applied Sciences

Editors and Formatters


This tutorial will introduce you to several programs you can use to create text files or formatted documents on UNIX workstations.

Text files are simple files that contain readable characters. Some examples of text files are programs, electronic mail and simple unformatted documents. A common way to create such files is with a "text editor".

Formatted documents are files which can be displayed or printed with "fancy formatting", such as different fonts, proportional spacing, embedded graphics, etc. The slides for this talk were made from a formatted document.

Some formatted documents are simple text files with the formatting info mixed in with the text to be formatted. Such documents are created with a text editor, and processed afterwards by a text formatting program. Others are specialized, non- text files which are created and manipulated only by special programs.


The symbols [RETURN] and [CR] both mean that you are to press the carriage return key on your keyboard. The symbol [ESCAPE] means that you are to press the escape key on your keyboard.


An "editor" is a tool used for creating and/or modifying text files. It allows the user to enter text, and to manipulate it in a variety of fashions. Text can be changed or moved around. Many have built-in spelling checkers and similar features. After getting used to a text editor, it's unlikely that you'd ever settle for a mere typewriter again.

There are literally dozens of editors available, and no single one is the best. Your choice of what editor to use is often regarded as a religious issue. People have very strong opinions on the subject, and are generally unwilling to change their minds. Everyone has a favorite, and usually one's choice is influenced by which editor one learned first. Pick one, learn it, and be happy.

There are three major types of editors. The simplest is called the "line editor". When using such an editor, you can't really see what you're doing, mostly because you can only edit one line at a time (hence the name). Such editors are severely limited in power, and therefore are quite unpopular. Nonetheless, there are two such editors available on most UNIX systems, called "ed" and "ex".

The most common and most popular type of editor is called the screen-oriented, or display-oriented editor. These are also sometimes referred to as "visual editors". When using a visual editor, you can see one screenful of text at a time.

Some visual editors are combined with text formatters, which will be discussed below. These represent the third type of editor. When the image on the screen is exactly the same as it will look on paper, the editor is called "What You See Is What You Get", or WYSIWYG.

Here is a representative sample of editors for your consideration. We present three UNIX screen-oriented editors and one combined editor/formatter.


Vi (pronounced "vee-eye" and short for "visual") is the "lingua franca" of UNIX editors. It's available on virtually every UNIX computer. Vi is a good editor to know if you'll be working on several different UNIX machines (especially if some are outside the HSEAS). Vi was written by Bill Joy, who later became a founder of Sun Microsystems. Vi is the brother of "ex", one of the UNIX line editors, and they share many commands.

Vi is a screen oriented editor. As you move the cursor keys, the display automatically updates to show you the part of the document that the cursor is pointing at. Vi is also a fairly quick editor, capable of providing good response on relatively slow computers or terminals.

Starting vi

To invoke vi, type

	vi filename [RETURN]

at your UNIX prompt. This will start up the editor.

Basic vi commands

The vi editor operates in two basic modes: the text insertion mode (in which you type the characters you want to include in your file), and the command mode (in which you operate upon the text, by moving or deleting text).

When first started, the vi editor is in command mode. To enter the insert mode in order to begin typing your text, press the i key. At this point, anything you type will appear on the screen just as if you were using a typewriter. At the end of each line, just as on a typewriter, you should press the [RETURN] key. When you are through typing and want to return to command mode, press the [ESCAPE] key.

Once in command mode, the arrow keys on your keyboard can be used to move around the body of the text. If your keyboard does not have arrows, the following keys can be used to move the cursor:

	h	- move back one space
	j	- move down one line
	k	- move up one line
	l	- move forward one space

Some other operations available in command mode:

	x	- delete the character beneath the cursor
	dd	- delete the current line of text (and put it into a buffer)
	dw	- delete from the cursor to the end of the word
	yy	- "yank" the current line into a buffer
	p	- place the content of the buffer into the file at the 
		  current cursor location.

To return to text insertion mode from command mode:

	i	- begin inserting text at the cursor location
	a	- begin appending text at the position following the cursor
	A	- begin appending text at the end of the line
	o	- open a line beneath the current line for text insertion.
	O	- open a line above the current line for text insertion.

To return to command mode after any of these insert commands, press the [ESCAPE] key again. When you aren't sure of the current mode (command or insert), press the [ESCAPE] key to make certain that you are in the command mode.

When in command mode, some of the commands used to write the file to the disk are:

	:w	- write the file to disk
	:q	- quit the editing session
	:q!	- quit the editing session without updating the file
	:wq	- write the file and quit

The attached Vi Quick Reference sheets are a more complete summary of the available vi operations.

Emacs-style Editors

Emacs, like vi, is a screen oriented editor, but it is very different in other ways. Unlike vi, emacs is not "moded". Rather than having a "command mode" and "insert mode", emacs commands are distinguished by special keys. Anything which isn't a command is text that goes into the file.

The original Emacs was written by Richard Stallman at MIT for DEC PDP-10 computers. Today, the term is used for any editor designed with the same philosophy as the original Emacs. The two editors described below are both Emacs-style editors.

Most Emacs-style editors have a number of features which are not available in vi. They can edit several files at the same time, allowing you to move text between them and view different sections (even of the same file) simultaneously. They can do automatic word wrapping and paragraph filling, as well as spell checking. Most have built-in help and/or on-line tutorials. Emacs-style editors allow for definition of macros (a set of frequently used commands), are highly customizable, know about several different programming languages, and more.

Commands in Emacs-style editors

Emacs commands are differentiated from normal text by the use of two special keys. The first is the [CONTROL] key. This key is used like the [SHIFT] key, it is held down while pressing another key. The other special key is the [ESCAPE] key. This is used as a "prefix", in that you press the [ESCAPE], then release it, then press the next key. The [ESCAPE] key is sometimes call the "meta" key.

For the remainder of this document, the following conventions will be used. "C-x" means Control-x. That is, hold down the [CONTROL] key and press the x key, then release both. "M-x" means Meta-x. In other words, press and release the [ESCAPE] key, then press the x key. Unlike vi, emacs-style editors do not have an "insert" mode and a "command" mode. Rather, commands are performed using these special keys, and all others are inserted as text into the document.

GNU Emacs

The version of emacs supported at the HSEAS is "GNU Emacs". GNU Emacs was written by Richard Stallman of MIT's Project GNU ("GNU is not UNIX"), as part of a long-term effort to provide a complete, free replacement for UNIX. While this is the same Richard Stallman who wrote the original PDP-10 Emacs, GNU Emacs is a totally different sort of monster.

GNU Emacs is an emacs-like screen oriented editor, and is best characterized as Big and Powerful. Rightfully so, the icon often associated with GNU Emacs is a kitchen sink ... Although GNU Emacs is extremely powerful and feature laden, and demands a lot of machine resources, and can bog down a workstation. GNU Emacs can do automatic file backup, and has an internal LISP programming language interpreter for writing your own commands and macros.

GNU Emacs is supported on all the UNIX Machines in HSEAS, and probably almost all UNIX machines at UR.

Invoking Emacs

To start up GNU Emacs, enter the following command at your UNIX prompt:

	emacs filename [RETURN]

Emacs comes with a built in tutorial. This is really the best way to learn how to use emacs. To start the tutorial, just type "emacs" at the UNIX prompt. Emacs will display several lines of information, the last of which says to type Control-H, followed by a "t" to start the tutorial.

The tutorial is self documenting. Like "teachjove", it's basically a text file, which leads you through the process of learning emacs by having you make modifications to it.

Basic Emacs commands

In general, the commands in GNU Emacs are just like those in JOVE. However, there may be a few exceptions.

Getting help

Emacs has several different help modes. They all are available via the C-h command. C-h C-h will give you more help on how to get help.

How to get the Emacs manual

The emacs manual is about 300 pages long. Please don't try to print it. Emacs is self documenting enough, that for most users the manual is not needed. You may borrow a copy from Del or the Consulting office for up to a day.


Textedit is the standard editor supported by Sun under their window system. Textedit is easy to use, since it is controlled by menus via the mouse. Most programs using edit windows use a Textedit like editor.

Textedit is controlled by 4 "drop-down-menus" along the top of the window. You can bring up a drop-down-menu by placing the mouse cursor over the appropriate menu-button, and clicking the right mouse button. When the menu appears, move the cursor over the desired function, and click the right mouse button on the desired function.

The "File" menu controls the loading and saving of files.

The "View" menu allows you to control how your text is presented. Under the "Change Line Wrap" menu item, you can control how the text is wrapped around at the end of a line.

The "Edit" menu is where the cut and paste commands can be found. There is also an undo command there, in case you want to undo a previous change you've made to your document.

The "Find" menu supports finding text, and the find and replace capabilities of Textedit.

You can scroll through your document by clicking on the scroll arrows on the left side of the window.

Help on using Textedit under OpenWindows can be found in the "DeskSet Environment Reference Guide", which should be available in the workstation labs.

Do note our warning in the next subsection though, before you start using TextEdit.

Other Editors

Linux has a variety of text editors (gedit, nedit, joe, pico, vim) too numerous to mention here. A caution - while some of these are nice editors, they are often common only to one OS, and then often only one revision of that OS. We strong recommend you stay with vi and emacs.


Formatters are programs which take as input regular text files, and produce "formatted" output, i.e. output with even margins, different types of fonts etc. Often embedded in the input text are commands to the formatter telling it how to format the output.


Fmt is a extremely simple formatter. Fmt just fills lines out to 72 characters wide by default; you can change the line width if you wish). It will skip over blank lines, so using a blank line between paragraphs will cause fmt to simply even up all the lines in each paragraph.At the UNIX prompt, type

fmt filename > formatted-filename

Fmt can be invoked from inside vi, using the command


Where filename is the unformatted file's name, and formatted-filename is thename of a file to put the formatted output into.


Pr prepares one or more filenames for printing. By default, the output is separated into pages headed by a date, the name of the file, and the page number. Pr can also produce multi-column output with the "-m" option. See the man page for other options.

At the UNIX prompt, type

pr file > formatted-file

Pr can be invoked from inside vi, using the command



Just as vi is the "standard" UNIX editor, roff and its associated programs are the standard text formatting tools for UNIX. Roff is a command language, in that formatting commands are embedded in the text.

There are several programs involved with roff. They include:

	nroff	 Format text for display on a terminal or similar device
	troff	 Format text for display on a phototypesetter
	ptroff	 Format text for display on a PostScript device
	groff	 Format text for display on a variety of devices (GNU)
	tbl	 Format tables for roff
	eqn	 Format mathematical equations for troff/ptroff
	neqn	 Format mathematical equations for nroff
	checknr	 Check roff input files for possible errors
	checkeq	 Check eqn/neqn input files for possible errors
	col	 Allow display of "funky" nroff output on a terminal


Because a roff document has the commands embedded inside, you must call one of the programs mentioned above to process the file and generate the output you're looking for. Some examples of such commands are:

	nroff filename
	ptroff -Pprinter filename
	tbl filename | nroff | col
	eqn filename | ptroff -Pprinter
	groff -tps | lpr -Pprinter
	checknr filename


Roff commands are embedded in the text file that is to be formatted. You must add them yourself when you create the file in your editor. Most roff commands begin with a dot (period, '.') at the beginning of the line, and are two characters long. Others can be embedded in a line of text, and begin with a backslash ('\').

	.ll 6.5i	Set the line length to 6.5 inches
	.po 1i		Set the page offset (left margin) to 1 inch
	.in +1c		Set the indentation to 1 centimeter
	.ce 2		Center the next two lines of text
	.sp 3		Skip three lines (add blank lines)
	.sp 1i		Skip down 1 inch
	.sp |2i		Move to two inches from the top of the page
	.ps 12		Use 12-point type
	.vs 14		Use 14-point vertical spacing
	.nf		No fill (stop filling lines out to the line length)
	.fi		Fill
	.bp		Break page (start a new page)
	.wh -1i bp	When 1 inch from the bottom, start a new page
	\fB		Start printing in boldface
	\fI		Start printing in italics
	\fP		Resume previous font style
	\s12		Print in 12-point type
	\s+2		Increase point size by two
	\s0		Resume previous point size


There are a number of "macro packages" available for roff. These allow other commands to make your life easier. For instance, there are macros to handle footnotes, and macros for special headers and footers. The more common macro packages are "-ms" and "-me". They are used by specifying their name on the roff command line, as in

	ptroff -ms filename

TeX and LaTeX

TeX (pronounced "tek") is an extremely powerful typesetting language, often used in academic and engineering circles. TeX has extensive support for typesetting equations. As with most formatters, a TeX file consists of text, with embedded commands which tell TeX how to format your file.

Unlike most formatters though, TeX can be difficult to learn ... the price one pays for the power of TeX is a fairly steep learning curve. LaTeX is a package to TeX macros which supports the most commonly used TeX functionality, in a package which is much easier to learn than pure TeX.

MS-Office Clones

On most of our Sun and Linux workstations, we now have either StarOffice or OpenOffice installed. These packages are clones, work-alikes for Microsoft's Office suite. They include (usually) a Miscorsoft Word (word processor) clone, a Microsoft Excel (spreadsheet) clone, a graphic web page editor (something like Microsoft's FrontPage) and a database (roughly similar to Microsoft's Access). The latest versions of OpenOffice have some very nice features (e.g., they can convert any of its documents into Adobe PDF format).

OpenOffice is also available (for free) for systems running Windows. It is mostly (not completely) compatible with MS-Office. In my personal experience, the most likely area for problems are fonts; if you stick with the normal set of fonts, you won't hve any trouble going between OpenOffice and MS-Office.


With the variety of editors and formatters available under UNIX, it's up to you to choose one, based on their relative merits and what you are hoping to accomplish, both now and in the distant future. (As we said, it's a religious issue.)

Partial List of Editors, Formatters, and Related Tools

awk		- pattern scanning and processing language
cmp		- compare two files
comm 		- select or reject lines common to two sorted files
diff		- display differences between two text files
ed		- basic line editor
emacs		- GNU project Emacs
eqn		- typeset mathematics
ex		- line editor
fmt, fmt_mail	- simple text and mail-message formatters
grep, fgrep 	- search a file for a string or regular expression
head		- display first few lines of specified files
join		- relational database operator
jove		- an interactive display-oriented text editor
look		- find lines in a sorted list
nroff		- format documents for display or line-printer
perl		- Practical Extraction and Report Language
pr		- prepare file(s) for printing
sed		- stream editor
sort		- sort and collate lines
tail		- display the last part of a file
tbl		- format tables for nroff or troff
troff		- Format text for display on a phototypesetter
uniq		- remove or report adjacent duplicate lines
vi		- visual display editor based on ex(1)

Prepared by Del Armstrong, Bob Kaser and John Simonson

Last modifed: Thursday, 07-Apr-2011 09:23:37 EDT