----------------------------------------------------------------------- This summary of GNU/Emacs written by Rajeev Pandey. Can be copied and distributed freely as long as this notice retained. Please send comments or corrections to rpandey@cs.orst.edu ----------------------------------------------------------------------- GNU/Emacs GNU -- GNU's Not Unix -- Richard Stallman (MIT) advanced, self-documenting, customizable, extensible real-time display editor. [mostly written in Lisp, some C for efficiency] display - WYSIWYG (what you see is what you get). realtime - updated frequently. advanced - text filling, auto-indent, viewing 2+ files, deals with characters, words, lines, paragraphs, sentences, pages. self-documenting - ^H to view options at any time. customizable - can change the definitions, or rearrange the command set. extensible - can create new commands (programs in Lisp) online (don't need to create a new version). ______________________________________________________________ | | | | | | | | | | | | | WINDOWS | | (can be subdivided vertically or horizontally) | | | | | | | | | | | |____________________________________________________________| | MODE LINE | |------------------------------------------------------------| | ECHO LINE | |____________________________________________________________| The Mode Line _________________________________________________________ |--ch-Emacs: ()----pos---| --------------------------------------------------------- (ch = ** means changed (pos = nn%, Top, Bot, All) %% means read-only) (mode = Fundamental, Text, Lisp, C, TeX) Emacs uses the ASCII character set. makes 7 bit ASCII --> 8 bit ASCII (=> 256 possible command chars) extra bit : Meta character In termcap, Meta-flag is ESC. ASCII graphics displayed with graphics (i.e. LF, Tab) non-ASCII (128+) displayed in octal. Keys are bound to functions (Lisp objects that can be executed) Bindings recorded in a keymap (changing bindings requires messing with some variables, since command behavior <--> variable values). Emacs comes up in insert mode. Use BkSp to delete last character. ___________________________________ Conventions: ^ = Ctrl or Cntrl (C) esc = Meta (M) case insensitive (^H usually bound to the DEL key and vice versa) ___________________________________ Entering Emacs % emacs + [ n = line number -l [ load Lisp file -f [ call Lisp function w/o args -kill [ exit w/o reconfirming -t -batch -q [ don't load the init file (called .emacs) Exiting Emacs suspending: ^Z (put emacs in the background) kill: ^X^C (asks if user wishes to save changes, kills editing session) [note: ^C and ^Z are redefined within emacs, not handled in a "UNIX manner"] Emacs Tutorial enter emacs, then: ^H T Moving Around in Emacs ^V move 1 screen forward V move 1 screen backwards ^L repaint, move cursor to center of the screen Line Movements: . / \ ^P | | ^B ^F <------ ------> | | \ / ^N ` ^X^N set goal column (cursor position in line for ^N, ^P) ^U^X^N unset goal column esc F move forward word esc B move backward word ^A move to beginning of a line ^E move to the end of a line esc A beginning of sentence esc E end of a sentence esc > beginning of file esc < end of file Repeating Commands: ^U repeat command n times (or hold down or ^ key while typing n) repeating n times with ^V or V causes the screen to scroll n lines, *not* n screens. ^U means repeat command 4 times ^U^U means repeat command 16 times Deleting: delete character ^D delete next character after the cursor kill word immediately before cursor. D kill word after cursor ^K kill from cursor to eoln K kill from current position to the end of sentence, ^K -n: previous n lines +n: next n lines ^ delete , join 2 lines Undoing Changes ^Y yank back deleted text Y go backwards in killed text ^X^U undo last change (repeating this command undoes earlier and earlier changes) [8000 character undo buffer] ^_ undo (DEC terminals: ^/) ^ break sequence of undo commands, making the previous undos normal commands, that then can themselves be undone. ^G discard beginning of command that you don't want to finish or quit long computation hanging emacs, ^X character extend (1 character) X named command extend (long names) Command Completion X can use command completion: example: instead of "replace-string" say "replace-st" complete as much as possible complete to one word ? list all the alternates Miscellaneous M information on a mode X auto-fill-mode (breaks lines automatically) S center a line ^X F set margin (fill column) to cursor position Q refill paragraph (if you made changes) G fill each paragraph in the region. Searching ^S search forward (incremental search) ^R search reverse backup in search X top-level exit recursive editing mode ^H (actually ) help followed by help key: c most basic help k more help a appropos f describe function ^O insert blank line ^X^O delete all but one of many blank lines ^X I insert file ^@ set mark ^X^X exchange cursor and mark Cutting and Pasting ^W cut marked region W copy the marked region ^Y paste (yank last text) Y replace reinserted killed text with previously killed text (kill ring) Buffers ^X A append to a buffer X insert-buffer Rectangles X delete-rectangle ------------------------------- X kill-rectangle | | X yank-rectangle | mark.----------- | X open-rectangle | | | | X clear-rectangle | | rectangle| | | | | | | -----------% | | cursor | ------------------------------- Mark Ring (upto 16 previous locations) ^U^@ set another mark Registers (single character name) ^X / r save position to register r ^X J r jump to position r ^X X r save region (text) to r (rectangles: ^X R r) ^X G r insert saved region from r (rectangles: ^X G r) Word Search ^S ^W search for words, ignoring differences in punctuation ^R ^W reverse word search Regular Expression Search ^ S Replacing Text Unconditional Replace X replace-string Query Replace % replace this one skip to next occurrence of string quit Transposing ^T transpose characters T transpose words ^T expressions (balanced) ^X^T transpose lines Case Conversion L convert last word to lowercase U convert last word to uppercase C convert last word to lowercase, but with capital initial character Spelling Checking (runs spell as an inferior process) $ check spelling of last word X spell-buffer X spell-region X spell-string Opening Files ^X^F find file ^X^V kill current buffer, get alternate file ^X 4 ^F put new file in a new window Saving Files ^X^S save current buffer ^X S save some buffers (lists changed buffers) --emacs automatically makes a backup file: ~ --its possible to have numbered backups ~~ --emacs can "lock" files to prevent simultaneous editing --emacs auto-saves the file after a a certain number of keystrokes (to the file ##) Dired ^X^D list the directory ^U^X^D verbose listing of directory --all sorts of file editing/deletion commands available Buffers ^X B create/switch to buffer ^X 4 B create/switch to buffer, but in another window ^X^B list buffers ^X K kill buffer Windows ^X 2 split window into 2 windows vertically ^X 5 split window into 2 windows horizontally ^X O select Other window ^X 0 kill (zero) the other window ^X 1 kill all but the selected (current) window ^X ^ (ctrl-X caret) make selected window taller ^X } make selected window wider ^X 4 D run dired in other window ^X 4 M compose mail in the other window Modes Fundamental (least special) LISP (can evaluate expressions etc....many modes here) C (can compile/correct errors from within emacs) FORTRAN (has keyword abbreviations) MDL Text TeX (can "incrementally compile" (and print) TeX/LaTeX !) Nroff Outline --the programming language modes follow the "proper" indentation rules --can also customize the indentation rules --also has facilities for manipulating comment lines --can keep a command log of changes --can create a Tag Table (description of how a multi-file program is broken up) indent appropriately newline + proper indentation Compiling Within Emacs X compile run the compiler, with errors to *compilation* buffer X kill-compiler ^X ` parse compiler error, and visit locus of error (i.e. bring up proper line/file) --can do same with grep, just substitute 'grep' for 'compile' above --can also use a makefile, if you have one, since X compile reads a shell command to execute Some LISP commands (modes: Emacs Lisp, Lisp Interaction, Lisp Mode, Inferior Lisp (Lisp shell + editor)) evaluate expression X eval-region X eval-current-buffer X run-lisp inferior Lisp mode need to setq inferior-lisp-program i.e.: (setq inferior-lisp-program "ibcl") X run-lisp will open up an inferior process running ibcl Some TeX/LaTeX Commands [emacs is 'smart enough' to recognize TeX or LaTeX (usually). X tex-mode decides which mode, if wrong, use the command X plain-tex-mode or X latex-mode to correct it.] X validate-TeX-buffer check each paragraph in the buffer for unbalanced braces or dollar signs. { insert '{}' and position the cursor between them " insert the right kind of quotes, depending on context insert a paragraph break (2 s), and validate previous paragraph. ^C^R invoke TeX on the current region + buffer header ^C^B invoke TeX on the entire current buffer ^C^K kill the inferior TeX process ^C^P print the output of the last ^C^R or ^C^B command ^C^Q show the print queue Executing Shell Commands single command: ! subshell: X shell Printing from Within Emacs X print-buffer (equivalent to lpr -p) X lpr-buffer (lpr) X print-region X lpr-region Other Emacs features: Read/Write mail using Rmail Recursive Editing Levels Customizing your .emacs file Customizing key bindings, variables, etc Fun things: Dissociated Press (jumbled but plausible output) X dissociated-press Towers of Hanoi X hanoi (upto 9 rings) Eliza X doctor undocumented (strange!) X yow Emulating your favorite editor EDT (the great DEC VMS editor) most edt key bindings are on the numeric keypad, which can really augment things well. X edt-emulation-on X edt-emulation-off vi (yuck) the "standard" Berkeley UNIX editor. 2 emulators available: X vi-mode (this just makes emacs look like vi insert mode, with vi commands) X vip-mode A Plug for tcsh Once you have gotten real familiar with emacs, you may want to look into switching from the csh (c shell) to the tcsh (tc shell). The nicest feature of tcsh is emacs-like command line editing, however, there are many others. One is command/file/pathname completion using , another is "spell checking" or correcting your commands using $ (so if you typed in a long pathname and missed a character, tcsh can correct it for you......). Also: periodic command execution, automatic logout, time-stamped history list, maintenance of history between logins, etc. My .emacs File (display-time) (setq-default version-control t) [display time displays the time, system load factor and a flag to indicate unread mail on the mode line (in addition to the other stuff] ---------------------------------+-------------------------------------------- Rajeev K. Pandey | Department of Computer Science | Internet: rpandey@ada.cs.orst.edu Oregon State University | Internet: r.pandey@ieee.org Dearborn Hall 303 | WWW: http://www.cs.orst.edu/~rpandey Corvallis, Oregon 97331-3202 USA | Phone: (541) 737-3273 Fax: 737-3014 ---------------------------------+--------------------------------------------