hidden text



Start and Stop
  • Emacs is located in /usr/bin or /usr/local/bin on any sane system. This of course means that it is located in /usr/local/gnu on the CS network.
  • To start emacs:
    romulus: [~] emacs
    or
    romulus: [~] emacs filename1 filename2 ...
    or
    romulus: [~] emacs -nw
    or
    romulus: [~] emacs -nw filename1 filename2 ...
  • To stop emacs:
    ctrl-x ctrl-c
  • To cancel whatever you are doing:
    ctrl-g


Files
  • To open a file within emacs:
    ctrl-x ctrl-f
  • To save the current file:
    ctrl-x ctrl-s
  • To save the current file with a new name (Windows: Save As...):
    ctrl-x ctrl-w
  • To save ALL open files:
    ctrl-x s

Buffers
  • Don't quit! If you learn how to read in multiple files into buffers in Emacs, you should never have to quit Emacs anymore, except at logout.
  • Switching to the next buffer is faster than starting a fresh Emacs session, and you still have your files around, cursor positioned at the point where you left off, et cetera.
  • To switch buffers using a buffer list:
    ctrl-x ctrl-b
  • To switch buffers by name:
    ctrl-x b
  • To kill a buffer:
    ctrl-x k

Help
  • A tutorial for beginners featuring hands-on learning:
    ctrl-h t
  • The info system (hypertext man pages):
    ctrl-h i
    On an info menu screen use:
    • m - select the current option/link
    • p - go back to the previous page
    • n - go forward to the next page
    • t - go to the top of the page
    • q - quit (or just kill the info buffer)
  • For an overview of the predefined key bindings (commands):
    ctrl-h b

Moving Around
  • For normal movement use the arrow keys. There is no beep mode.
  • Go to the beginning of a line:
    ctrl-a
  • Go to the end of a line:
    ctrl-e
  • Go to the beginning of a function:
    ctrl-meta-a
  • Go to the end of a function:
    ctrl-meta-e
  • Go to the beginning of the buffer:
    meta-<
  • Go to the end of the buffer:
    meta->
  • To go directly to a specific line number:
    ESC-g

Editing Text
  • Emacs has two text editing modes: insert mode and overwrite mode. Use the insert key to switch between them.
  • Emacs doesn't believe in the delete key use:
    ctrl-d
  • To kill a line (from the cursor to the end of line):
    ctrl-k
  • To paste a recently killed block (emacs calls paste yank):
    ctrl-y
  • Undo!
    ctrl-x u

Searching
  • To search:
    ctrl-s
  • To repeat search (find next...):
    ctrl-s
  • To search and replace:
    meta-shift-5
    or
    meta-%
    When you do a search and replace you will be prompted for each match. Proper responses are:
    • y - yes replace this match
    • n - no do not replace this match
    • ! - I am insane, replace all remaining matches
Splitting The Screen
  • Horizontal split :
    ctrl-x 2
  • Vertical split:
    ctrl-x 3
  • Jump to the other window:
    ctrl-x o
  • Scroll the other window:
    ctrl-meta-v
  • Revert to single window:
    ctrl-x 1

Marking Regions
  • Marking allows you to select a region just as though you highlighted it with the mouse. You can then perform various operations on the region between the mark and the current cursor position.
  • Set Mark Here:
    ctrl-space
  • Mark Paragraph:
    meta-h
  • Mark Function:
    ctrl-meta-h
  • Mark Whole Buffer (Select All...):
    ctrl-x h
  • Cut region:
    ctrl-w
  • Copy region:
    meta-w

Emacs as an IDE
  • Fancy file headers:
    meta-x make-header
  • Version Control:
  • Register a file for version control
    C-x v i
  • Commits a modified file that's already been registered for version control
    C-x v v
  • Save the revision comment and commit the change
    C-c C-c
  • Revert a buffer to the last revision
    C-x v u
  • See differences between buffer and last revision
    C-x v =
  • Retreive a given revision in another window
    C-x v ~
  • Compile:
    meta-x compile
  • Next Compiler Error:
    C-x `             (a backtick)
  • Debug:
    meta-x gdb
  • Hex Editor:
    meta-x hexel-mode

Stupid Emacs Tricks
  • Spell checker:
    meta-x ispell-buffer
  • Execute any shell command:
    meta-!
  • Start a new shell within emacs:
    meta-x shell
  • Send and Read email:
    meta-x rmail
  • Send and Read news posts:
    meta-x gnus
  • Using ftp is as simple as reading in a file (ctrl-x ctrl-f) and using a filename consisting of a username, site, and file in the following syntax:
    /(username)@(site):(file)
    (e.g. /anonymous@ftp.cerias.purdue.edu:/pub)

    Ange may then prompt you for a password. If the file opened was a regular file, it will be sucked into a buffer without copying it into your directory. You can also specify directories as as in the above example. Ange then uses the directory editor.
  • Recover lost file after a crash:
    meta-x recover-file
  • Restore a buffer to its original contents:
    meta-x revert-buffer
  • Seek professional help:
    meta-x doctor

Links and Stuff



hidden text