I created this page for those C programmers who, like me, are being forced
to learn how to use the emacs editor after years of using the Unix standard vi
editor. I will focus on how to do common things that you do when coding in C with the vi
editor. Note that while there may be more than one way to do something, and sometimes an
easier way to do something, the information I provide is more often a straight forward
translation of how you would do things in vi in terms of how you would do the
same thing using the emacs editor. Also what is here is the bare minimum to get
you started. Unlike in vi, in emacs you don't have to enter a
"insert" mode to add text -- what you type appears immediately on screen.
If you are a vi fan and have been experimenting with vi clones (vim, nvi
and the rest), then you need to check out the VIPER package in emacs.
Written by Michael Kifer, it's
cool, like vi on steroids.
Ctrl - SPACE, move cursor upto the first character of the line next to last line you
want to yank, Esc - w
place (emacs calls this yank -- yank from the copy buffer)
p or P
Ctrl - y
Match Parenthesis
Action
Vi
Emacs
match paranthesis
%
This is one vi feature I am addicted to and which made the change to emacs
tough because emacs does not have a direct way to do this even under it's various
programming modes. Below is some emacs lisp
code that I picked off from the Internet that will map the % key to do exactly what vi
does. A big thanks to whoever wrote this. (Thanks to Eric Pement (Sed FAQ) for pointing out that this is
from the Emacs FAQ).
What you need to do is open the file .emacs under your home directory and stick
the following lines as is in the file. Close and re-open emacs and, presto, you
can use the % like you do in vi. Note that I have not tested this extensively,
but it seems to work.
(global-set-key "%" 'match-paren)
(defun match-paren (arg)
"Go to the matching paren if on a paren; otherwise insert %."
(interactive "p")
(cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
((looking-at "\\s\)") (forward-char 1) (backward-list 1))
(t (self-insert-command (or arg 1)))))
Many commands in emacs bring up a prompt line at the bottom of
the editor screen (like the ":" command line at the bottom of the vi
editor) where you need to provide additional information after which you press the
Enter/Return key to cause the command to act.
Esc:
Unlike the Alt/Ctrl/Meta/Shift key combinations, Esc key combinations
require that you press and release the Esc key before you press the next key. On Unix
workstations, you may be able to use the Meta key instead of the Esc key (in which case,
you would keep the Meta key pressed when pressing the next key in the key combination).
On
NTEmacs (GNU Emacs compiled for Windows 9x/ME/NT/XP/2K) you can use the ALT key for Esc
key combinations (keeping the ALT key pressed when keying in the next key in the
combination).
Emacs is extremely powerful because it can be customised to
behave any way you want it to. Emacs
Lisp is the programming language that you use to customise emacs.
The latest version of this site has moved to it's own domain at http://www.grok2.com/. Please update your bookmarks and
links. Click here to go to the new site.
The latest version of this site has moved to it's own
domain at http://www.grok2.com/. Please update your
bookmarks and links. Click here to go to the new site.