EmacsQuickReference Page1of4

EmacsQuick Emacs-Ring-SiteNumber27 Reference [NextSite|SkipNextSite|PreviousSite|SkipPreviousSite|ListSites| Home]

ByPaulSeamons

Notation ItisimportanttounderstandthenotationcommonlyusedinEmacsdocumentation.MostofthecommandsusedinEmacsconsistofamodifierkey,in conjuctionwithoneormoreotherkeys.Thefollowingarethecommonmodifierkeys: CTRL -()- TheCONTROLkey. META -(M)- DependingupontheterminalthisistheALTkey.YoumayalsousetheESCkeytosendMETA. ESC -(ESC)- TheESCAPEkey. SHIFT -(S)- TheSHIFTkey. InEmacsdocumentationitiscommontouseanabbreviatedsyntaxwhendescribingkeysequences.Insteadoftyping CTRL-xCTRL-c Youwouldtype C-xC-c ThiswouldrepresentholdingdowntheCONTROLkeyandpressingtheletterx,andthenholdingdowntheCONTROLkeyandpressingtheletterc. (M-C-\wouldrepresentholdingdownthetheALTkeyandCONTROLkeyandpressingthe"\"key.YoucouldalsopressandreleasetheESCAPEkey holddowntheCONTROLkeyandtypethe"\"key.) Thefollowingisatableofnotationforotherkeyboardcharacters. BACKSPC Thekey. SPC TheSPACEbar. ENTER TheEnterkey. RET TheEnterkey. TAB TheTABkey. Insert? ThisisalargeplacewhereEmacsdiffersfromtheVieditor.InViyouareeitherinInsertModeoryouarenot.Inordertoexecutecommandsotherthan keyinsertionyouneedtobeoutofInsertionMode.ByusingCTRLtoescapethekeysequences,Emacsallowsyoutousethecommandsatanypoint inyoursession.Forexample,ifyouareinViandareinsertingtextyouwouldhavetotypethefollowingkeysequencetosaveyourfileandreturnto InsertMode: ESC:wi InEmacs(whichisessentiallyalwaysin"InsertMode")youwouldtypethefollowing: C-xC-s Whenviewedfromtheinsertionmodeviewpoint,Vidoesn'treallysaveanykeystrokesoverEmacsasiscommonlyclaimedbyreligiousViadvocates. (Itactuallyrequiresmoreinmostcases-thedebateisreallywhetheryou'reinInsertModemorethanyouareinCommandMode.) Whatisreallyhappeningonthebackend Emacsisreallyabunchoflisproutinesprogrammedtooperateonthetextinthebuffers.Thesecomplexroutinesareaccessedviakeybindingsonthe frontend.Forexample,whenyoutypean"s"youarereallytellingEmacstorunthe"self-insert-command"ontheletter"s"whichinsertstheletter"s"at thecurrentPointofInsertion(POI).ThesebackendcommandscanbeaccessedbytypingM-xandthenthecommand.Forexample,youopenafile withthekeybinding"C-xC-f".Youcanbeginthesameoperationbytyping"M-xfind-file". KeyboardShortcuts-(KeyBindings) Key Binding Backend Function Whatitdoes QuitingThings M-xsave-buffers- .ExitsoutofEmacs.Ifyouhaveopenbuffersthathavebeenmodifiedyouareprompted C-xC-c QuitEmacs kill-emacs tosavethechangesordiscardthem. C-g M-xkeyboard-quit Ifyouareinakeyrequestsequencethatyoucan'tgetoutof,thisreturnsyoutothemainbuffer. M-xkeyboard- Doesaboutthesamethingas"C-g" ESCESCESC escape-quit C-xk M-xkill-buffer Killsthecurrentbuffer.Ifthebufferismodifiedyouarepromptedtosaveit. Filesanddirectories Openafile.Thispromptsforthenameofafile.Onceyouhavetypedthefileitopensitinthecurrent buffer.Ifthefiledoesn'texist,ablankbufferiscreatedandEmacsallowsyoutobegintyping(Inthiscase C-xC-f M-xfind-file thefilewillnotexistonthesystemuntilyousaveitthefirsttime).Whenyouaretypingthenameofthe file,youmayusethetabkeyforfilenamecompletion.AlsoyoumayuseM-pandM-ntogotothe "previous"and"next"filesthathavebeenfoundusingfind-file. C-xC-s M-xsave-buffer Saveafile.Thissavesthecurrentbuffer.

MoreHere.Thisopensthespecified(samewayasfind-file).Itopensabufferthatliststhe

http://seamons.com/emacs/ 08/25/03 EmacsQuickReference Page2of4

directoryandallowsyoutoperformoperationsonthefiles.listedinthatdirectory.Therearemany M-xdired(directory features(tomanytolisthere)thatIwillgointolater.Themostbasicistoputtheonthefileyou C-xd edit) wantandhitENTER.Thisdoesafind-fileonthatfile. C-xC-w M-xwrite-file Savethecurrentfileas... C-xi M-xinsert-file Insertafile Buffers Thislistsallbuffersthatareopen.Emacswilltypicallyopenabufferforeachfilethatyouvisit(ifyouvisit anewfilewithoutclosinganoldone).Thiswillgiveyoualistofallofthecurrentlyopenbuffersandwill allowyoutochooseonefromthelisttoswitchto.(Youwillnoticethereareacoupleofbuffersbeginning C-xC-b M-xlist-buffers withan*.ThesearebuffersusedbyEmacstostoreoutput.Youmaykillthemifyoulike.)Ifyouhavea fileopenedmultipletimes,youwillseeitlistedas"file"and"file<2>".Thislistofbuffersiscalledthe bufferring Switchbuffers.Doesjustthat.Thedefaultbuffertoswitchtoisthelastonethatyoucamefrom. M-xswitch-to- C-xb (TypingC-xbENTERrepeatedlyswapsbetweenthecurrentandthelastbufferlikeALT-TABin buffer windows.)YoumaytypeaTABtocompletethebuffernameorTABTABtoseealistofallofthebuffer namesyoucantype. C-xk M-xkill-buffer Killsthecurrentbuffer.Ifthebufferismodifiedyouarepromptedtosaveit. Windowsandframes Killsthecurrentwindowifmorethanoneisvisible.Thebuffercontainedinthewindowisputbacktothe M-xdelete-window C-x0 bufferring. M-xdelete-other- Ifmorethanonewindowisvisibleinthecurrentviewingframe,itremovesallbutthecurrentwindow. C-x1 windows Otherbuffersremainopenbutunviewed. M-xsplit-window- Splitsthecurrentviewingwindowintotwowindowsplacedoneovertheother. C-x2 vertically M-xsplit-window- Splitsthecurrentviewingwindowintotwowindowsplacedsidetoside. C-x3 horizontally C-xo M-xother-window Switchesbetweentwowindows. MovingAround C-p(up arrow) M-xprevious-line Movestothepreviousline. C-n(down arrow) M-xnext-line Movestothenextline. C-f(right arrow) M-xforward-char Moveforwardonecharacter C-f(left arrow) M-xbackward-char Movebackwardonecharacter M-f M-xforward-word Moveforwardoneword. M-xbackward- Movebackwardoneword. M-b word M-xbeginning-of- Movetothebeginningoftheline. C-a line C-e M-xend-of-line Movetothebeginningoftheline. M-xbackward- Movebackwardonesentence. M-a sentence M-xforward- Moveforwardonesentence. M-e sentence C-v M-xscroll-up Pagedownonepage. M-v M-xscroll-down Pageuponepage. M-> M-xend-of-buffer Movestotheendofthebuffer. M-xbeginning-of- Movestothebeginningofthebuffer. M-< buffer C-x] M-xforward-page InmostmodesdoesthesameasM-> M-xbackward- InmostmodesdoesthesameasM-< C-x[ page Gotoline.Doeswhatitsays.Ican'tbelievethatthereisnotadefaultkeybindingforthis(thereisin M-xgoto-line XEmacs).Iusuallysetupinmy.emacsfiletheline(global-set-key "\M-g" 'goto-line)whichtellsemacsto useM-gtorunthecommand. C-xo M-xother-window Switchesbetweentwowindows. Switchbuffers.Doesjustthat.Thedefaultbuffertoswitchtoisthelastonethatyoucamefrom. M-xswitch-to- C-xb (TypingC-xbENTERrepeatedlyswapsbetweenthecurrentandthelastbufferlikeALT-TABin buffer windows.)YoumaytypeaTABtocompletethebuffernameorTABTABtoseealistofallofthebuffer namesyoucantype. M-xset-mark- C-SPC command SetMark.Setsthemarktothecurrentcursorlocation(point).Manycommandsarerunontheregionin

http://seamons.com/emacs/ 08/25/03 EmacsQuickReference Page3of4

betweenthepointandmark. M-xexchange- Exchangesthepoint(cursorlocation)andthemark. C-xC-x point-and-mark CopyingandDeletingstuff C-_ M-xundo Undo.Undoesthelastcommand.Canbedonerepeatedly. C-d M-xdelete-char Delete.Deletesthecharacterunderthepoint(afterthecursorlocation). M-xdelete- .Deletesthecharacterbeforethepoint(beforethecursorlocation). BACKSPC backward-char Delete M-d M-xkill-word Killsthewordafterthecursorlocation.Placesonthekillring. M-xbackward-kill- Killsthewordbeforethecursorlocation.Placesonthekillring. M-BACKSPC word Kill.Killsfromthepointtotheendoftheline.Ifrepeatedinarow,allofkillsgointothesamekillring C-k M-xkill-line entry.Doingthisoncedoesnotkillthenewlineattheendoftheline.Repeatingkillsthenewline.(for example,tokilltheentirecurrentlineyouwouldtypeC-atomovetothebeginningoftheline,andC-kC-k tokillthelineandthenewline). C-y M-xyank Yank.Insertsthelastentryfromthekillring.Thiscanbedonerepeatedly. M-y M-xyank-pop Cyclethroughthekillring.OperatesonlyifthelastcommandwasC-y M-xset-mark- .Setsthemarktothecurrentcursorlocation(point).Manycommandsarerunontheregionin C-SPC SetMark command betweenthepointandmark. Killsthetextbetweenthemarkandthepoint.Placesonthekillring.Ifthebufferisreadonly,placestext M-xkill-region C-w onkillringbutwarnsaboutnotbeingabletomodifybuffer. M-w M-xkill-ring-save Placestextbetweenmarkandpointonthekillringwithoutkillingtext. M-z M-xzap-to-char Deletesthetextfromthepointuptothefirstinstanceofthespecifedcharacter SearchandReplace M-xisearch- Searchesforwardforthetypedintext.C-srepeatedlysearchesforwardmultipletimes.C-rswitches C-s forward directionofsearch. M-xisearch- Searchesbackwardforthetypedintext.C-rrepeatedlysearchesbackwardmultipletimes.C-sswitches C-r backward directionofsearch. Requeststwopatterns.Searchesforfirstpatternandreplaceswithsecondpattern.Promptsateach M-xquery-replace M-% match.(yfor"yesreplace",nfor"nonext",and!for"replaceall"). M-xisearch- Searchusingaregularexpression(asyoutypeit). C-uC-s forward-regexp M-xquery-replace- Queryreplacesusingaregularexpressionasthematch. M-C-% regexp Fixingupthetext M-xindent-relative- Indentthetextaccordingtotheprogrammodeyouarein. TAB maybe M-C-\ M-xindent-region Runsthe"TAB"onalllinesintheregion. M-u M-xupcase-word Uppercasifiesfromthepointtotheendoftheword. M-xdowncase- Lowercasifiesfromthepointtotheendoftheword. M-l word M-xtranspose- Swapscharactersbeforeandafterpointwithoneanother. C-t chars M-xtranspose- Swapscurrentandnextwordwithoneanother. M-t words Dired-DirectoryEditor Thisopensthedirectoryspecified(samewayasfind-file).Itopensabufferthatliststhedirectoryand M-xdired(directory allowsyoutoperformoperationsonthefiles.listedinthatdirectory.Therearemanyfeatures(tomanyto C-xd edit) listhere)thatIwillgointolater.ThemostbasicistoputthecursoronthefileyouwantandhitENTER. Thisdoesafind-fileonthatfile.

M-xdired- RunsaC-xC-f(find-file)onthecurrentlyhighlightedfile.Ifthefileisadirectory,thatdirectorywill advertised-find- ENTER beopenedindiredmodeinanewbuffer. file M-xdired-create- Promptsforanewdirectorynameandcreatesit. + directory M-xdired-flag- Flagsthecurrentfilefordeletion. d file-deletion M-xdired-flag- ~ backup-files Flagsallfilesendingwith~fordeletion(backupfiles) M-xdired-do-

http://seamons.com/emacs/ 08/25/03 EmacsQuickReference Page4of4

x flagged-delete Deleteallfilesmarkedfordeletion(linesbeginningwithaD M-xdired-do- Deletesthecurrentlyhighlightedfile(s) D delete M-xdired-do- Copiesthecurrentlyhighlightedfile(s).Promptsforthedestination. C copy M-xdired-do- Renamesthecurrentlyhighlightedfile(s).Promptsforthedestination. R rename Allcommandsinthis M-xdired-do- Renamesthecurrentlyhighlightedfile(s)usingregularexpressions.Promptsforaregexforfrom %R sectionwillonly rename-regex andto.(example-fromregex\(.+\).txt,toregex\1.text) operatewhenyou M-xdired-mark areindiredmode. m Markthecurrentfile(markswitha*) u M-xdired-unmark Unmarkthecurrentfile(markswithSPC-SPCisblank) M-xdired- Changesmarksfromfirstpromptedlettertosecondpromptedletter(example- - *c *cDSPC change-marks thiswillclearthedeletionflag)

M-xdired-do- Executecommandonfilesmarkedwith*.Ifyourcommandcontainsa*,thelistofmarkedfiles ! shell-command willbesubstitutedinplaceandexecuted.Otherwise,thecommandwillbeplayedoncewitheach markedfileasthelastargument. g M-xrevert-buffer Refreshesthecurrentdireddirectory. Help-Findingit M-xhelp-with- BeginstheEmacsbuiltinTutorial-highlyrecommended C-ht tutorial C-hk M-xdescribe-key Allowsyoutotypeinkeystrokesandseethebackendfunctionthattheyarerunning. M-xdescribe- Allowsyoutotypeafunctionnameandreceiveanexplanationofwhatitdoes. C-hf function M-xdescribe- AllowsyoutotypeaEmacsvariablenameandseeitscontents C-hv variable M-xdescribe- Showatableofallofthecurrentkeybindings. C-hb bindings Thisoneispossiblythemostimportant.ItentersintotheEmacshelpbrowserwhichallowsyoutoreadin C-hi M-xinfo depthaboutjustaboutanysubjectrelatingtoEmacs.(Basiccommandsare"l"forlast,"n"fornext,and "p"forprevious.)I'lltalkmoreaboutthislater. TextRegisters M-xcopy-to- Promptsforregisterletter.Savestextbetweenpointandmarkintheregister. C-xrs register C-xri M-xinsert-register Promptsforregisterletter.Insertsthetextsavedinthatregisteratpoint. PositionRegisters M-xpoint-to- Promptsforregisterletter.Savespointinregister. C-xrSPC register M-xjump-to- Promptsforregisterletter.Jumptstopointsavedinthatregister. C-xrj register Bookmarks Promptsforbookmarkname(defaultisbuffername).Savespointinabookmark.Thisinformationis M-xbookmark-set C-xrm savedevenifyoucloseEmacs. M-xbookmark- Promptsforbookmarkname.Jumptstopointsavedinthatbookmark(Evenifyouhadclosedyouremacs C-xrb jump session). M-xbookmark- Listsallsavedbookmarks.Typing"j"whenonabookmarkjumpstothefile.Diredcommandsareusedto C-xrl bmenu-list deletebookmarks(Type"d"whenonfile-then"x"todeletebookmark). Rectangles-(Priceless) C-xro M-xopen-rectangle Opensrectangleofwhitespacebetweenpointandmark. Replacestextbetweenpointandmarkwithrectangleoftext(promptsfortext).Thisisamajortimesaver. Typing C-xrt"OtherText"RET M-xstring- wouldreplace C-xrt rectangle SomeText OtherText SomeText With OtherText SomeText OtherText C-xrk M-xkill-rectangle Killstextbetweenpointandmarkandplacesinrectanglekillring. C-xry M-xyank-rectangle Insertslastkilledrectangleatpoint.

http://seamons.com/emacs/ 08/25/03