COP4610: Operating Systems &
Concurrent Programming |
up
↑ |
The Emacs Text Editor
If you would like to see a more complete tutorial on Emacs, check the Web.
At the time of this writing, the official Emacs documentation was posted at
http://www.gnu.org/software/emacs/manual/.
Beware: Emacs key bindings are completely
customizable. The key bindings in the table below are so frequently used
that they are unlikely to be modified in most installations. However, you
need to remember that other particular keys or keystroke combinations may
have different effects, depending on the the particular installation you are
using and the particular kind of file you are editing. (Unless you override
the feature, emacs will usually tries to guess what you are editing from the
filename extension, and helpfully switch to an appropriate editing mode.) You
can find out the current key bindings, from inside emacs, by the command
sequence "M-x describe-bindings".
Remember: if there is anything you think you don't like about
emacs, you can change it by defining your own environment in the ".emacs"
file of your home directory. For example, you can find key bindings
that mimic the vi interface.
Emacs
- Recommended text editor
- Customizable key bindings
- Based on a LISP programming language implementation, that can be used
by anyone to add functionality
- Now has many more such extensions than any one person will use
- Some you will find very useful, including:
- Multiple buffers/windows
- Can be run in language-specific modes
- use color to distinguish C reserved words, typenames, comments,
etc.
- match up bracketing symbols, such as "{" and "}"
- automatic indentation
- Can split screen, even running through a terminal emulator
- Can run Unix commands, shell, debugger, etc. in different portions
of screen
- Well integrated with the gdb, the Gnu
Debugger.
- Available for virtually all platforms<
- Already installed for your use on departmental servers
- Available for installation on your own workstation
Starting Up Emacs
- Log in to a system where it is installed
- Enter "emacs -nw filename" at the command line
(If you have X-windows support, just enter "emacs filename")
Getting your Own Copy of Emacs at Home
- It comes with most (all?) Linux distributions, and with the various Gnu
software distributions for other systems, such as MacPorts for Mac OS X and
Cygwin for MS Windows.
- You can download a Windows version, too, for free
- Browse to the Gnu Emacs
site, and read about how to get a copy.
- For non-Unix systems (Windows, Mac OS X):
- Be careful to notice and correct the file name suffix changes that
Windows sometimes makes without your permission
- Extract the emacs setup file you downloaded above
- Set up your workstation environment so that clicking on a file with
certain extensions will automatically invoke emacs
Ctrl and Meta Keys
- Emacs uses special key sequences for recognizing command or action
statements
- Entering text, including code, is verbatim, until a command statement
is encountered
- Command statements begin with either one of the two action keys: the
Ctrl or Meta keys
- Ctrl (abbreviated as 'C' in some emacs documentation) is the 'Ctrl' (short
for "Control") key on your keyboard
- Meta (abbreviated as 'M' in some emacs documentation) is either the 'Esc'
("Escape") or 'Alt' ("Alternate") key on your keyboard, depending on
how you set up your local emacs configuration
- Some people recommend using Alt as your meta key. Some like Esc.
- To issue a command or action sequence hold down the action key (if Ctrl
or Alt) and press the other key, or if you are using Esc for M, hit the Esc
key, release it, and then hit the other key.
- Examples:
- C-x : Means hold down 'Ctrl' and
press 'x' then release both
- C-X : Means hold down 'Ctrl' and press 'X'
('Shift' + 'x') then release both
- M-l : may means hold down 'Alt' and
press 'l' then release both, or if you are using 'Esc', press 'Esc',
release it, and then press 'l'.
- C-x C-s : Means hold down 'Ctrl' and press
'x' then release both, then hold down 'Ctrl' and press 's' and release
both.
- M-x t : Means do the right thing for M-x,
as described above, and then press and release 't'
Builtin Emacs Help
- tutorial: "C-h t"
or "M-x help-with-tutorial"
- searching for info about commands: "M-x apropos"
(prompts for string to search for commands)
- full on-line documentation: "M-x info"
(then scan down the page to find the sections on emacs)
- to get out of emacs: "C-x C-c"
A Few Frequently Used Emacs Commands
Basic
Commands |
C-x C-s |
Save file to disk |
C-x C-c |
Exit emacs |
C-e |
Move to the end of the line |
C-a |
Move to the beginning of the line |
C-x C-f |
Load a file from disk into emacs |
C-i |
Insert file at cursor |
C-x k |
Kill/delete buffer (Current is default) |
C-v |
Page Down |
M-v |
Page Up |
C-k |
Cut from cursor to end of line |
C-y |
Paste at cursor |
C-_ |
Undo |
|
Advanced
Commands |
C-SPACE |
Set mark |
C-w |
Cut from mark to cursor |
C-2 |
Splits screen into two sub screens horizontally |
C-1 |
Reduces sub screens to only 1 |
C-o |
Switch between sub screens |
C-s |
Search for word (forward) |
C-r |
Search for word (backward) |
M-% |
Query Replace |
C-c C-g |
Goto Line |
C-c i |
Ispell (spell check) word |
C-c C-i |
Ispell (spell check) buffer |
|