If the file exists then Emacs will open it for editing.
Otherwise Emacs will begin with a new buffer (document)
that will default to being saved with that filename.
Emacs can be started from X or from the console, the choice
is yours. The drawback of running Emacs from the console
is that menus are activated using the F10 key and
they're pretty ugly. (Emacs can do more than Vi, but Vi
is nicer to use at the console.) In X, you can also run
XEmacs, a jazzed-up version of the Emacs run from X. (Type
xemacs instead of emacs to run.)
Moving |
Cursor keys |
As you would expect. |
[PageUp] |
"
" |
[PageDn] |
" " |
|
M-< |
Move to start of buffer
(document). |
M-> |
Move to end of buffer (document). |
|
C-l (el) |
Scroll display so that
current line is in the middle. |
|
M-f |
Move forward a word. |
M-b |
Move back a word. |
|
C-a |
Move to start of line. |
C-e |
Move to end of line. |
|
M-a |
Move to start of sentence. * |
M-e |
Move to end of sentence.
* |
* Only works if 2 spaces
follow/precede sentence. |
|
Cut (kill), copy, & paste (yank)
|
To Cut or Copy text you need to set a
"mark" and a "point". Move the cursor to a particular
position and press C-Space to set the mark.
The point is just the position of the cursor so move
it one space beyond where you want to cut or copy. |
C-w |
Cut (Emacs terminology: "kill the
region"). |
C-k |
This Cuts but you don't
set a Mark to use it. Move the cursor somewhere, and
whilst holding down the Ctrl key, tap away at the k
key. Now move somewhere else and press Ctrl+y. Note
that when you use repitition (e.g. C-u 5 C-k) you don't
need to take the cutting of the newline characters into
account. The best way of understanding this command
is to play about with it for a few minutes. |
|
M-w |
Copy. |
|
C-y |
Paste (Emacs terminology:
"yank text into buffer"). |
M-y |
After you paste some text you can replace
with text you've previously cut or copied it by cycling
backwards through all the text you've cut or copied. |
|
Save, open (find), & exit
|
When you first save a modified
document in Emacs, the original file will be saved as
~filename in case you ever want to revert
back to it. Emacs will also autosave your document in
case of power loss, a crash etc, giving the autosaved
file the name #filename# and delete
the file every time you save the document. To recover
a file, open the normal file (not the autosaved file)
and enter: M-x recover file. |
C-x C-s |
Save current buffer to file. |
C-x C-w |
Save current buffer
as... |
C-x s |
If you had many buffers open, it would
be annoying if you had to swap to each before saving
them. This will ask in turn, ask which you want to save. |
|
C-x C-f |
Open (Emacs Terminology:
"find") a file into a new buffer (filename completion
available with Tab key). By opening a file that doesn't
exist, you start a new named document. And by opening
a file that's already open you switch to it. |
C-x d |
Browse your Linux filesystem. Either press
Enter or the middle mouse button (both together on a
2 button mouse) to open a file or move to another directory. |
C-x i |
Insert contents of another
file at cursor. |
|
C-x C-c |
Exit Emacs. (Note: In console mode you
could also suspend Emacs with Ctrl+z, do something else,
then bring it back with: fg (In X, Ctrl+z will
just minimise the window.)) |
|
Search & replace
|
C-s |
Enter isearch mode. Type the word, word
completion will take place and Emacs will jump to the
next word that starts with what you've entered. Press
C-s for next occurence. (Document wrap takes place.) |
C-r |
Same as C-s but search
occurs in reverse direction. |
|
M-% |
Replace... |
|
Buffers/windows
|
C-x 1 |
Maximise current buffer. |
C-x 2 |
Switch current buffer
into 2. (Use: C-x o ("o" for "other") to switch from
top to bottom.) |
C-x 5 2 |
Open current buffer in new frame. |
C-x b |
Switch to another buffer. |
C-x C-b |
List buffers. |
C-x k |
Kill a buffer. Press
Enter to kill the current buffer or enter the name of
another buffer to kill. The name of a buffer is the
filename minus the path. |
|
Undo & redo
|
C-x u |
Undo (infinite). |
C-_ |
"
" |
|
Help
|
C-h k key combo |
Display documentation for key combo. |
C-h ? |
Display list of types
of help and how to access them. |
|
Repitition
|
Vi has it and Emacs has it. It's one of
the things that separates Unix/Linux editors from the
Windows crop. To repeat a command in Emacs press Ctrl+u,
followed by the amount of times to repeat an operation,
and finally the operation itself. Here's some examples: |
C-u 30 = |
Insert 30 "="s at cursor. |
C-u 10 [Down
Cursor] |
Move cursor down 10
lines. |
C-u 3 C-x u |
Undo 3 times. |
|
Miscellaneous
|
C-g |
Cancel half way through just about anything.
Very handy. |