
The ECN No Name Newsletter is no longer being published.
This is an archived issue.
[previous article]
[next article]
Is Emacs Right For You?
Mark Senn, Systems Programmer
mds@purdue.edu
This article compares the GNU Emacs and VI text editors.
Some basic Emacs commands are described.
If you'd like to try Emacs to see if you like it,
see the ``Try Emacs'' section below.
Instructions on how to learn more about it are also included.
I like the Emacs text editor
and use it for editing text files of all kinds,
some binary files,
reading/sending mail,
and reading news.
Of all the tools I use, Emacs is the most important.
VI vs. Emacs
-
Emacs is free and widely available
-
Emacs is free and is available for many different computers,
including Windows 95 and Windows NT.
At the ECN it is installed as /usr/local/bin/emacs
on the Suns and HPs.
-
Insert Mode
-
In VI one must type
i
to go into insert mode,
followed by
text to insert .
followed by the "Esc"
key.
In Emacs you just type
text to insert.
In VI,
commands are ordinary characters like a, i,
etc.
In Emacs all commands are control characters
or the Esc key followed by other characters.
I like Emacs' method more---with VI, I would sometimes be in the wrong mode
(insert or command)
when I typed something.
I do not find control characters or Esc inconvenient for Emacs commands.
-
Multiple Windows
-
VI doesn't let you see and modify two parts (for example, top and bottom)
of long files at the same time.
Emacs lets you have as many windows into the same or different files
as you want.
-
Narrowing
-
In Emacs you can conveniently display and restrict editing to a portion of the
file you're editing.
This is called narrowing to a region.
A subsequent widen lets you edit the whole file again.
I know of no easy way to do this in VI.
-
Rectangular Regions of Text
-
In Emacs one can manipulate rectangular regions of text easily.
Go to, for example, the upper left corner and set a mark by typing
Control-
(that's Control-space),
then move to the lower right corner and type
Control-x r d
-
Modes
-
People all over the world have written Emacs software to:
-
type different kinds of files more conveniently by using automatic
indenting, matching braces,
making commands different colors than text in files, etc.
-
compile programs and ``step through'' error messages one at a time
-
read and send mail
-
read and post news
-
accomplish a variety of tasks
-
Customization
-
Emacs has a very complete programming language.
You can define your own commands.
You can have any key run any built-in or user-defined command.
-
Maximum line length
-
VI's limit is 4096 characters.
Emacs' depends on disk space; lines with over 10 million characters have worked for me.
While doing real work with ordinary text files,
sometimes the VI limitation can cause problems.
Have you ever wanted to edit the executable version of a program to change
a filename to one of the same length or shorter?
Emacs can do that.
-
Newline characters
-
VI always writes a newline character as the very last character of a file.
Emacs has no such restriction.
Enough Commands To Do Real Work
-
Notation
-
In Emacs documentation
C-letter
means hold down the Control key and type letter
at the same time.
For example,
C-a
means hold down the Control key and type a.
M-letter
means type the Esc key and then type letter.
For example,
M-x
means type the Esc key and then type x .
In the example
C-a\ C-b
do not type a space between the
C-a
and the
C-b.
The space is just there to make it easier to read.
-
Starting Emacs
-
To start Emacs type
emacs -nw filename
where filename is the name of the file you want to edit.
The -nw keeps Emacs from using a new X window---I like that best.
Typing
C-x 2
in Emacs keeps one X window but divides it into two parts
so you can look at and change more than one part of the file at the same time.
If filename doesn't exist,
it will be created.
-
Basic Emacs Commands
-
Ordinary characters get inserted into the file.
All commands are prefixed with control characters or Esc
| Type | To |
| C-a | go to beginning of current line |
| C-b | go backward one character |
| C-d | delete current character |
| C-e | go to end of current line |
| C-f | go forward one character |
| C-g | abort the current operation |
| C-n | go to next line |
| C-p | go to previous line |
| C-v | go down a screenful |
| M-v | go up a screenful |
| M-< | go to start of file |
| M-> | go to end of file |
| C-x 2 | split horizontally this Emacs window into 2 |
| C-x 3 | split vertically this Emacs window into 2 |
| C-o | go to other window |
| C-x o 1 | make this window the only window |
| C- | (that's Control-space) set a mark---use |
| other movement commands and to define |
| region between mark and current position |
| C-w | delete region |
| C-x n n | narrow to region |
| C-x n w | widen (undo previous C-x n n) |
| C-x C-f | read another file |
| C-x C-s | save file |
-
Exiting Emacs
-
To get out of Emacs, type
C-x C-c
followed by
y
or
n
as appropriate to save or not save your changes.
-
Try Emacs
-
This simple example demonstrates a few basic Emacs commands.
Type
emacs -nw emacstest
to experiment with Emacs by creating the file emacstest.
Type in a screen and a half of lines; use line numbers like this:
1
2
Then, follow these instructions and watch what happens.
| M-< | go to start of file |
| M-> | go to end of file |
| M-< | to back to start of file |
| C-f C-f | go forward two characters |
| to start of second line |
| C- | (that's Control-space) set mark |
| C-n C-n C-n | go down three lines |
| C-x n n | narrow |
| y y | type y y if you get a |
| ``You have typed C-x -n n, ...'' message |
| C-p | go to previous line |
| abc | insert abc |
| C-x n w | widen |
| C-n C-n | go down two lines |
| C-x 2 | split this window into two windows |
| def | insert def |
| (notice how bottom window changes) |
| C-x o | go to other window |
| M-> | go to end of file |
| C-p | go to previous line |
| ghi | insert ghi |
| C-x C-c | exit |
| y | save changes |
Double check that the file looks like what you expect from VI and then
remove it if you'd like.
-
For More Information
-
Type
Del t
in Emacs for an extensive Emacs tutorial.
-
Visit the Emacs homepage at
http://www.fsf.org/software/emacs/emacs.html
-
The book Learning GNU Emacs by
Debra Cameron, Bill Rosenblat, and Eric Raymond
published by O'Reilly & Associates is suggested.
webmaster@ecn.purdue.edu
Last modified: Tuesday, 12-May-98 09:40:13 EST
HTML