Ex/EditCommandSummary(Version2.0) Exandeditaretexteditors,usedforcreatingand modifyingfilesoftextontheUNIXcomputersystem. Editisavariantofexwithfeaturesdesignedtomakeit lesscomplicatedtolearnanduse.Intermsofcommand syntaxandeffecttheeditorsareessentiallyidentical,and thiscommandsummaryappliestoboth. Thesummaryismeantasaquickreferenceforusers alreadyacquaintedwitheditorex.Fullerexplanations oftheeditorsareavailableinthedocumentsEdit:A Tutorial(aself-teachingintroduction)andtheExRefer-enceManual(thecomprehensivereferencesourcefor botheditandex).Bothofthesewriteupsareavailable intheComputingServicesLibrary. Intheexamplesincludedwiththesummary,commandsandtextenteredbytheuserareprintedinboldfacetodistinguishthemfromresponsesprintedbythe computer. TheEditorBuffer Inordertoperformitstaskstheeditorsetsasidea temporaryworkspace,calledabuffer,separatefromthe user’spermanentfile.Beforestartingtoworkonan existingfiletheeditormakesacopyofitinthebuffer, leavingtheoriginaluntouched.Alleditingchangesare madetothebuffercopy,whichmustthenbewritten backtothepermanentfileinordertoupdatetheold version.Thebufferdisappearsattheendoftheediting session. Editing:CommandandTextInputModes Duringaneditingsessiontherearetwousualmodes ofoperation:commandmodeandtextinputmode.(This disregards,forthemoment,openandvisualmodes,discussedbelow.)Incommandmode,theeditorissuesa colonprompt(:)toshowthatitisreadytoacceptand executeacommand.Intextinputmode,ontheother hand,thereisnopromptandtheeditormerelyaccepts texttobeaddedtothebuffer.Textinputmodeisinitiatedbythecommandsappend,insert,andchange,andis terminatedbytypingaperiodasthefirstandonlycharacteronaline. LineNumbersandCommandSyntax Theeditorkeepstrackoflinesoftextinthebuffer bynumberingthemconsecutivelystartingwith1and renumberingaslinesareaddedordeleted.Atanygiven timetheeditorispositionedatoneoftheselines;this positioniscalledthecurrentline.Generally,commands thatchangethecontentsofthebufferprintthenewcurrentlineattheendoftheirexecution. Mostcommandscanbeprecededbyoneortwolinenumberaddresseswhichindicatethelinestobeaffected. Ifonenumberisgiventhecommandoperatesonthat lineonly;iftwo,onaninclusiverangeoflines.Commandsthatcantakeline-numberprefixesalsoassume defaultprefixesifnonearegiven.Thedefaultassumed byeachcommandisdesignedtomakeitconvenientto useinmanyinstanceswithoutanyline-numberprefix. Forthemostpart,acommandusedwithoutaprefix operatesonthecurrentline,thoughexceptionstothis ruleshouldbenoted.Theprintcommandbyitself,for instance,causesoneline,thecurrentline,tobeprinted attheterminal. Thesummaryshowsthenumberoflineaddresses thatcanbeprefixedtoeachcommandaswellasthe defaultsassumediftheyareomitted.Forexample,(.,.) meansthatupto2line-numbersmaybegiven,andthat ifnoneisgiventhecommandoperatesonthecurrent line.(Intheaddressprefixnotation,‘‘.’’standsforthe currentlineand‘‘$’’standsforthelastlineofthe buffer.)Ifnosuchnotationappears,noline-numberpre-fixmaybeused. Somecommandstaketrailinginformation;onlythe moreimportantinstancesofthisarementionedinthe summary. OpenandVisualModes Besidescommandandtextinputmodes,exandedit provideonsomeCRTterminalsothermodesofediting, openandvisual.Inthesemodesthecursorcanbe movedtoindividualwordsorcharactersinaline.The commandsthengivenareverydifferentfromthestandardeditorcommands;mostdonotappearonthescreen whentyped.AnIntroductiontoDisplayEditingwithVi providesafulldiscussion. SpecialCharacters Somecharacterstakeonspecialmeaningswhenused incontextsearchesandinpatternsgiventothesubstitutecommand.Foredit,theseare‘‘ˆ ’’and‘‘$’’,meaning thebeginningandendofaline,respectively.Exhasthe followingadditionalspecialcharacters: .&*[]˜ Touseoneofthespecialcharactersasitssimplegraphic representationratherthanwithitsspecialmeaning,precedeitbyabackslash(\).Thebackslashalwayshasa specialmeaning. ComputingServices,U.C.Berkeley April3,1979 NameAbbrDescription Examples (.)appenda Beginstextinputmode,addinglinestothebuffer afterthelinespecified.Appendingcontinuesuntil‘‘.’’ istypedaloneatthebeginningofanewline,followed byacarriagereturn.0aplaceslinesatthebeginning ofthebuffer.

:a Threelinesoftext areaddedtothebuffer afterthecurrentline. . : (.,.)changec Deletesindicatedline(s)andinitiatestextinputmode toreplacethemwithnewtextwhichfollows.New textisterminatedthesamewayaswithappend.

:5,6c Lines5and6are deletedandreplacedby thesethreelines. . : (.,.)copyaddrco Placesacopyofthespecifiedlinesafterthelineindicatedbyaddr.Theexampleplacesacopyoflines8 through12,inclusive,afterline25.

:8,12co25 Lastlinecopiedisprinted : (.,.)deleted Removeslinesfromthebufferandprintsthecurrent lineafterthedeletion.

:13,15d Newcurrentlineisprinted : editfile edit!file e e!

Clearstheeditorbufferandthencopiesintoitthe namedfile,whichbecomesthecurrentfile.Thisisa wayofshiftingtoadifferentfilewithoutleavingthe editor.Theeditorissuesawarningmessageifthis commandisusedbeforesavingchangesmadetothe filealreadyinthebuffer;usingtheforme!overrides thisprotectivemechanism.

:ech10 Nowritesincelastchange :e!ch10 "ch10"3lines,62characters : filenamef Iffollowedbyaname,renamesthecurrentfileto name.Ifusedwithoutname,printsthenameofthe currentfile.

:fch9 "ch9"[Modified]3lines... :f "ch9"[Modified]3lines... : (1,$)globalgglobal/pattern/commands (1,$)global!g!orv Searchestheentirebuffer(unlessasmallerrangeis specifiedbyline-numberprefixes)andexecutescom-mandsoneverylinewithanexpressionmatchingpat-tern.Thesecondform,abbreviatedeitherg!orv, executescommandsonlinesthatdonotcontainthe expressionpattern.

:g/nonsense/d : (.)inserti Insertsnewlinesoftextimmediatelybeforethespecifiedline.Differsfromappendonlyinthattextis placedbefore,ratherthanafter,theindicatedline.In otherwords,1ihasthesameeffectas0a.

:1i Theselinesoftextwill beaddedpriortoline1. . : (.,.+1)joinj Joinlinestogether,adjustingwhitespace(spacesand tabs)asnecessary.

:2,5j Resultinglineisprinted :

NameAbbrDescription Examples (.,.)listl Printslinesinamoreunambiguouswaythantheprint commanddoes.Theendofaline,forexample,is markedwitha‘‘$’’,andtabsprintedas‘‘ˆ I’’.

:9l Thisisline9$ : (.,.)moveaddrm Movesthespecifiedlinestoapositionaftertheline indicatedbyaddr.

:12,15m25 Newcurrentlineisprinted : (.,.)numbernu Printseachlineprecededbyitsbufferlinenumber.

:nu 10Thisisline10 : (.)openo Tooinvolvedtodiscusshere,butifyouenteropen modeaccidentally,presstheESCkeyfollowedbyqto getbackintonormaleditorcommandmode.Editis designedtopreventaccidentaluseoftheopencommand. preservepre Savesacopyofthecurrentbuffercontentsasthough thesystemhadjustcrashed.Thisisforuseinan emergencywhenawritecommandhasfailedandyou don’tknowhowelsetosaveyourwork.† :preserve Filepreserved. : (.,.)printpPrintsthetextofline(s).

:+2,+3p Thesecondandthirdlines afterthecurrentline : quit quit! q q!

Endstheeditingsession.Youwillreceiveawarningif youhavechangedthebuffersincelastwritingitscontentstothefile.Inthiseventyoumusteithertypew towrite,ortypeq!toexitfromtheeditorwithout savingyourchanges.

:q Nowritesincelastchange :q! % (.)readfiler Placesacopyoffileinthebufferafterthespecified line.Address0ispermissibleandcausesthecopyof filetobeplacedatthebeginningofthebuffer.The readcommanddoesnoteraseanytextalreadyinthe buffer.Ifnolinenumberisspecified,fileisplaced afterthecurrentline.

:0rnewfile "newfile"5lines,86characters : recoverfilerec Retrievesacopyoftheeditorbufferafterasystem crash,editorcrash,phonelinedisconnection,orpreservecommand. (.,.)substitutes substitute/pattern/replacement/ substitute/pattern/replacement/gc Replacesthefirstoccurrenceofpatternonalinewith replacement.Includingagafterthecommand changesalloccurrencesofpatternontheline.Thec optionallowstheusertoconfirmeachsubstitution beforeitismade;seethemanualfordetails.

:3p Line3containsamisstake :s/misstake/mistake/ Line3containsamistake : †Seekassistancefromaconsultantassoonaspossibleaftersavingafilewiththepreservecommand,becausethe fileissavedonsystemstoragespaceforonlyoneweek.

NameAbbrDescription Examples undou Reversesthechangesmadeinthebufferbythelast buffer-editingcommand.Notethatthisexamplecon-tainsanotificationaboutthenumberoflinesaffected.

:1,15d 15linesdeleted newlinenumber1isprinted :u 15morelinesinfile... oldlinenumber1isprinted : (1,$)writefilew (1,$)write!filew!

Copiesdatafromthebufferontoapermanentfile.If nofileisnamed,thecurrentfilenameisused.Thefile isautomaticallycreatedifitdoesnotyetexist.A responsecontainingthenumberoflinesandcharacters inthefileindicatesthatthewritehasbeencompleted successfully.Theeditor’sbuilt-inprotectionsagainst overwritingexistingfileswillinsomecircumstances inhibitawrite.Theformw!forcesthewrite,confirmingthatanexistingfileistobeoverwritten.

:w "file7"64lines,1122characters :wfile8 "file8"Fileexists... :w!file8 "file8"64lines,1122characters : (.)zcountz Printsascreenfulloftextstartingwiththelineindicated;or,ifcountisspecified,printsthatnumberof lines.Variantsofthezcommandaredescribedinthe manual. !command Executestheremainderofthelineafter!asaUNIX command.Thebufferisunchangedbythis,andcontrolisreturnedtotheeditorwhentheexecutionof commandiscomplete.

:!date FriJun912:15:11PDT1978 ! : control-d Printsthenextscrolloftext,normallyhalfofa screen.Seethemanualfordetailsofthescrolloption. (.+1)<cr> Anaddressalonefollowedbyacarriagereturncauses thelinetobeprinted.Acarriagereturnbyitself printsthelinefollowingthecurrentline.

:<cr> thelineafterthecurrentline : /pattern/ Searchesforthenextlineinwhichpatternoccursand printsit.

:/Thispattern/ Thispatternnextoccurshere. : // Repeatsthemostrecentsearch.

:// Thispatternalsooccurshere. : ?pattern?

Searchesinthereversedirection forpattern. ??

Repeatsthemostrecentsearch, movinginthereversedirection throughthebuffer.