emacs for vi users
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 - x Ctrl - f
||Ctrl - x Ctrl - s
||Ctrl - x Ctrl - c
||Ctrl - b
||Ctrl - n
||Ctrl - p
||Ctrl - f
|back one word
||Esc - b
|foward one word
||Esc - f
|beginning of line
||Ctrl - a
|end of line
||Ctrl - e
||Ctrl - b
||Esc - v
||Ctrl - f
||Ctrl - v
|jump to line number 'n'
||Esc - x goto-line RET
||Ctrl - d
||Esc - d
||Ctrl - k Ctrl - k
|delete 'n' lines
||Esc - n Ctrl - k
||Ctrl - x u
|yank 'n' lines
||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
||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 %."
(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)))))
||Ctrl - s (text incremental search)
||Ctrl - r (text incremental search)
Books & References
GNU Emacs Pocket Reference, Authors: Debra
Cameron, Pub: O'Reilly
Learning GNU Emacs, Author: Debra
Cameron, Bill Rosenblatt & Eric Raymond, Pub: O'Reilly
GNU Emacs Manual, Author: Richard Stallman,
Pub: Free Software Foundation
||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.
||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).
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
||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 Books I Own
Vi in Emacs
Linux on Vaio
Source Code Browsers
C Struct Packing
Walt Disney World
Photographs of Flowers
Put this on your site!
The Sundial Bridge
Repetitive Strain Injury (RSI)
Selling Software Online (MicroISV)
Tcl Tk Life-Savers
The Experience Shows!
Web-Site Development Online