ViCommand&FunctionReference AlanP.W.Hewett Revisedforversion2.12byMarkHorton 1.Author’sDisclaimer Thisdocumentdoesnotclaimtobe100%complete.Thereareafewcommandslistedinthe originaldocumentthatIwasunabletotesteitherbecauseIdonotspeaklisp,becausethey requiredprogramswedon’thave,orbecauseIwasn’tabletomakethemwork.InthesecasesI leftthecommandout.Thecommandslistedinthisdocumenthavebeentriedandareknownto work.Itisexpectedthatprospectiveusersofthisdocumentwillreaditoncetogettheflavorof everythingthatvicandoandthenuseitasareferencedocument.Experimentationisrecommended.Ifyoudon’tunderstandacommand,tryitandseewhathappens. [Note:Inrevisingthisdocument,Ihaveattemptedtomakeitcompletelyreflectversion2.12ofvi. ItdoesnotattempttodocumenttheVAXversion(version3),butwithoneortwoexceptions (wrapmargin,arrowkeys)everythingsaidabout2.12shouldapplyto3.1.MarkHorton] 2.Notation [option]isusedtodenoteoptionalpartsofacommand.Manyvicommandshaveanoptional count.[cnt]meansthatanoptionalnumbermayprecedethecommandtomultiplyoriteratethe command.{variableitem}isusedtodenotepartsofthecommandwhichmustappear,butcan takeanumberofdifferentvalues.<character[-character]>meansthatthecharacteroroneof thecharactersintherangedescribedbetweenthetwoanglebracketsistobetyped.Forexample <esc>meanstheescapekeyistobetyped.<a-z>meansthatalowercaseletteristobe typed.ˆ <character>meansthatthecharacteristobetypedasacontrolcharacter,thatis, withthe<cntl>keyhelddownwhilesimultaneouslytypingthespecifiedcharacter.Inthisdocumentcontrolcharacterswillbedenotedusingtheuppercasecharacter,butˆ <uppercasechr> andˆ <lowercasechr>areequivalent.Thatis,forexample,<ˆ D>isequalto<ˆ d>.Themost commoncharacterabbreviationsusedinthislistareasfollows: <esc>escape,octal033 <cr>carriagereturn,ˆ M,octal015 <lf>linefeedˆ J,octal012 <nl>newline,ˆ J,octal012(sameaslinefeed) <bs>backspace,ˆ H,octal010 <tab>tab,ˆ I,octal011 <bell>bell,ˆ G,octal07 <ff>formfeed,ˆ L,octal014 <sp>space,octal040 <del>delete,octal0177 3.Basics TorunvitheshellvariableTERMmustbedefinedandexportedtoyourenvironment.Howyou dothisdependsonwhichshellyouareusing.Youcantellwhichshellyouhavebythecharacter itpromptsyouforcommandswith.TheBourneshellpromptswith‘$’,andtheCshellprompts -2-with‘%’.Fortheseexamples,wewillsupposethatyouareusinganHP2621terminal,whose termcapnameis‘‘2621’’. 3.1.BourneShell Tomanuallysetyourterminaltypeto2621youwouldtype: TERM=2621 exportTERM Therearevariouswaysofhavingthisautomaticallyorsemi-automaticallydonewhenyou login.Supposeyouusuallydialinona2621.Youwanttotellthistothemachine,butstillhave itworkwhenyouuseahardwiredterminal.Therecommendedway,ifyouhavethetsetprogram,istousethesequence tset−s−d2621>tset$$ .tset$$ rmtset$$ inyour.login(forcsh)orthesamethingusing‘.’insteadof‘source’inyour.profile(forsh).The abovelinesaysthatifyouaredialinginyouareona2621,butifyouareonahardwiredterminal itfiguresoutyourterminaltypefromanon-linelist. 3.2.TheCShell Tomanuallysetyourterminaltypeto2621youwouldtype: setenvTERM2621 Therearevariouswaysofhavingthisautomaticallyorsemi-automaticallydonewhenyou login.Supposeyouusuallydialinona2621.Youwanttotellthistothemachine,butstillhave itworkwhenyouuseahardwiredterminal.Therecommendedway,ifyouhavethetsetprogram,istousethesequence tset−s−d2621>tset$$ sourcetset$$ rmtset$$ inyour.login.*Theabovelinesaysthatifyouaredialinginyouareona2621,butifyouareon ahardwiredterminalitfiguresoutyourterminaltypefromanon-linelist. 4.NormalCommands Viisavisualeditorwithawindowonthefile.Whatyouseeonthescreenisvi’scurrentnotion ofwhatyourfilewillcontain,(atthispointinthefile),whenitiswrittenout.Mostcommands donotcauseanychangeinthescreenuntilthecompletecommandistyped.Shouldyougetconfusedwhiletypingacommand,youcanabortthecommandbytypingan<del>character.You willknowyouarebacktocommandlevelwhenyouheara<bell>.Usuallytypingan<esc>will producethesameresult.Whenvigetsanimproperlyformattedcommanditringsthe<bell>. Followingarethevicommandsbrokendownbyfunction. 4.1.EntryandExit Toentervionaparticularfile,type vifile Thefilewillbereadinandthecursorwillbeplacedatthebeginningofthefirstline.Thefirst screenfullofthefilewillbedisplayedontheterminal. *Onaversion6systemwithoutenvironments,theinvocationoftsetissimpler,justaddtheline‘‘tset −d2621’’toyour.loginor.profile.

-3-Togetoutoftheeditor,type ZZ Ifyouareinsomespecialmode,suchasinputmodeorthemiddleofamulti-keystrokecommand, itmaybenecessarytotype<esc>first. 4.2.CursorandPageMotion NOTE:Thearrowkeys(seethenextfourcommands)oncertainkindsofterminalswillnotwork withthePDP-11versionofvi.Thecontrolversionsorthehjklversionswillworkonanytermi-nal.Experienceduserspreferthehjklkeysbecausetheyarealwaysrightundertheirfingers. Beginnersoftenpreferthearrowkeys,sincetheydonotrequirememorizationofwhichhjklkeyis which.Themnemonicvalueofhjklisclearfromlookingatthekeyboardofanadm3a. [cnt]<bs>or[cnt]hor[cnt]← Movethecursortotheleftonecharacter.Cursorstopsattheleftmarginof thepage.Ifcntisgiven,thesecommandsmovethatmanyspaces. [cnt]ˆ Nor[cnt]jor[cnt]↓or[cnt]<lf> Movedownoneline.Movingoffthescreenscrollsthewindowtoforceanew lineontothescreen.Mnemonic:Next [cnt]ˆ Por[cnt]kor[cnt]↑ Moveuponeline.Movingoffthetopofthescreenforcesnewtextontothe screen.Mnemonic:Previous [cnt]<sp>or[cnt]lor[cnt]→ Movetotherightonecharacter.Cursorwillnotgobeyondtheendoftheline. [cnt]-Movethecursorupthescreentothebeginningofthenextline.Scrollifneces-sary. [cnt]+or[cnt]<cr> Movethecursordownthescreentothebeginningofthenextline.Scrollupif necessary. [cnt]$Movethecursortotheendoftheline.Ifthereisacount,movetotheendof theline"cnt"linesforwardinthefile. ˆ Movethecursortothebeginningofthefirstwordontheline. 0Movethecursortotheleftmarginofthecurrentline. [cnt]|Movethecursortothecolumnspecifiedbythecount.Thedefaultiscolumn zero. [cnt]wMovethecursortothebeginningofthenextword.Ifthereisacount,then moveforwardthatmanywordsandpositionthecursoratthebeginningofthe word.Mnemonic:next-word [cnt]WMovethecursortothebeginningofthenextwordwhichfollowsa"white space"(<sp>,<tab>,or<nl>).Ignoreotherpunctuation. [cnt]bMovethecursortotheprecedingword.Mnemonic:backup-word [cnt]BMovethecursortotheprecedingwordthatisseparatedfromthecurrentword bya"whitespace"(<sp>,<tab>,or<nl>). [cnt]eMovethecursortotheendofthecurrentwordortheendofthe"cnt"’thword hence.Mnemonic:end-of-word [cnt]EMovethecursortotheendofthecurrentwordwhichisdelimitedby"white space"(<sp>,<tab>,or<nl>).

-4- [linenumber]G Movethecursortothelinespecified.Ofparticularusearethesequences"1G" and"G",whichmovethecursortothebeginningandtheendofthefilerespectively.Mnemonic:Go-to NOTE:Thenextfourcommands(ˆ D,ˆ U,ˆ F,ˆ B)arenottruemotioncommands,inthatthey cannotbeusedastheobjectofcommandssuchasdeleteorchange. [cnt]ˆ DMovethecursordowninthefileby"cnt"lines(orthelast"cnt"ifanewcount isn’tgiven.Theinitialdefaultishalfapage.)Thescreenissimultaneously scrolledup.Mnemonic:Down [cnt]ˆ UMovethecursorupinthefileby"cnt"lines.Thescreenissimultaneously scrolleddown.Mnemonic:Up [cnt]ˆ FMovethecursortothenextpage.Acountmovesthatmanypages.Twolines ofthepreviouspagearekeptonthescreenforcontinuityifpossible. Mnemonic:Forward-a-page [cnt]ˆ BMovethecursortothepreviouspage.Twolinesofthecurrentpagearekeptif possible.Mnemonic:Backup-a-page [cnt](Movethecursortothebeginningofthenextsentence.Asentenceisdefinedas endingwitha".","!",or"?"followedbytwospacesora<nl>. [cnt])Movethecursorbackwardstothebeginningofasentence. [cnt]}Movethecursortothebeginningofthenextparagraph.Thiscommandworks bestinsidenroffdocuments.Itunderstandstwosetsofnroffmacros,−ms and−mm,forwhichthecommands".IP",".LP",".PP",".QP","P",aswell asthenroffcommand".bp"areconsideredtobeparagraphdelimiters.Ablank linealsodelimitsaparagraph.Thenroffmacrosthatitacceptsasparagraph delimitersisadjustable.SeeparagraphsundertheSetCommandssection. [cnt]{Movethecursorbackwardstothebeginningofaparagraph. ]]Movethecursortothenext"section",whereasectionisdefinedbytwosetsof nroffmacros,−msand−mm,inwhich".NH",".SH",and".H"delimitasection.Alinebeginningwitha<ff><nl>sequence,oralinebeginningwitha "{"arealsoconsideredtobesectiondelimiters.Thelastoptionmakesituseful forfindingthebeginningsofCfunctions.Thenroffmacrosthatareusedfor sectiondelimiterscanbeadjusted.SeesectionsundertheSetCommands section. [[Movethecursorbackwardstothebeginningofasection. %Movethecursortothematchingparenthesisorbrace.ThisisveryusefulinC orlispcode.Ifthecursorissittingona(){or}thecursorismovedtothe matchingcharacterattheotherendofthesection.Ifthecursorisnotsitting onabraceoraparenthesis,visearchesforwarduntilitfindsoneandthen jumpstothematchmate. [cnt]HIfthereisnocountmovethecursortothetopleftpositiononthescreen.If thereisacount,thenmovethecursortothebeginningoftheline"cnt"lines fromthetopofthescreen.Mnemonic:Home [cnt]LIfthereisnocountmovethecursortothebeginningofthelastlineonthe screen.Ifthereisacount,thenmovethecursortothebeginningoftheline "cnt"linesfromthebottomofthescreen.Mnemonic:Last MMovethecursortothebeginningofthemiddlelineonthescreen.Mnemonic: Middle m<a-z>Thiscommanddoesnotmovethecursor,butitmarkstheplaceinthefileand thecharacter"<a-z>"becomesthelabelforreferringtothislocationinthe file.Seethenexttwocommands.Mnemonic:markNOTE:Themark -5-commandisnotamotion,andcannotbeusedasthetargetofcommandssuch asdelete. ´ <a-z>Movethecursortothebeginningofthelinethatismarkedwiththelabel"<a-z>". ` <a-z>Movethecursortotheexactpositiononthelinethatwasmarkedwithwith thelabel"<a-z>". ´´ Movethecursorbacktothebeginningofthelinewhereitwasbeforethelast "non-relative"move.A"non-relative"moveissomethingsuchasasearchora jumptoaspecificlineinthefile,ratherthanmovingthecursororscrollingthe screen. `` Movethecursorbacktotheexactspotonthelinewhereitwaslocatedbefore thelast"non-relative"move. 4.3.Searches Thefollowingcommandsallowyoutosearchforitemsinafile. [cnt]f{chr} Searchforwardonthelineforthenextor"cnt"’thoccurrenceofthecharacter "chr".Thecursorisplacedatthecharacterofinterest.Mnemonic:findcharacter [cnt]F{chr} Searchbackwardsonthelineforthenextor"cnt"’thoccurrenceofthecharacter"chr".Thecursorisplacedatthecharacterofinterest. [cnt]t{chr} Searchforwardonthelineforthenextor"cnt"’thoccurrenceofthecharacter "chr".Thecursorisplacedjustprecedingthecharacterofinterest. Mnemonic:movecursoruptocharacter [cnt]T{chr} Searchbackwardsonthelineforthenextor"cnt"’thoccurrenceofthecharacter"chr".Thecursorisplacedjustprecedingthecharacterofinterest. [cnt];Repeatthelast"f","F","t"or"T"command. [cnt],Repeatthelast"f","F","t"or"T"command,butintheoppositesearch direction.Thisisusefulifyouovershoot. [cnt]/[string]/<nl> Searchforwardforthenextoccurrenceof"string".Wraparoundattheendof thefiledoesoccur.Thefinal</>isnotrequired. [cnt]?[string]?<nl> Searchbackwardsforthenextoccurrenceof"string".Ifacountisspecified, thecountbecomesthenewwindowsize.Wraparoundatthebeginningofthe filedoesoccur.Thefinal<?>isnotrequired. nRepeatthelast/[string]/or?[string]?search.Mnemonic:nextoccurrence. NRepeatthelast/[string]/or?[string]?search,butinthereversedirection. :g/[string]/[editorcommand]<nl> Usingthe:syntaxitispossibletodoglobalsearchesalathestandardUNIX "ed"editor.

-6-4.4.TextInsertion Thefollowingcommandsallowfortheinsertionoftext.Allmulticharactertextinsertionsareterminatedwithan<esc>character.Thelastchangecanalwaysbeundonebytypingau.The textinsertininsertionmodecancontainnewlines. a{text}<esc>Inserttextimmediatelyfollowingthecursorposition.Mnemonic:append A{text}<esc>Inserttextattheendofthecurrentline.Mnemonic:Append i{text}<esc>Inserttextimmediatelyprecedingthecursorposition.Mnemonic:insert I{text}<esc>Inserttextatthebeginningofthecurrentline. o{text}<esc>Insertanewlineafterthelineonwhichthecursorappearsandinserttext there.Mnemonic:opennewline O{text}<esc>Insertanewlineprecedingthelineonwhichthecursorappearsandinserttext there. 4.5.TextDeletion Thefollowingcommandsallowtheusertodeletetextinvariousways.Allchangescanalwaysbe undonebytypingtheucommand. [cnt]xDeletethecharacterorcharactersstartingatthecursorposition. [cnt]XDeletethecharacterorcharactersstartingatthecharacterprecedingthecursor position. DDeletestheremainderofthelinestartingatthecursor.Mnemonic:Deletethe restofline [cnt]d{motion} Deletesoneormoreoccurrencesofthespecifiedmotion.Anymotionfromsections4.1and4.2canbeusedhere.Thedcanbestuttered(e.g.[cnt]dd)to deletecntlines. 4.6.TextReplacement Thefollowingcommandsallowtheusertosimultaneouslydeleteandinsertnewtext.Allsuch actionscanbeundonebytypingufollowingthecommand. r<chr>Replacesthecharacteratthecurrentcursorpositionwith<chr>.Thisisaone characterreplacement.No<esc>isrequiredfortermination.Mnemonic: replacecharacter R{text}<esc>Startsoverlayingthecharactersonthescreenwithwhateveryoutype.Itdoes notstopuntilan<esc>istyped. [cnt]s{text}<esc> Substitutefor"cnt"charactersbeginningatthecurrentcursorposition.A"$" willappearatthepositioninthetextwherethe"cnt"’thcharacterappearsso youwillknowhowmuchyouareerasing.Mnemonic:substitute [cnt]S{text}<esc> Substitutefortheentirecurrentline(orlines).Ifnocountisgiven,a"$" appearsattheendofthecurrentline.Ifacountofmorethan1isgiven,all thelinestobereplacedaredeletedbeforetheinsertionbegins. [cnt]c{motion}{text}<esc> Changethespecified"motion"byreplacingitwiththeinsertiontext.A"$" willappearattheendofthelastitemthatisbeingdeletedunlessthedeletion involveswholelines.Motion’scanbeanymotionfromsections4.1or4.2. Stutteringthec(e.g.[cnt]cc)changescntlines.

-7-4.7.MovingText Viprovidesanumberofwaysofmovingchunksoftextaround.Thereareninebuffersintowhich eachpieceoftextwhichisdeletedor"yanked"isputinadditiontothe"undo"buffer.Themost recentdeletionoryankisinthe"undo"bufferandalsousuallyinbuffer1,thenextmostrecent inbuffer2,andsoforth.Eachnewdeletionpushesdownalltheolderdeletions.Deletionsolder than9disappear.Thereisalsoasetofnamedregisters,a-z,intowhichtextcanoptionallybe placed.Ifanydeleteorreplacementtypecommandisprecededby"<a-z>,thatnamedbuffer willcontainthetextdeletedafterthecommandisexecuted.Forexample,"a3ddwilldeletethree linesstartingatthecurrentlineandputtheminbuffer"a.*Therearetwomorebasiccommands andsomevariationsusefulingettingandputtingtextintoafile. ["<a-z>][cnt]y{motion} Yankthespecifieditemor"cnt"itemsandputinthe"undo"bufferorthe specifiedbuffer.Thevarietyof"items"thatcanbeyankedisthesameasthose thatcanbedeletedwiththe"d"commandorchangedwiththe"c"command. Inthesamewaythat"dd"meansdeletethecurrentlineand"cc"means replacethecurrentline,"yy"meansyankthecurrentline. ["<a-z>][cnt]YYankthecurrentlineorthe"cnt"linesstartingfromthecurrentline.Ifno bufferisspecified,theywillgointothe"undo"buffer,likeanydeletewould.It isequivalentto"yy".Mnemonic:Yank ["<a-z>]pPut"undo"bufferorthespecifiedbufferdownafterthecursor.Ifwholelines wereyankedordeletedintothebuffer,thentheywillbeputdownontheline followingthelinethecursorison.Ifsomethingelsewasdeleted,likeawordor sentence,thenitwillbeinsertedimmediatelyfollowingthecursor.Mnemonic: putbuffer Itshouldbenotedthattextinthenamedbuffersremainstherewhenyoustart editinganewfilewiththe:efile<esc>command.Sincethisisso,itispossibletocopyordeletetextfromonefileandcarryitovertoanotherfileinthe buffers.However,theundobufferandtheabilitytoundoarelostwhenchangingfiles. ["<a-z>]PPut"undo"bufferorthespecifiedbufferdownbeforethecursor.Ifwhole lineswhereyankedordeletedintothebuffer,thentheywillbeputdownonthe lineprecedingthelinethecursorison.Ifsomethingelsewasdeleted,likea wordorsentence,thenitwillbeinsertedimmediatelyprecedingthecursor. [cnt]>{motion}Theshiftoperatorwillrightshiftallthetextfromthelineonwhichthecursor islocatedtothelinewherethemotionislocated.Thetextisshiftedbyone shiftwidth.(Seesection6.)>>meansrightshiftthecurrentlineorlines. [cnt]<{motion}Theshiftoperatorwillleftshiftallthetextfromthelineonwhichthecursoris locatedtothelinewheretheitemislocated.Thetextisshiftedbyone shiftwidth.(Seesection6.)<<meansleftshiftthecurrentlineorlines. Oncethelinehasreachedtheleftmarginitisnotfurtheraffected. [cnt]={motion}Prettyprintstheindicatedareaaccordingtolispconventions.Theareashould bealisps-expression. 4.8.MiscellaneousCommands Vihasanumberofmiscellaneouscommandsthatareveryuseful.Theyare: ZZThisisthenormalwaytoexitfromvi.Ifanychangeshavebeenmade,thefile iswrittenout.Thenyouarereturnedtotheshell. *Referringtoanuppercaseletterasabuffername(A-Z)isthesameasreferringtothelowercase letter,exceptthattextplacedinsuchabufferisappendedtoitinsteadofreplacingit.

-8-ˆ LRedrawthecurrentscreen.Thisisusefulifsomeone"write"syouwhileyouare in"vi"orifforanyreasongarbagegetsontothescreen. ˆ ROndumbterminals,thosenothavingthe"deleteline"function(thevt100is suchaterminal),visavesredrawingthescreenwhenyoudeletealinebyjust markingthelinewithan"@"atthebeginningandblankingtheline.Ifyou wanttoactuallygetridofthelinesmarkedwith"@"andseewhatthepage lookslike,typingaˆ Rwilldothis. ."Dot"isaparticularlyusefulcommand.Itrepeatsthelasttextmodifying command.Thereforeyoucantypeacommandonceandthentoanotherplace andrepeatitbyjusttyping".". uPerhapsthemostimportantcommandintheeditor,uundoesthelastcommandthatchangedthebuffer.Mnemonic:undo UUndoallthetextmodifyingcommandsperformedonthecurrentlinesincethe lasttimeyoumovedontoit. [cnt]JJointhecurrentlineandthefollowingline.The<nl>isdeletedandthetwo linesjoined,usuallywithaspacebetweentheendofthefirstlineandthe beginningofwhatwasthesecondline.Ifthefirstlineendedwitha"period", thentwospacesareinserted.Acountjoinsthenextcntlines.Mnemonic:Join lines QSwitchtoexeditingmode.Inthismodeviwillbehaveverymuchlikeed. Theeditorinthismodewilloperateonsinglelinesnormallyandwillnot attempttokeepthe"window"uptodate.Onceinthismodeitisalsopossible toswitchtotheopenmodeofediting.Byenteringthecommand[linenumber]open<nl>youenterthismode.Itissimilartothenormalvisualmode exceptthewindowisonlyonelinelong.Mnemonic:Quitvisualmode ˆ ]Anabbreviationforatagcommand.Thecursorshouldbepositionedatthe beginningofaword.Thatwordistakenasatagname,andthetagwiththat nameisfoundasifithadbeentypedina:tagcommand. [cnt]!{motion}{UNIXcmd}<nl> AnyUNIXfilter(e.g.commandthatreadsthestandardinputandoutputs somethingtothestandardoutput)canbesentasectionofthecurrentfileand havetheoutputofthecommandreplacetheoriginaltext.Usefulexamplesare programslikecb,sort,andnroff.Forinstance,usingsortitwouldbepossibletosortasectionofthecurrentfileintoanewlist.Using!!meanstakea lineorlinesstartingatthelinethecursoriscurrentlyonandpassthemtothe UNIXcommand.NOTE:Tojustescapetotheshellforonecommand,use :!{cmd}<nl>,seesection5. z{cnt}<nl>Thisresetsthecurrentwindowsizeto"cnt"linesandredrawsthescreen. 4.9.SpecialInsertCharacters Therearesomecharactersthathavespecialmeaningsduringinsertmodes.Theyare: ˆ VDuringinserts,typingaˆ Vallowsyoutoquotecontrolcharactersintothefile. Anycharactertypedaftertheˆ Vwillbeinsertedintothefile. [ˆ ]ˆ Dor[0]ˆ D<ˆ D>withoutanyargumentbacksuponeshiftwidth.Thisisnecessaryto removeindentationthatwasinsertedbytheautoindentfeature.ˆ <ˆ D>temporarilyremovesalltheautoindentation,thusplacingthecursorattheleft margin.Onthenextline,thepreviousindentlevelwillberestored.Thisis usefulforputting"labels"attheleftmargin.0<ˆ D>saysremoveallautoindentsandstaythatway.Thusthecursormovestotheleftmarginandstays thereonsuccessivelinesuntil<tab>’saretyped.Aswiththe<tab>,the <ˆ D>isonlyeffectivebeforeanyother"non-autoindent"controllingcharacters -9-aretyped.Mnemonic:Deleteashiftwidth ˆ WIfthecursorissittingonaword,<ˆ W>movesthecursorbacktothebeginningoftheword,thuserasingthewordfromtheinsert.Mnemonic:erase Word <bs>Thebackspacealwaysservesasaneraseduringinsertmodesinadditiontoyour normal"erase"character.Toinserta<bs>intoyourfile,usethe<ˆ V>to quoteit. 5.:Commands Typinga":"duringcommandmodecausesvitoputthecursoratthebottomonthescreenin preparationforacommand.Inthe":"mode,vicanbegivenmostedcommands.Itisalsofrom thismodethatyouexitfromviorswitchtodifferentfiles.Allcommandsofthisvarietyareterminatedbya<nl>,<cr>,or<esc>. :w[!][file]Causesvitowriteoutthecurrenttexttothedisk.Itiswrittentothefileyou areeditingunless"file"issupplied.If"file"issupplied,thewriteisdirectedto thatfileinstead.Ifthatfilealreadyexists,viwillnotperformthewriteunless the"!"issuppliedindicatingyoureallywanttodestroytheoldercopyofthe file. :q[!]Causesvitoexit.Ifyouhavemodifiedthefileyouarelookingatcurrentlyand haven’twrittenitout,viwillrefusetoexitunlessthe"!"issupplied. :e[!][+[cmd]][file] Starteditinganewfilecalled"file"orstarteditingthecurrentfileoveragain. Thecommand":e!"says"ignorethechangesI’vemadetothisfileandstart overfromthebeginning".Itisusefulifyoureallymessupthefile.The optional"+"saysinsteadofstartingatthebeginning,startatthe"end",or,if "cmd"issupplied,execute"cmd"first.Usefulcasesofthisarewherecmdis "n"(anyinteger)whichstartsatlinenumbern,and"/text",whichsearchesfor "text"andstartsatthelinewhereitisfound. ˆˆ Switchbacktotheplaceyouwerebeforeyourlasttagcommand.Ifyourlast tagcommandstayedwithinthefile,ˆ ˆ returnstothattag.Ifyouhaveno recenttagcommand,itwillreturntothesameplaceinthepreviousfilethatit wasshowingwhenyouswitchedtothecurrentfile. :n[!]Starteditingthenextfileintheargumentlist.Sincevicanbecalledwithmultiplefilenames,the":n"commandtellsittostopworkonthecurrentfileand switchtothenextfile.Ifthecurrentfilewasmodifies,ithastobewrittenout beforethe":n"willworkorelsethe"!"mustbesupplied,whichsaysdiscard thechangesImadetothecurrentfile. :n[!]file[filefile...] Replacethecurrentargumentlistwithanewlistoffilesandstarteditingthe firstfileinthisnewlist. :rfileReadinacopyof"file"onthelineafterthecursor. :r!cmdExecutethe"cmd"andtakeitsoutputandputitintothefileafterthecurrent line. :!cmdExecuteanyUNIXshellcommand. :ta[!]tagVilooksinthefilenamedtagsinthecurrentdirectory.Tagsisafileoflines intheformat: tagfilenamevi-search-command -10-Ifvifindsthetagyouspecifiedinthe:tacommand,itstopseditingthecurrent fileifnecessaryandifthecurrentfileisuptodateonthediskandswitchesto thefilespecifiedandusesthesearchpatternspecifiedtofindthe"tagged"item ofinterest.Thisisparticularlyusefulwheneditingmulti-fileCprogramssuch astheoperatingsystem.Thereisaprogramcalledctagswhichwillgenerate anappropriatetagsfileforCandf77programssothatbysaying:tafunction<nl>youwillbeswitchedtothatfunction.Itcouldalsobeusefulwhen editingmulti-filedocuments,thoughthetagsfilewouldhavetobegenerated manually. 6.SpecialArrangementsforStartup Vitakesthevalueof$TERMandlooksupthecharacteristicsofthatterminalinthefile /etc/termcap.Ifyoudon’tknowvi’snamefortheterminalyouareworkingon,lookin /etc/termcap. Whenvistarts,itattemptstoreadthevariableEXINITfromyourenvironment.*Ifthat exists,ittakesthevaluesinitasthedefaultvaluesforcertainofitsinternalconstants.Seethe sectionon"SetValues"forfurtherdetails.IfEXINITdoesn’texistyouwillgetallthenormal defaults. Shouldyouinadvertentlyhangupthephonewhileinsidevi,orshouldthecomputercrash, allmaynotbelost.Uponreturningtothesystem,type: vi−rfile Thiswillnormallyrecoverthefile.Ifthereismorethanonetemporaryfileforaspecificfile name,virecoversthenewestone.Youcangetanolderversionbyrecoveringthefilemorethan once.Thecommand"vi-r"withoutafilenamegivesyouthelistoffilesthatweresavedinthe lastsystemcrash(butnotthefilejustsavedwhenthephonewashungup). 7.SetCommands Vihasanumberofinternalvariablesandswitcheswhichcanbesettoachievespecialaffects. Theseoptionscomeinthreeforms,thosethatareswitches,whichtogglefromofftoonandback, thosethatrequireanumericvalue,andthosethatrequireanalphanumericstringvalue.Thetoggleoptionsaresetbyacommandoftheform: :setoption<nl> andturnedoffwiththecommand: :setnooption<nl> Commandsrequiringavaluearesetwithacommandoftheform: :setoption=value<nl> Todisplaythevalueofaspecificoptiontype: :setoption?<nl> Todisplayonlythosethatyouhavechangedtype: :set<nl> andtodisplaythelongtableofallthesettableparametersandtheircurrentvaluestype: :setall<nl> Mostoftheoptionshavealongformandanabbreviation.Botharelistedinthefollowing tableaswellasthenormaldefaultvalue. *Onversion6systemsInsteadofEXINIT,putthestartupcommandsinthefile.exrcinyourhome directory.

-11-Toarrangetohavevaluesotherthanthedefaultusedeverytimeyouentervi,placethe appropriatesetcommandinEXINITinyourenvironment,e.g. EXINIT=’setaiawtersesh=/bin/csh’ exportEXINIT or setenvEXINIT’setaiawtersesh=/bin/csh’ forshandcsh,respectively.Theseareusuallyplacedinyour.profileor.login.Ifyouarerunningasystemwithoutenvironments(suchasversion6)youcanplacethesetcommandinthefile .exrcinyourhomedirectory. autoindentaiDefault:noaiType:toggle Wheninautoindentmode,vihelpsyouindentcodebystartingeachlineinthe samecolumnastheprecedingline.Tabbingtotherightwith<tab>or<ˆ T> willmovethisboundarytotheright,anditcanbemovedtotheleftwith <ˆ D>. autoprintapDefault:apType:toggle Causesthecurrentlinetobeprintedaftereachextextmodifyingcommand. Thisisnotofmuchinterestinthenormalvivisualmode. autowriteawDefault:noawtype:toggle Autowritecausesanautomaticwritetobedoneifthereareunsavedchanges beforecertaincommandswhichchangefilesorotherwiseinteractwiththeoutsideworld.Thesecommandsare:!,:tag,:next,:rewind,ˆ ˆ ,andˆ ]. beautifybfDefault:nobfType:toggle Causesallcontrolcharactersexcept<tab>,<nl>,and<ff>tobediscarded. directorydirDefault:dir=/tmpType:string Thisisthedirectoryinwhichviputsitstemporaryfile. errorbellsebDefault:noebType:toggle Errormessagesareprecededbya<bell>. hardtabshtDefault:hardtabs=8Type:numeric Thisoptioncontainsthevalueofhardwaretabsinyourterminal,orofsoftware tabsexpandedbytheUnixsystem. ignorecaseicDefault:noicType:toggle Alluppercasecharactersaremappedtolowercaseinregularexpressionmatching. lispDefault:nolispType:toggle Autoindentforlispcode.Thecommands()[[and]]aremodifiedappropriatelytoaffects-expressionsandfunctions. listDefault:nolistType:toggle Allprintedlineshavethe<tab>and<nl>charactersdisplayedvisually. magicDefault:magicType:toggle Enablethemetacharactersformatching.Theseinclude.*<>[string] [ˆ string]and[<chr>-<chr>]. numbernuDefault:nonuType:toggle Eachlineisdisplayedwithitslinenumber. openDefault:openType:toggle Whenset,preventsenteringopenorvisualmodesfromexoredit.Notofinterestfromvi. optimizeoptDefault:optType:toggle Basicallyofuseonlywhenusingtheexcapabilities.Thisoptionprevents -12-automatic<cr>sfromtakingplace,andspeedsupoutputofindentedlines,at theexpenseoflosingtypeaheadonsomeversionsofUNIX. paragraphsparaDefault:para=IPLPPPQPPbpType:string Eachpairofcharactersinthestringindicatenroffmacroswhicharetobe treatedasthebeginningofaparagraphforthe{and}commands.Thedefault stringisforthe-msand-mmmacros.Toindicateoneletternroffmacros, suchas.Por.H,quoteaspaceinforthesecondcharacterposition.Forexample: :setparagraphs=P\bp<nl> wouldcausevitoconsider.Pand.bpasparagraphdelimiters. promptDefault:promptType:toggle Inexcommandmodethepromptcharacter:willbeprintedwhenexiswaiting foracommand.Thisisnotofinterestfromvi. redrawDefault:noredrawType:toggle Ondumbterminals,forcethescreentoalwaysbeuptodate,bysendinggreat amountsofoutput.Usefulonlyathighspeeds. reportDefault:report=5Type:numeric Thissetsthethresholdforthenumberoflinesmodified.Whenmorethanthis numberoflinesaremodified,removed,oryanked,viwillreportthenumberof lineschangedatthebottomofthescreen. scrollDefault:scroll={1/2window}Type:numeric Thisisthenumberoflinesthatthescreenscrollsupordownwhenusingthe <ˆ U>and<ˆ D>commands. sectionsDefault:sections=SHNHHHUType:string Eachtwocharacterpairofthisstringspecifynroffmacronameswhichareto betreatedasthebeginningofasectionbythe]]and[[commands.Thedefault stringisforthe-msand-mmmacros.Toenteroneletternroffmacros,usea quotedspaceasthesecondcharacter.Seeparagraphsforafullerexplanation. shellshDefault:sh=fromenvironmentSHELLor/bin/shType:string Thisisthenameoftheshtobeusedfor"escaped"commands. shiftwidthswDefault:sw=8Type:numeric Thisisthenumberofspacesthata<ˆ T>or<ˆ D>willmoveoverforindenting,andtheamount<and>shiftby. showmatchsmDefault:nosmType:toggle Whena)or}istyped,showthematching(or{bymovingthecursortoitfor onesecondifitisonthecurrentscreen. slowopenslowDefault:terminaldependentType:toggle Onterminalsthatareslowandunintelligent,thisoptionpreventstheupdating ofthescreensomeofthetimetoimprovespeed. tabstoptsDefault:ts=8Type:numeric <tab>sareexpandedtoboundariesthataremultiplesofthisvalue. taglengthtlDefault:tl=0Type:numeric Ifnonzero,tagnamesareonlysignificanttothismanycharacters. termDefault:(fromenvironmentTERM,elsedumb)Type:string Thisistheterminalandcontrolsthevisualdisplays.Itcannotbechanged whenin"visual"mode,youhavetoQtocommandmode,typeasettermcommand,anddo‘‘vi.’’togetbackintovisual.Orexitvi,fix$TERM,andreenter. Thedefinitionsthatdriveaparticularterminaltypearefoundinthefile /etc/termcap.

-13-terseDefault:terseType:toggle Whenset,theerrordiagnosticsareshort. warnDefault:warnType:toggle Theuseriswarnedifshe/hetriestoescapetotheshellwithoutwritingoutthe currentchanges. windowDefault:window={8at600baudorless,16at1200baud,andscreensize−1 at2400baudormore}Type:numeric Thisisthenumberoflinesinthewindowwhenevervimustredrawanentire screen.Itisusefultomakethissizesmallerifyouareonaslowline. w300,w1200,w9600 Thesesetwindow,butonlywithinthecorrespondingspeedranges.Theyare usefulinanEXINITtofinetunewindowsizes.Forexample, setw300=4w1200=12 causesa4lineswindowatspeedupto600baud,a12linewindowat1200 baud,andafullscreen(thedefault)atover1200baud. wrapscanwsDefault:wsType:toggle Searcheswillwraparoundtheendofthefilewhenisoptionisset.Whenitis off,thesearchwillterminatewhenitreachestheendorthebeginningofthe file. wrapmarginwmDefault:wm=0Type:numeric Viwillautomaticallyinserta<nl>whenitfindsanaturalbreakpoint(usually a<sp>betweenwords)thatoccurswithin"wm"spacesoftherightmargin. Thereforewith"wm=0"theoptionisoff.Settingitto10wouldmeanthatany timeyouarewithin10spacesoftherightmarginviwouldbelookingfora <sp>or<tab>whichitcouldreplacewitha<nl>.Thisisconvenientfor peoplewhoforgettolookatthescreenwhiletheytype.(Inversion3,wrapmarginbehavesmorelikenroff,inthattheboundaryspecifiedbythedistance fromtherightedgeofthescreenistakenastherightmostedgeofthearea whereabreakisallowed,insteadoftheleftmostedge.) writeanywaDefault:nowaType:toggle Vinormallymakesanumberofchecksbeforeitwritesoutafile.Thisprevents theuserfrominadvertentlydestroyingafile.Whenthe"writeany"optionis enabled,vinolongermakesthesechecks.