Home About Meetings Directions Mailing Lists Jobs

Emacs Tutorial May 1999 HTML format

From LILUG


Handy Emacs Tidbits

Assembled by Matt Surico, LILUG

Getting Help

C-h t Starts the tutorial
C-h a regexp Gives "apropos" help
C-h i Runs "info"
C-h f function gives help on the function
C-h k Gives help on a key
C-h C-h Shows all the subsystems in help (including t,a,i,f,k above)

File Basics

C-x C-f filename Opens filename for editing
C-x C-r filename Opens filename read-only
C-x C-s saves a buffer to the file in the buffer
C-x C-w filename saves the buffer to filename

Moving Around

C-a Go to beginning of line
M-a Go to beginning of sentence
C-e Go to end of line
M-e Go to end of sentence
C-f Go forward one character
M-f Go forward one word
C-b Go backwards one character
M-b Go backwards one word
C-n Go down one line
C-p Go up one line
M-r Go to middle of window
M-< Go to beginning of buffer
M-> Go to end of buffer
C-v Move down one window's worth of buffer
M-v Move up one window's worth of buffer
M-{ Go to beginning of paragraph
M-} Go to end of paragraph

Working in the Minibuffer

M-x command runs command
C-g quits the command

Using Numerical Arguments to Commands

M-number key-sequence Runs key-sequence that number of times
C-u number key-sequence Does the same thing
C-u key-sequence Uses 4 as the default
C-u's can be strung together (e.g., C-u C-u C-n moves down 16 lines)

Generally Important Stuff

C-x u Undo
C-x C-s Save
C-d Erase one character (the one after point)
M-d Kill one word (from after point to the end of the word)
C-k Kill from after point to the end of the line
C-x C-c Quit Emacs
C-z Suspend Emacs (character mode)
C-z C-z Suspend Emacs (X Window System mode)
C-t transpose characters on either side of point
M-t transpose words on either side of point

Regions

A region is an area of the buffer which you can define and then run commands against. Defining a region is usually done by setting the mark and then moving point.

C-< SPC > sets the mark
C-@ also sets the mark
C-x C-x exchanges mark and point
C-w kill the region (which removes it)
M-w place the region into the kill ring without removing it
C-x C-u convert the region to upper-case
C-x C-l convert the region to lower-case

The Kill Ring

Each string of characters "killed" is added to the bottom of the kill ring.

C-y yanks back last killed text
M-y yanks the text killed prior to the last killed text

Searching/Replacing

C-s performs a search forward
C-r performs a search backwards
< DEL > corrects mistakes while typing in a search string
C-s (after a previous C-s) re-runs the search
M-p moves backwards one on the search ring (similar to the kill ring)
M-n moves forwards one on the search ring
M-x replace-string < RET > string < RET >
M-x replace-regexp < RET > regexp < RET >

Spell Checking (ispell)

M-$ ispell word
M-x ispell-buffer
M-x ispell-region

Version Control

M-x version-control never (default) keeps one original ~ copy of your file
M-x version-control t keeps numbered copies of your file changes

Buffers

C-x b buffer change to default buffer
C-x C-b lists all buffers
C-x k buffer kills buffer buffer
M-x edit-tab-stops

Multiple Windows

C-x 2 splits the Emacs frame into 2 windows
C-x 3 splits the Emacs frame into 3 windows
C-x o switch to other window
M-x compare-windows
C-x 1 make this window the only visible window
C-x 0 make the other window the only visible window

Keyboard Macros

C-x ( begins a keyboard macro editing session
C-x ) ends a keyboard macro editing session
C-x e runs the keyboard macro you last defined
C-x C-k edits last defined keyboard macro

Dired

C-x d opens dired
flagging:
d flags a file for deletion
u removes the flag
x actually deletes a flagged file
~ flag all Emacs ~ backups for deletion
. flag "excess" numbered Emacs backups for deletion
f visit the file under the cursor
o visit the file under the cursor in another window
v view the file under the cursor
marking:
m marks a file
* marks all executables
@ marks all symbolic links
/ marks all directories
%u changes all marked files to upper-case
%l changes all marked files to lower-case
%R from-name to-name renames marked file
%C from-name to-name copies marked file
= runs diff on the file at point and the file marked

The Calendar

M-x calendar opens the calendar
C-f move forward one day
C-b move backward one day
C-n move forward one week
C-p move backward one week
M-} move forward one month
M-{ move backward one month
C-x ] move forward one year
C-x [ move backward one year
C-a move to beginning of week
C-e move to end of week
M-a move to beginning of the month
M-e move to end of the month
g d go to date (which is typed in via prompts)
. go to today
M-= display number of days in the current region
p d display day in the year (i.e. date n out of 365/6)
M displays three months of moon phases
q quits the calendar