Emacs
There
are many different text editors available for Unix computers.
You
can have multiple editors on one system
vi
-
old, reliable, present on every Unix machine, completely and utterly user
hostile
jed
- fairly simple
pico
-
extremely simple, perhaps too simple
emacs
- a good compromise between features and ease of use
The
full name of the Emacs program is: "GNU macs, the Extensible, Customizable,
Self-Documenting, Real-time Display Editor.
•Emacs
is free software produced by the Free Software Foundation (Boston, MA)
and distributed under the GNU General Public License.
–Open
source software - Linux
–GNU
is an acronym for: “GNU is Not Unix”
Editors are used to create files of text and to modify their contents
You
need an editor for sending email, writing programs and many other tasks
•There
are many different editors - vi, ed and emacsare common
UNIX examples
•There
are different styles of editor - e.g. line editors and WYSIWYG editors
•They
are not the same as word processors which are concerned with printed documents
Emacs is a text editor that dates back from 1976, and comes from the
name "Editor MACroS".
It
was originally written to encompass a whole bunch of text editors with
different command sets and keyboard commands.
That's
right, Emacs in the strictest sense of the word is just a text editor,
from the same vein as Notepad, vi, and PICO.
Emacs differs from other editors in at least two major ways:
1.It
has tight integration with the command shell, so if set up properly, it
can run nearly any program accessible via direct access to the command
shell.
2.It
is extensible (and changeable) -- you can write packages in Lisp to extend
the capabilities of the program.
•To
start Emacs, at the > command prompt, just type:emacs
•To use Emacs to edit a file, type:
emacs filename
(where filename is the name of your file)
•When
Emacs
is launched, it opens either a blank text window or a window containing
the text of an existing file.

•The display in Emacs is divided into three basic areas.
The
top area is called the text ‘edit’ window. The text window takes up most
of the screen, and is where the document being edited appears.
•Below
the text window, there is a single mode ‘status’ line (in reverse type).
The mode line gives information about the document, and about the Emacs
session.
•The
bottom line of the Emacs display is called the minibuffer. The minibuffer
holds space for commands that you give to Emacs, and displays status
information.
•Emacs
uses Control and Escape characters to distinguish editor
commands from text to be inserted in the buffer.
Control-x
means to hold down the control key, and type the letter x
(You
don't need to capitalize the x, or any other control character)
[ESCAPE]
x means to press the escape key down, release it, and then type
x
•Your
current position in the file is shown by the cursor
•Most
basic movement is one character or line at a time
–use
the arrow keys or
•[Ctrl]-b
backward (left) one character
•[Ctrl]-f
forward (right) one character
•[Ctrl]-p
previous line (up one character)
•[Ctrl]-n
next line (down one character)
•Scrolling
happens as necessary
•Can
also move in steps of a word, sentence, paragraphs and screen
•[Esc]-f
forwards one word
•[Esc]-b
backwards one word
•[Ctrl]-a
start of current line
•[Ctrl]-e
end of current line
•[Esc]-a
start of current sentence
•[Esc]-e
end of current sentence
•[Ctrl]-v
scroll down one screen
•[Esc]-v
scroll up one screen
•[Esc]<
move to start of file
•[Esc]>
move to end of file
•[Ctrl]-l
refreshes the screen (e.g. to remove system messages)
•To
insert text, position the cursor and type
•Type
RETURN
to enter a new line, otherwise the line will wrap around
•DEL
deletes the character before the cursor and [Ctrl]-d the character
after the cursor. Hold down for repeated operation
•[Esc]del
and [Esc]d deletes whole words
•[Ctrl]-k
deletes from cursor to end of line. A further [Ctrl]-k deletes the
new line character
•Mark
and then delete a whole area:
–[Ctrl]-SPACE
at start and move cursor to end
–[Ctrl]-w
to delete the marked out region
•Commands that remove more than one character at a time save the
text. It can be yanked back with [Ctrl]-y
–Another
[Ctrl]-y
to yank back another copy
–[Esc]y
to yank back next previously deleted text
•Can use [Ctrl]-w and [Ctrl]-y to move text around
•Need
to be able to load and save files
•[Ctrl]-x
[Ctrl]-f finds and loads a file
•Prompts
for the pathname in the minibuffer
•Type
the name and press RETURN
•Use
TAB
for filename completion
•File
is either loaded or created
•Changes
made on screen are not immediately made to the file, they are made to a
copy called the buffer
•Have
to explicitly write them back by saving, [Ctrl]-x s (all files)
[Ctrl]-x
[Ctrl]-s (current file) (answer y and n to prompts)
•Can
have more than one file open at a time. [Ctrl]-x f also switches
between buffers
•[Ctrl]-x
b swaps to the previous buffer
•Save
frequently - work will be lost if emacs or the system crashes
•A
buffer is best described as a temporary file that holds changes
you make to a saved file on disk.
•When
you save the file, Emacs overwrites the file with the contents of the buffer.
So, when you open a file in Emacs, you are actually opening a buffer that
holds the changes.
•You
can revert to a saved version of a buffer by choosing "Revert Buffer" from
the "Files" menu. This discards any changes since the last save.
•[Ctrl]-x
u undoes the previous commands
•Repeating
[Ctrl]-x
u takes you further back through the editing history
•Need
to search for text in a large file
•Incremental
search
–type
[Esc]
x
–enter
command isearch-forward or isearch-backwards in the minibuffer
(use TAB for command completion)
–enter
search string at the prompt and note how Emacs homes in and wraps around
end of file
–you
can delete the last character in the search string
–[Ctrl]-s
(search forwards) and [Ctrl]-r (backwards) may work instead and
[Ctrl]-g
to quit at any time
•Change
all occurrences of one string of text with another
–type
[Esc]x
–enter
query-replace
–enter
search and target strings
–type
y
or n at each prompt
–use
replace-string
to avoid the prompting
•[Esc]x
then spell-buffer for the spell checker
•Can
divide the edit window into smaller sub-windows, each with a different
document
•[Ctrl]-x
2 split horizontally
•[Ctrl]-x
3 split vertically
•[Ctrl]-x
1 make current window the full window
•[Ctrl]-x
o move cursor to the next window
•Modes configure Emacs for different kinds of editing, controlling
wrap-around and indenting
–[Esc]x
then mode name
–fundamental
mode
–text-mode
(gives automatic text wrapping)
–C++
mode
•May
guess mode from the filename suffix
•A
keyboard macro is a command defined by the user to abbreviate
a sequence of keys.
–For
example, if you discover that you are about to type a particular command
100 times, you can speed your work by defining a keyboard macro
with that particular command and calling the macro with a repeat
count of 100. The following construction is used:
1.[Ctrl]-x
( your command [Ctrl]-x).................defines macro
2.[Ctrl]-u
100 [Ctrl]-x e ....................................executes the macro 100
times
•[Ctrl]-h
for top level help menu
•[Ctrl]-h
[Ctrl]-h to find out what each menu option means
•[Ctrl]-h
t for the on-line tutorial