12.07.2015 Views

GNU Emacs Reference Card (for version 18)

GNU Emacs Reference Card (for version 18)

GNU Emacs Reference Card (for version 18)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>GNU</strong> <strong>Emacs</strong> <strong>Reference</strong> <strong>Card</strong> (<strong>for</strong> <strong>version</strong> <strong>18</strong>)Starting emacsTo enter <strong>Emacs</strong>, just type its name: emacs. To read in a file to edit, seeFiles, belowLeaving <strong>Emacs</strong>suspend <strong>Emacs</strong> (the ususal way of leaving it)exit emacs permantlyFilesread a file to <strong>Emacs</strong>save a file back to diskinsert contents of another file into this bufferreplace this file with the file you really wantwrite buffer to a specifed filerun Dired, the directory editorC-zC-x C-cC-x C-fC-x C-sC-x iC-x C-vC-x C-wC-x dGetting HelpThe help system is simple. Type C-h and follow the directions. If youare first time user, type C-h t <strong>for</strong> a tutorial. (This card assumes youknow the tutorial.)get rid of Help window C-x 1scroll Help windowEsc C-vapropos: show commands matching a string C-h ashow the function a Key runsC-h cdescribe a functionC-h fget mode-specific in<strong>for</strong>mationC-h mError Recoveryabort partially typed or executing command C-grecover a file lost by a system crashM-x recover-fileundo a wanted change C-x u or C-restore a buffer to its original contents M-x revert-bufferredraw garbaged screenC-lIncremental Search1


search <strong>for</strong>wardsearch backwardregular expression searchC-sC-rC-M-sUse C-s or C-r again to repeat the search in either directionexit increamental searchundo effect of last characterabort current searchESCDELC-gIf <strong>Emacs</strong> is still searching, C-g will cancel the parts of the search notdone, otherwise it aborts the entire search.MotionCursor motion:entity to move over backward <strong>for</strong>wardcharacter C-b C-fword M-b M-fline C-p C-ngo to beginning (or end) C-a C-esentence M-a M-eparagraph M-[ M-]page C-x [ C-x ]sexp C-M-b C-M-ffunction C-M-a C-M-ego to buffer beginning (or end) M-< M->Screen Motion:scroll to next screenC-vscroll to previous screenM-vscroll left C-x Killing and Deletingentity to kill backward <strong>for</strong>wardcharacter(delete, not kill) DEL C-dword M-DEL M-dline (to end of) M-O C-k C-ksentence C-x DEL M-ksexp M-- C-M-k C-M-kkill regionC-w2


kill to next occurence of “char”yank back last thing killedreplace last yank with previous killM-z charC-yM-yMarkingset mark hereexchange point and markset mark “arg” words awaymark paragraphmark sexpmark functionmark entire bufferC-@ or C-SPCC-x C-xM-@M-hC-M-@C-M-hC-x hQuery Replaceinteractively replace a text stringusing regular expressionsValid responses in query-replace mode arereplace this one, go on to nextSPCreplace this one, don’t move ,skip to next without replacingDELreplace all remaining matches !back up to the previous match^exit query-replaceESCenter recursive edit(C-M-c to exit)C-rMultiple WindowsM-%M-x query-replace-regexpdelete all other windows C-x 1delete this window C-x 0split window in 2 vertically C-x 2split window in 2 horizontally C-x 5scroll other windowC-M-vswitch cursor to another windowC-x oshrink window shorterM-x shrink-windowshrink window tallerC-x ^shrink window narrower C-x {shrink window wider C-x }select a buffer in other windowC-x 4 bfind file in other windowC-x 4 f3


compose mail in other windowC-x 4 mrun Dired in other windowC-x 4 dfind tag in other window C-x 4 .Formattingindent current line(mode dependent)TABindent region(mode dependent)C-M-\indent sexp(mode dependent)C-M-qindent region rigidly ”arg” columnsC-x TABinsert newline after pointC-omove rest of the line vertically downC-M-odelete blank lines around pointC-x C-odelete all white space arround pointM-\put exactly one space at pointM-SPCfill paragraphM-qfill regionM-gset fill columnC-x fset prefix each line starts with C-x .Case Changeuppercase wordlowercase wordcapitalize worduppercase regionlowercase regioncapitalize regionM-uM-lM-cC-x C-uC-x C-lM-x capitalize-regionThe MinibufferThe following keys are defined in the minibuffercomplete as much as possibleTABcomplet up to one wordSPCcomplete and executeRETshow possible completions ?abort commandC-gType C-x ESC to edit and repeat the last command that used the minibuffer. The following keys are then defined.previous minibuffer commandnext minibuffer command4M-pM-n


Buffersselect another bufferlist all bufferskill a bufferC-x bC-x C-bC-x kTransposingtranspose characterstranspose wordstranspose linestranspose sexpsC-tM-tC-x C-tC-M-tSpelling Checkcheck spelling of current wordcheck speelin of all words in regioncheck spelling <strong>for</strong> entire bufferM-$M-x spell-regionM-x spell-bufferTagsfind tagfind next occurence of tagspecify a new tags fileregexp search on all files in tags tablequery replace all the filescontinue last tags search or query-replaceM-.C-u M-.M-x visit-tags-tableM-x tags-searchM-x tags-query-replaceM-,Shellsexecute a shell commandrun a shell command on the regionfilter region through a shell commandstart a shell in window *shell*M-!M-|C-u M-|M-x shellRmailscroll <strong>for</strong>wardSPCscroll reverseDELbegenning of message . (dot)next non-deleted messagenprevious non-deleted messagepnext messageM-n5


previous messagedelete messagedelete message and back upundelete messagereply to message<strong>for</strong>ward message to someonesend mailget newly arrived mailquit Rmailoutput message to another Rmail fileoutput message in Unix-mail styleshow summary of headersM-pdC-durfmgqoC-ohRegular ExpressionsThe following have special meaning inside a regular expression.any single character. (dot)zero or more repeats *one or more repeats +zero or one repeat ?any character in set [...]any character not in set[^...]beginning of line^end of line $quote a special character ”c” \calternative ”or” \|grouping \(. . . )\)nth group \nbeginning of buffer \‘end of buffer \’word break \bnot beginning or end of word \Bbeginning of word \any word-syntax character \wany non word-syntax character \Wcharacter with syntax ”c”\sccharacter with syntax not ”c”\ScRegisters6


copy region to registerC-x xinsert register contentsC-x gsave point in register C-x /move point to saved locationC-x jInfoenter the Info documentation readerMoving within a node:scroll <strong>for</strong>wardscroll reversebeginning of nodeMoving between nodes:next nodeprevious nodemove upselect menu item by nameselect ”n”th menu item by number (1-5)follow cross reference (return with l)return to last node you sawreturn to directory nodego to any node by nameC-h iSPCDEL.(dot)npumnfldgOther:run Info tutorialhlist Info commands ?quit Infoqsearch nodes <strong>for</strong> regexpsKeyboard Macrosstart defining a keyboard macro C-x (end keyboard macro definition C-x )execute last-defined keyboard macroC-x eappend to last keyboard macroM-x name-last-kbd-macroinsert lisp definition in bufferM-x insert-kbd-macroCommands Dealing with <strong>Emacs</strong> Lispeval sexp be<strong>for</strong>e pointC-x C-e7


eval current defuneval regioneval entire bufferread and eval minibufferre-execute last minibuffer commandread and eval <strong>Emacs</strong> Lisp fileload from standard system directoryC-M-xM-x eval-regionM-x eval-current-bufferM-ESCC-x ESCM-x load-fileM-x load-librarySimple CustomizationHere are some examples of binding global keys in <strong>Emacs</strong> Lisp. Note thatyou cannot say “\M-#”; you must say “\e#”.(global-set-key "\C-cg" ’goto-line)(global-set-key "\e\C-r" ’isearch-backward-regexp)An example of setting a variable in <strong>Emacs</strong> Lisp:(setq backup-by-copying-when-linked t)Writing Commands(defun ()""(interactive ""))An example:(defun this-line-to-top-of-screen (line)"Reposition line point is on to the top ofthe screen. With ARG, put point on line ARG.Negetive counts from bottom."(interactive "P")(recenter (if (null line)0(prefix-numeric-value line))))The argument to interactive is a string specifying how to get the argumentswhen the function is called interactively. Type C-h f interactive<strong>for</strong> more in<strong>for</strong>mation.8

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!