Emacs Xemacs cheatsheet

The following emacs commands can make your life much simpler if you are editing with emacs or Xemacs. Remember that these are text editors and their world is very dependent on the computer keyboard. Yeah right, by now you shouldn't' be using the mouse at all.

[c-x means control-x or the keyboard combination <ctrl>-<x> ] [m-x means meta-x and at CCRMA is the keyboard combination <esc>-<x>]


      
      c-w:       cut 
      m-w:       copy
      c-y:       yank (paste)
      c-k:       kill (delete) line

      c-a:       move cursor to line beginning
      c-e:       move cursor to line end
      c-v:       move cursor to middle of file
      c-l:       position window so cursor is in the middle
      c-f:       move cursor ahead character
      c-b:       move cursor back one character

      c-s:       search for char-string (word) forward
      c-r        search for char-string (word) backward
      c-g:       quit emacs command (mini-buffer)
      
      c-x-3:     start two windows (vertical)
      c-x-2:     start two windows (horizontal)
      c-x-1:     go back to one window

      c-[space-bar]:  mark set (start selection)

      c-a:       beginning of line
      c-e:       end of line
      m-a:       beginning of paragraph
      m-e:       end of paragraph
      c-x-[:     goto beginning of file
      c-x-]:     goto end of file

      m-[shift] \% replace character string (word)


      c-x (:     start defining macro
      c-x ):     end defining macro
      c-x e:     execute macro

      c-x z:     repeat last command
          z:     repeat second to last command
      c-x m-z:   repeat last compex command


      c-[space-bar] c-e      select a line
      m-a  c-[space-bar] m-e  select a paragraph (region)

      m-x -> ispell-buffer  spell check file
      m-x -> ispell-region  spell check paragraph
      m-x -> latex-mode     go to \LaTeX mode
Make sure you also have a backup of your .emacs file or emacs preferences file. It would be a good idea to open it and understand it. You can add to this file your own command definitions and combinations. Pay good attention to the following lines and make sure the mode you are intending to use is part of this list.


 		 
(mapcar #'(lambda (element)  ;; emacs modes
            (setq auto-mode-alist 
     (pushnew element auto-mode-alist)))
        '(("\\.pike$"                 . pike-mode)
          ("\\.pmod$"                 . pike-mode)
          ("\\.ats$"                  . lisp-mode)
          ("\\.clm$"                  . lisp-mode)
          ("\\.cm$"                   . lisp-mode)
          ("\\.cmn$"                  . lisp-mode)
          ("\\.ins$"                  . lisp-mode)
          ("\\.cl$"                   . lisp-mode)
          ("\\.lisp$"                 . lisp-mode)
          ("\\.scm$"                  . scheme-mode)
          ("\\.sh$"                   . sh-mode)
          ("\\.bashrc"                . sh-mode)
          ("\\.gnus"                  . emacs-lisp-mode)
          ("\\.c$"                    . c-mode)
          ("\\.h$"                    . c-mode)
          ("\\.l$"                    . c-mode)
          ("\\.y$"                    . c-mode)
          ("\\.awk$"                  . c-mode)
          ("\\.cc$"                   . c-mode)
          ("\\.x$"                    . c-mode)
          ("\\.m$"                    . matlab-mode)
          ("\\.s$"                    . asm-mode)
          ("\\.p$"                    . pascal-mode)
          ("\\.txt$"                  . text-mode)
          ("\\.text$"                 . text-mode)
          ("\\.tex$"                  . latex-mode)
          ("\\.sm$"                   . latex-mode)
          ("\\.sty$"                  . latex-mode)
          ("\\.bib$"                  . bibtex-mode)
          ("\\.el$"                   . emacs-lisp-mode)
          ("\\.tcl$"                  . tcl-mode)
          ("\\.java$"                 . java-mode)
          ("\\.html$"                 . html-mode)
          ("\\.ohtml$"                . html-mode)
          ("[]>:/]Makefile"           . makefile-mode)
          ("[]>:/]\\..*emacs"         . emacs-lisp-mode)
          ("\\.rfc$"                  . rfc-mode)
          ("\\.id$"                   . rfc-mode)
          ("\\.isl$"                  . isl-mode)
          ("\\.php?$"                . php-mode)
          ("\\.Xdefaults$"            . xrdb-mode)
          ("\\.Xenvironment$"         . xrdb-mode)
          ("\\.Xresources$"           . xrdb-mode)
          ("*.\\.ad$"                 . xrdb-mode)
          ("\\.sql$"                  . sql-mode)
          ("\\.tbl$"                  . sql-mode)
          ("\\.sp$”                   . sql-mode)
          )
        )
Emacs is smart enough to recognize the file extension when you are opening a file and automatically will load the necessary mode so that your text will be formatted according to the text-mode you are going to edit. You turn-on this feature by adding file extensions and their relevant mode.

Suppose you want to use matlab mode. You also need to add the following code to you .emacs file:


 		 
  ;--------------------;
  ; Enable MATLAB mode ;
  ; -------------------;
  (autoload 'matlab-mode "matlab" "Matlab Editing Mode" t)
  (add-to-list 'auto-mode-alist '("\\.m$" . matlab-mode))
  (setq matlab-indent-function t)

  (defun my-matlab-mode-hook ()
    (setq matlab-indent-function t)  ; if you want function bodies indented
    (setq fill-column 76)            ; where auto-fill should wrap
    (turn-on-auto-fill))

  (setq matlab-mode-hook 'my-matlab-mode-hook)
  (autoload 'matlab-shell "matlab" "Interactive Matlab mode." t)
Emacs is very good for editing documents. The next lines will add some functionality to emacs so that you will feel at home while editing files in Emacs, feel free to add this code to your dot-emacs file.


 		 
     ;:* Initialise aucTeX
     ;:*(require 'tex-site)
     ;:*=======================
     ;:* load TeX-toolbar
     ;:*(require 'tex-toolbar)
     ;:*=======================
     ;:* autoload style files
     (setq TeX-auto-save t)
     (setq TeX-parse-self t)
     ;:*=======================
     ;; The documentstyle command is usually near the beginning.
     (setq-default TeX-auto-parse-length 200)
     (setq LaTeX-default-options "a4paper,12pt,german,normalheadings")
     (setq-default TeX-master t)
     ;:* 
     (add-hook 'latex-mode-hook 
               (function (lambda ()
                           (local-set-key (quote [228]) (quote "\"a"))
                           (local-set-key (quote [246]) (quote "\"o"))
                           (local-set-key (quote [252]) (quote "\"u"))
                           (local-set-key (quote [223]) (quote "\"s"))
                           (local-set-key (quote [196]) (quote "\"A"))
                           (local-set-key (quote [214]) (quote "\"O"))
                           (local-set-key (quote [220]) (quote "\"U"))
                                             
     (setq ispell-extra-args '("-t"))       ; start ispell in TeX mode
                           )))
In general before buying any books related to the subject matter of text editing, you should run the emacs tutorial inside emacs which will last about an hour but you will graduate as an “EmacSoologist”.

© Copyright 2001-2022 CCRMA, Stanford University. All rights reserved.
Created and Mantained by Juan Reyes