Composers' Desktop Project
On Using EMACS on the PC
by Archer Endrich
[EMACS is a text editor. It has over 2,000 built-in commands and allows the user to combine these commands into macros to automate work (Wikipedia). This document refers to microEMACS: the latest version (5.0) is available here and includes a Windows installer. R.F.]
- Invoke with emacs [filename] at the Windows Command prompt.
- F6 calls up some extra. Repeating F6 exits it,
removing it from the screen, while <Control-g> exits,
leaving it on the screen.
- The letter M in the Emacs documentation stands for the
<ESC> key. Here, ESC is written out in
- Keystrokes notations in the text below: all keystrokes are
contained inside angle brackets, e.g, <Del>.
- If two different keys are placed within one pair of brackets,
then both keys are meant to be pressed simultaneously. E.g.,
<Control-d>: the Control key is held down
while pressing the letter d (lower case without
the Shift key)
- Similarly, double keystrokes while holding down Control
could be written within one pair of brackets as in
<Control-x Control-w> or even <Control x w>.
- If two different keys are placed within separate pairs of
brackets, the first is to be pressed, released, and then the
second key pressed. E.g., <ESC> <Shift-R>:
press ESC, release it and then press Capital R,
i.e., with the Shift key.
- Enter text as normal.
- When saving, make sure you have the filename you want.
- If it is a new file or a file you're re-editing and need to save
to a new name, use:<Control-x> <Control-w>
<Control-x w> also works (i.e., while holding
down Control, press first the x and then the w).
You then see the prompt: 'Write file: ' and you need to enter a filename.
Remember, 8 characters plus an extension only, unless you have
a newer version of EMACS. Whatever extension you give it
(3 letters max) will be used without complaint or alteration
by EMACS this is a useful feature when creating the
various CDP files, with varying extensions, such as .brk,
- Save work as you go with <Control-x> <Control-s>
<Control-x s> also works (i.e., while holding
down Control, press first the x and then the s).
- Exit with <Control-x> <Control-c> (be sure
you've saved first as above).
<Control-x c> also works (i.e., while holding
down Control, press first the x and then the c).
- Delete text backwards with <Del> or
- Delete text forwards with <Control-d>
- Kill (delete from cursor position to end of line)
NB - This saves to a buffer and you can get it back with
- Delete a whole block of text:
- Set cursor to beginning of block and set a mark
by pressing <ESC-Spacebar>,
i.e., press Spacebar while holding down ESC.
This sets a 'mark'.
You will 'wipe' from the mark to the current
cursor position, so now:
- Move cursor to end of block and press <Control-w>
- Get it back again with <Control-y> (i.e.,
MOVING ABOUT IN THE FILE
- Move down a specified number of lines with <Control-u>
enter the number of lines for u if not the default 4
followed by <Shift-DownArrow>
(If you accidentaly press <Shift-Return>, you will get
u blank lines. You can recover from this by moving the cursor
to the start of the blank lines and repeating the procedure, this time
using <Shift-Del> instead of <Shift-DownArrow>.)
- Move to beginning of a line with <Control-a>
- Move to end of a line with <Control-e>
- Move to next line down with <Control-n>
- Move to next line up with <Control-p>
- Move forward one character with <Control-f>
- Move back one character with <Control-b>
- Reverse the order of the previous two letters with
<Control-t> e.g., 'ea' becomes 'ae'.
- Move one word at a time to the Right with
- Move one word at a time to the Left with
- Scroll down one page with <Control-v>
- Scroll up one page with <Control-z>
- Move to top of file with <Home> or
<ESC-< > (i.e., ESC followed by Shift
- Move to bottom of file with <End> or
<ESC-> > (i.e., ESC followed by
- <PageUp> and <PageDn> work OK
- Forwards: press <Control-s> or F1, enter
the text for which to search, then press <ESC>.
- Backwards: press <Control-r> or F2, enter
the text for which to search, then press <ESC>.
SEARCH & REPLACE (a very powerful and useful feature)
- Replace all instances of first typed-in string with the second
typed-in string, ending each string with <ESC>.
Thus: <ESC> <Shift-R> enter string...
<ESC> enter string... <ESC>. E.g.,
- Press <ESC>, release it and then press
- Now enter the text to be replaced.
- Press <ESC>.
- Now enter the new text that is to replace the previous text.
- Finally, press <ESC> again to make the replacement(s).
MACROS (run a whole sequence of operations)
- Start recording: <Control-x> <Shift-(>
- Then perform the sequence of operations to be repeated
- End recording: <Control-x> <Shift-)>
- Execute 1 instance of the sequence:
<Control-x> <e> release
Control-x before pressing e.
- Execute n instances of the sequence:
<Control-u> enter number of times,
and then press <Control-x> <e> to run
the sequence release Control-x before
NB - If you for example enter <Control-u> 10 for
10 instances of a sequence and then press <RETURN>
instead of <Control-x e>, you will get 10 blank lines.
You can recover from this by returning the cursor to the
beginning of the blank section and entering <Control-u>
10 and then press the <Delete> key.
- Open two windows with <Control-x> <2>
release Control-x and then press 2.
- Move to previous window with <Control-x> <p>
release Control-x and then press p.
- Move to new window with <Control-x> <o>
release Control-x and then press o.
- Open another file, e.g. in the same or (having moved to a
second window, with <Control-x> <Control-f>
<Control-x f> also works (i.e., while holding
down Control, press first the x and then the f).
You see the prompt: 'Find file: ', enter the name
of the file you want to open and then press <Return>.
If you have two windows open with two different files, you can
now CUT and PASTE between the two open files.
- Show existing buffers with <Control-x>
<Control-x b> also works (i.e., while holding
down Control, press first the x and then the b).
If there is one window open, a new window is created,
displaying the list of buffers.
If two windows are open it displays the list of buffers
in the opposite one.
- Change name of current buffer with <ESC>
Note that this only changes the buffer name, but does
not change the name of the file itself.
Use <Control-x w> to do that, i.e., Write
the file to a new name.