爱问 爱问共享资料 爱问分类
首页 > > > vi.and.Vim.Editors.Pocket.Reference.2nd.Edition…

vi.and.Vim.Editors.Pocket.Reference.2nd.Edition.pdf

vi.and.Vim.Editors.Pocket.Refer…

上传者: yjice
638次下载 0人收藏 暂无简介 简介 2011-06-07 举报

简介:vi.and.Vim.Editors.Pocket.Reference.2nd.Edition

viandVimEditorsPocketReferenceSECONDEDITIONviandVimEditorsPocketReferenceArnoldRobbinsBeijing•Cambridge•Farnham•Köln•Sebastopol•TokyoviandVimEditorsPocketReference,SecondEditionbyArnoldRobbinsCopyright2011ArnoldRobbins.Allrightsreserved.PrintedinCanada.PublishedbyO’ReillyMedia,Inc.,1005GravensteinHighwayNorth,Sebastopol,CA95472.O’Reillybooksmaybepurchasedforeducational,business,orsalespromo-tionaluse.Onlineeditionsarealsoavailableformosttitles(http://my.safaribooksonline.com).Formoreinformation,contactourcorporate/institutionalsalesdepartment:(800)998-9938orcorporate@oreilly.com.Editor:AndyOramCopyeditor:AmyThomsonProductionEditor:AdamZarembaProofreader:SadaPreischIndexer:JohnBickelhauptCoverDesigner:KarenMontgomeryInteriorDesigner:DavidFutatoIllustrator:RobertRomanoPrintingHistory:January1999:FirstEdition.January2011:SecondEdition.NutshellHandbook,theNutshellHandbooklogo,andtheO’ReillylogoareregisteredtrademarksofO’ReillyMedia,Inc.viandVimEditorsPocketReference,theimageofatarsier,andrelatedtradedressaretrademarksofO’ReillyMedia,Inc.Manyofthedesignationsusedbymanufacturersandsellerstodistinguishtheirproductsareclaimedastrademarks.Wherethosedesignationsappearinthisbook,andO’ReillyMedia,Inc.,wasawareofatrademarkclaim,thedesignationshavebeenprintedincapsorinitialcaps.Whileeveryprecautionhasbeentakeninthepreparationofthisbook,thepublisherandauthorassumenoresponsibilityforerrorsoromissions,orfordamagesresultingfromtheuseoftheinformationcontainedherein.ISBN:978-1-449-39217-8[TM]1294430582ContentsviandVimEditorsPocketReference1Introduction1Conventions1Acknowledgments2Command-LineOptions2viCommands3InputModeShortcuts9SubstitutionandRegularExpressions11exCommands16Initialization21Recovery21visetOptions21NothingliketheOriginal23EnhancedTagsandTagStacks23Vim—viImproved25nvi—Newvi59elvis63vile—vilikeEmacs71InternetResourcesforvi80ProgramSourceandContactInformation81Index83vviandVimEditorsPocketReferenceIntroductionThispocketreferenceisacompaniontoLearningtheviandVimEditors,byArnoldRobbinsetal.Itdescribesthevicom-mand-lineoptions,command-modecommands,excom-mandsandoptions,regularexpressionsandtheuseofthesubstitute(s)command,andotherpertinentinformationforusingvi.Whileretainingcoverageoftheviclones,nvi,elvis,andvile,thiseditionoffersexpandedcoverageoftheVimeditor,whichhasbecomethedefactostandardversionofviintheGNU/Linuxworld.TheSolarisversionofviservedasthe“reference”versionoftheoriginalviforthispocketreference.ConventionsThefollowingfontconventionsareusedinthisbook:CourierUsedforfilenames,commandnames,options,andevery-thingtobetypedliterally.1CourierItalicUsedforreplaceabletextwithincommands.ItalicUsedforreplaceabletextwithinregulartext,InternetURLs,foremphasis,andfornewtermswhenfirstdefined.[...]Identifiesoptionaltext;thebracketsarenottyped.CTRL-GIndicatesakeystroke.AcknowledgmentsThankstoRobertP.J.DayandElbertHannah,whoreviewedthisedition.TheproductionteamatO’ReillyMediadidagreatjobhelpingmemakethebooklookthewayIwanted.Aspecialthankstomyeditor,AndyOram,forkeepingtheprojectmov-ingwithcontinualgentleencouragement.Command-LineOptionsCommandActionvifileInvokevionfilevifile1file2InvokevionfilessequentiallyviewfileInvokevionfileinread-onlymodevi-RfileInvokevionfileinread-onlymodevi-rfileRecoverfileandrecenteditsafteracrashvi-ttagLookuptagandstarteditingatitsdefinitionvi-wnSetthewindowsizeton;usefuloveraslowconnectionvi+fileOpenfileatlastlinevi+nfileOpenfiledirectlyatlinenumbern2|viandVimEditorsPocketReferenceCommandActionvi-ccommandfileOpenfile,executecommand,whichisusuallyasearchcommandorlinenum-ber(POSIX)vi+/patternfileOpenfiledirectlyatpatternexfileInvokeexonfileex-file<scriptInvokeexonfile,takingcommandsfromscript;suppressinformativemes-sagesandpromptsex-sfile<scriptInvokeexonfile,takingcommandsfromscript;suppressinformativemes-sagesandprompts(POSIX)viCommandsvicommandsareusedin“screen”mode(thedefault),whereyouusethecommandstomovearoundthescreenandtoper-formoperationsonthetext.Mostvicommandsfollowageneralpattern:[command][number]textobjectortheequivalentform:[number][command]textobjectMovementCommandsvimovementcommandsdistinguishbetweentwokindsof“words.”Thelowercasecommandsdefineawordasacontig-uoussequenceofunderscores,letters,anddigits.Theupper-casecommandsdefineawordasacontiguoussequenceofnonwhitespacecharacters.viCommands|3CommandMeaningCharacterh,j,k,lLeft,down,up,right(,,,)Textw,W,b,BForward,backwardbyworde,EEndofword),(Beginningofnext,previoussentence},{Beginningofnext,previousparagraph]],[[Beginningofnext,previoussectionLinesENTERFirstnonblankcharacterofnextline0,$First,lastpositionofcurrentline^Firstnonblankcharacterofcurrentline+,-Firstnonblankcharacterofnext,previouslinen|ColumnnofcurrentlineH,M,LTop,middle,lastlineofscreennHn(number)oflinesaftertoplinenLn(number)oflinesbeforelastlineScrollingCTRL-F,CTRL-BScrollforward,backwardonescreenCTRL-DCTRL-UScrolldown,uponehalf-screenCTRL-ECTRL-YShowonemorelineatbottom,topofwindowzENTERRepositionlinewithcursor:totopofscreenz.Repositionlinewithcursor:tomiddleofscreenz–Repositionlinewithcursor:tobottomofscreenCTRL-LRedrawscreen(withoutscrolling)4|viandVimEditorsPocketReferenceCommandMeaningSearches/patternSearchforwardforpattern?patternSearchbackwardforpatternn,NRepeatlastsearchinsame,oppositedirection/,?Repeatprevioussearchforward,backwardfxSearchforwardforcharacterxincurrentlineFxSearchbackwardforcharacterxincurrentlinetxSearchforwardtocharacterbeforexincur-rentlineTxSearchbackwardtocharacterafterxincurrentline;Repeatpreviouscurrent-linesearch,Repeatpreviouscurrent-linesearchinop-positedirectionLinenumberCTRL-GDisplaycurrentlinenumbernGMovetolinenumbernGMovetolastlineinfile:nMovetolineninfileMarkingpositionmxMarkcurrentpositionasx‘xMovecursortomarkx(graveaccent)‘‘Returntopreviousmarkorcontext(twograveaccents)’xMovetobeginningoflinecontainingmarkx(singlequote)’’Returntobeginningoflinecontainingpre-viousmark(twosinglequotes)viCommands|5EditingCommandsCommandActionInserti,aInserttextbefore,aftercursorI,AInserttextbeforebeginning,afterendoflineo,OOpennewlinefortextbelow,abovecursorChangecwChangewordccChangecurrentlinecmotionChangetextbetweenthecursorandthetar-getofmotionCChangetoendoflinerReplacesinglecharacterRTypeover(overwrite)characterssSubstitute:deletecharacterandinsertnewtextSSubstitute:deletecurrentlineandinsertnewtextDelete,movexDeletecharacterundercursorXDeletecharacterbeforecursordwDeletewordddDeletecurrentlinedmotionDeletetextbetweenthecursorandthetargetofmotionDDeletetoendoflinep,PPutdeletedtextafter,beforecursor"npPuttextfromdeletebuffernumbernaftercursor(forlastninedeletions)YankywYank(copy)word6|viandVimEditorsPocketReferenceCommandActionyyYankcurrentline"ayyYankcurrentlineintonamedbuffera(a–z);uppercasenamesappendtextymotionYanktextbetweenthecursorandthetargetofmotionp,PPutyankedtextafter,beforecursor"aPPuttextfrombufferabeforecursor(a–z)Othercommands.Repeatlasteditcommandu,UUndolastedit;restorecurrentlineJJointwolinesexeditcommands:dDeletelines:mMovelines:coor:tCopylines:.,$dDeletefromcurrentlinetoendoffile:30,60m0Movelines30through60totopoffile:.,/pattern/co$Copyfromcurrentlinethroughlinecontain-ingpatterntoendoffileExitCommandsCommandMeaning:wWrite(save)file:w!Write(save)file,overridingprotection:wqWrite(save)andquitfile:xWrite(save)andquitfileZZWrite(save)andquitfile:30,60wnewfileWritefromline30throughline60asnewfile:30,60w>>fileWritefromline30throughline60andappendtofileviCommands|7CommandMeaning:w%.newWritecurrentbuffernamedfileasfile.new:qQuitfile:q!Quitfile,overridingprotectionQQuitviandinvokeex:efile2Editfile2withoutleavingvi:nEditnextfile:e!Returntoversionofcurrentfileasoftimeoflastwrite(save):e#Editalternatefile:viInvokevieditorfromex:Invokeoneexcommandfromvieditor%Currentfilename(substitutesintoexcom-mandline)#Alternatefilename(substitutesintoexcom-mandline)SolarisviCommand-ModeTagCommandsCommandAction^]Lookupthelocationoftheidentifierunderthecursorinthetagsfileandmovetothatlocation;iftagstack-ingisenabled,thecurrentlocationisautomaticallypushedontothetagstack^TReturntothepreviouslocationinthetagstack,i.e.,popoffoneelementBufferNamesBuffernamesBufferuse1–9Thelastninedeletions,frommosttoleastrecenta–zNamedbufferstouseasneeded;uppercaselettersappendtotherespectivebuffers8|viandVimEditorsPocketReferenceBufferandMarkingCommandsCommandMeaning"bcommandDocommandwithbufferbmxMarkcurrentpositionwithx‘xMovecursortocharactermarkedbyx(graveaccent)‘‘Returntoexactpositionofpreviousmarkorcontext(twograveaccents)’xMovecursortofirstcharacteroflinemarkedbyx(singlequote)’’Returntobeginningofthelineofpreviousmarkorcontext(twosinglequotes)InputModeShortcutsviprovidestwowaystodecreasetheamountoftypingyouhavetodo:abbreviationsandmaps.WordAbbreviation:ababbrphraseDefineabbrasanabbreviationforphrase.:abListalldefinedabbreviations.:unababbrRemovedefinitionofabbr.CommandandInputModeMaps:mapxsequenceDefinecharacter(s)xasasequenceofeditingcommands.:unmapxDisablethesequencedefinedforx.:mapListthecharactersthatarecurrentlymapped.InputModeShortcuts|9:map!xsequenceDefinecharacter(s)xasasequenceofeditingcommandsortextthatwillberecognizedininsertmode.:unmap!xDisablethesequencedefinedfortheinsertmodemapx.:map!Listthecharactersthatarecurrentlymappedforinterpre-tationininsertmode.Forbothcommandandinsertmodemaps,themapnamexcantakeseveralforms:OnecharacterWhenyoutypethecharacter,viexecutestheassociatedsequenceofcommands.MultiplecharactersAllthecharactersmustbetypedwithinonesecond.Thevalueofnotimeoutchangesthebehavior.#nFunctionkeynotation:a#followedbyadigitnrepresentsthesequenceofcharacterssentbythekeyboard’sfunctionkeynumbern.ToentercharacterssuchasEscape(^[)orcarriagereturn(^M),firsttypeCTRL-V(^V).ExecutableBuffersNamedbuffersprovideyetanotherwaytocreate“macros”—complexcommandsequencesyoucanrepeatwithafewkey-strokes.Here’showit’sdone:1.Typeavicommandsequenceoranexcommandprecededbyacolon;returntocommandmode.2.Deletethetextintoanamedbuffer.3.Executethebufferwiththe@commandfollowedbythebufferletter.Theexcommand:@buf-nameworkssimilarly.10|viandVimEditorsPocketReferenceSomeversionsofvitreat*identicallyto@whenusedfromtheexcommandline.Inaddition,ifthebuffercharactersuppliedafterthe@or*commandsis*,thecommandistakenfromthedefault(unnamed)buffer.AutomaticIndentationEnableautomaticindentationwiththefollowingcommand::setautoindentFourspecialinputsequencesaffectautomaticindentation:^TAddonelevelofindentation;typedininsertmode^DRemoveonelevelofindentation;typedininsertmode^^DShiftthecursorbacktothebeginningoftheline,butonlyforthecurrentline*0^DShiftthecursorbacktothebeginningofthelineandresetthecurrentauto-indentleveltozero†Twocommandscanbeusedforshiftingsourcecode:<<Shiftalinelefteightspaces>>ShiftalinerighteightspacesThedefaultshiftisthevalueofshiftwidth,usuallyeightspaces.SubstitutionandRegularExpressionsRegularexpressions,andtheirusewiththesubstitutecom-mand,arewhatgivevimostofitssignificanteditingpower.*^^Dand0^Darenotinelvis.†Thenvi1.79documentationhasthesetwocommandsswitched,buttheprogramactuallybehavesasdescribedhere.SubstitutionandRegularExpressions|11TheSubstituteCommandThegeneralformofthesubstitutecommandis::[addr1[,addr2]]s/old/new/[flags]Omittingthesearchpattern(:s//replacement/)usesthelastsearchorsubstitutionregularexpression.Anemptyreplacementpart(:s/pattern//)“replaces”thematchedtextwithnothing,effectivelydeletingitfromtheline.SubstitutionflagsFlagMeaningcConfirmeachsubstitutiongChangealloccurrencesofoldtonewoneachline(globally)pPrintthelineafterthechangeismadeIt’softenusefultocombinethesubstitutecommandwiththeexglobalcommand,:g::g/ObjectOriented/s//Buzzwordcompliant/gviRegularExpressions.(period)Matchesanysinglecharacterexceptanewline.Rememberthatspacesaretreatedascharacters.*Matcheszeroormore(asmanyasthereare)ofthesinglecharacterthatimmediatelyprecedesit.The*canfollowametacharacter,suchas.,orarangeinbrackets.^Whenusedatthestartofaregularexpression,^requiresthatthefollowingregularexpressionbefoundatthebe-ginningoftheline.Whennotatthebeginningofaregularexpression,^standsforitself.$Whenusedattheendofaregularexpression,$requiresthattheprecedingregularexpressionbefoundattheend12|viandVimEditorsPocketReferenceoftheline.Whennotattheendofaregularexpression,$standsforitself.\Treatsthefollowingspecialcharacterasanordinarychar-acter.Use\\togetaliteralbackslash.~Matcheswhateverregularexpressionwasusedinthelastsearch.[]Matchesanyoneofthecharactersenclosedbetweenthebrackets.Arangeofconsecutivecharacterscanbespeci-fiedbyseparatingthefirstandlastcharactersintherangewithahyphen.Youcanincludemorethanonerangeinsidebracketsandspecifyamixofrangesandseparatecharacters.Mostmetacharacterslosetheirspecialmeaninginsidebrackets,soyoudon’tneedtoescapethemifyouwanttousethemasordinarycharacters.Withinbrackets,thethreemetacharactersyoustillneedtoescapeare\-].Thehyphen(-)acquiresmeaningasarangespecifier;touseanactualhyphen,youcanalsoplaceitasthefirstchar-acterinsidethebrackets.Acaret(^)hasspecialmeaningonlywhenit’sthefirstcharacterinsidethebrackets,butinthiscase,themeaningdiffersfromthatofthenormal^metacharacter.Asthefirstcharacterwithinbrackets,a^reversestheirsense:thebracketsmatchanyonecharacternotinthelist.Forexample,[^a-z]matchesanycharacterthat’snotalow-ercaseletter.CAUTIONOnmodernsystems,thelocalecanaffecttheinter-pretationofrangeswithinbrackets,causingvitomatchlettersinasurprisingfashion.ItisbettertousePOSIXbracketexpressions(see“POSIXBrack-etExpressions”onpage14)tomatchspecifickindsofcharacters,suchasalllowercaseoralluppercasecharacters.SubstitutionandRegularExpressions|13\(...\)Savesthepatternenclosedbetween\(and\)intoaspecialholdingspaceor“holdbuffer.”Youcansaveuptoninepatternsinthiswayonasingleline.Youcanalsousethe\nnotationwithinasearchorsub-stitutestring::s/\(abcd\)\1/alphabet-soup/changesabcdabcdintoalphabet-soup.‡\<\>Matchescharactersatthebeginning(\<)orend(\>)ofaword.Theendorbeginningofawordisdeterminedeitherbyapunctuationmarkorbyaspace.Unlike\(...\),thesedon’thavetobeusedinmatchedpairs.POSIXBracketExpressionsPOSIXbracketexpressionsmaycontainthefollowing:CharacterclassesAPOSIXcharacterclassconsistsofkeywordsbracketedby[:and:].Thekeywordsdescribedifferentclassesofcharacters,suchasalphabeticcharacters,controlcharac-ters,andsoon(seethefollowingtable).CollatingsymbolsAcollatingsymbolisamulticharactersequencethatshouldbetreatedasaunit.Itconsistsofthecharactersbracketedby[.and.].EquivalenceclassesAnequivalenceclasslistsasetofcharactersthatshouldbeconsideredequivalent,suchaseandè.Itconsistsofanamedelementfromthelocale,bracketedby[=and=].Allthreeconstructsmustappearinsidethesquarebracketsofabracketexpression.‡Thisworkswithvi,nvi,andVim,butnotwithelvisorvile.14|viandVimEditorsPocketReferencePOSIXcharacterclassesClassMatchingcharacters[:alnum:]Alphanumericcharacters[:alpha:]Alphabeticcharacters[:blank:]Spaceandtabcharacters[:cntrl:]Controlcharacters[:digit:]Numericcharacters[:graph:]Printableandvisible(nonspace)characters[:lower:]Lowercasecharacters[:print:]Printablecharacters(includeswhitespace)[:punct:]Punctuationcharacters[:space:]Whitespacecharacters[:upper:]Uppercasecharacters[:xdigit:]HexadecimaldigitsMetacharactersUsedinReplacementStrings\nIsreplacedwiththetextmatchedbythenthpatternpre-viouslysavedby\(and\),wherenisanumberfromonetonine,andpreviouslysavedpatterns(keptinholdbuf-fers)arecountedfromtheleftontheline.\Treatsthefollowingspecialcharacterasanordinarychar-acter.Tospecifyarealbackslash,typetwoinarow(\\).&Isreplacedwiththeentiretextmatchedbythesearchpat-ternwhenusedinareplacementstring.Thisisusefulwhenyouwanttoavoidretypingtext.~Thestringfoundisreplacedwiththereplacementtextspecifiedinthelastsubstitutecommand.Thisisusefulforrepeatinganedit.\uor\lChangesthenextcharacterinthereplacementstringtouppercaseorlowercase,respectively.SubstitutionandRegularExpressions|15\Uor\Land\eor\E\Uand\Laresimilarto\uor\l,butallfollowingcharac-tersareconvertedtouppercaseorlowercaseuntiltheendofthereplacementstringoruntil\eor\Eisreached.Ifthereisno\eor\E,allcharactersofthereplacementtextareaffectedbythe\Uor\L.MoreSubstitutionTricks•Youcaninstructvitoignorecasebytyping:setic.•Asimple:sisthesameas:s//~/.•:&isthesameas:s.Youcanfollowthe&withgtomakethesubstitutiongloballyontheline,andevenuseitwithalinerange.•Youcanusethe&keyasavicommandtoperformthe:&command,i.e.,torepeatthelastsubstitution.•The:~commandissimilartothe:&command,butwithasubtledifference.Thesearchpatternusedisthelastre

vi.and.Vim.Editors.Pocket.Reference.2nd.Edition.pdf

vi.and.Vim.Editors.Pocket.Refer…

上传者: yjice
638次下载 0人收藏 暂无简介 简介 2011-06-07 举报

简介:vi.and.Vim.Editors.Pocket.Reference.2nd.Edition

viandVimEditorsPocketReferenceSECONDEDITIONviandVimEditorsPocketReferenceArnoldRobbinsBeijing•Cambridge•Farnham•Köln•Sebastopol•TokyoviandVimEditorsPocketReference,SecondEditionbyArnoldRobbinsCopyright2011ArnoldRobbins.Allrightsreserved.PrintedinCanada.PublishedbyO’ReillyMedia,Inc.,1005GravensteinHighwayNorth,Sebastopol,CA95472.O’Reillybooksmaybepurchasedforeducational,business,orsalespromo-tionaluse.Onlineeditionsarealsoavailableformosttitles(http://my.safaribooksonline.com).Formoreinformation,contactourcorporate/institutionalsalesdepartment:(800)998-9938orcorporate@oreilly.com.Editor:AndyOramCopyeditor:AmyThomsonProductionEditor:AdamZarembaProofreader:SadaPreischIndexer:JohnBickelhauptCoverDesigner:KarenMontgomeryInteriorDesigner:DavidFutatoIllustrator:RobertRomanoPrintingHistory:January1999:FirstEdition.January2011:SecondEdition.NutshellHandbook,theNutshellHandbooklogo,andtheO’ReillylogoareregisteredtrademarksofO’ReillyMedia,Inc.viandVimEditorsPocketReference,theimageofatarsier,andrelatedtradedressaretrademarksofO’ReillyMedia,Inc.Manyofthedesignationsusedbymanufacturersandsellerstodistinguishtheirproductsareclaimedastrademarks.Wherethosedesignationsappearinthisbook,andO’ReillyMedia,Inc.,wasawareofatrademarkclaim,thedesignationshavebeenprintedincapsorinitialcaps.Whileeveryprecautionhasbeentakeninthepreparationofthisbook,thepublisherandauthorassumenoresponsibilityforerrorsoromissions,orfordamagesresultingfromtheuseoftheinformationcontainedherein.ISBN:978-1-449-39217-8[TM]1294430582ContentsviandVimEditorsPocketReference1Introduction1Conventions1Acknowledgments2Command-LineOptions2viCommands3InputModeShortcuts9SubstitutionandRegularExpressions11exCommands16Initialization21Recovery21visetOptions21NothingliketheOriginal23EnhancedTagsandTagStacks23Vim—viImproved25nvi—Newvi59elvis63vile—vilikeEmacs71InternetResourcesforvi80ProgramSourceandContactInformation81Index83vviandVimEditorsPocketReferenceIntroductionThispocketreferenceisacompaniontoLearningtheviandVimEditors,byArnoldRobbinsetal.Itdescribesthevicom-mand-lineoptions,command-modecommands,excom-mandsandoptions,regularexpressionsandtheuseofthesubstitute(s)command,andotherpertinentinformationforusingvi.Whileretainingcoverageoftheviclones,nvi,elvis,andvile,thiseditionoffersexpandedcoverageoftheVimeditor,whichhasbecomethedefactostandardversionofviintheGNU/Linuxworld.TheSolarisversionofviservedasthe“reference”versionoftheoriginalviforthispocketreference.ConventionsThefollowingfontconventionsareusedinthisbook:CourierUsedforfilenames,commandnames,options,andevery-thingtobetypedliterally.1CourierItalicUsedforreplaceabletextwithincommands.ItalicUsedforreplaceabletextwithinregulartext,InternetURLs,foremphasis,andfornewtermswhenfirstdefined.[...]Identifiesoptionaltext;thebracketsarenottyped.CTRL-GIndicatesakeystroke.AcknowledgmentsThankstoRobertP.J.DayandElbertHannah,whoreviewedthisedition.TheproductionteamatO’ReillyMediadidagreatjobhelpingmemakethebooklookthewayIwanted.Aspecialthankstomyeditor,AndyOram,forkeepingtheprojectmov-ingwithcontinualgentleencouragement.Command-LineOptionsCommandActionvifileInvokevionfilevifile1file2InvokevionfilessequentiallyviewfileInvokevionfileinread-onlymodevi-RfileInvokevionfileinread-onlymodevi-rfileRecoverfileandrecenteditsafteracrashvi-ttagLookuptagandstarteditingatitsdefinitionvi-wnSetthewindowsizeton;usefuloveraslowconnectionvi+fileOpenfileatlastlinevi+nfileOpenfiledirectlyatlinenumbern2|viandVimEditorsPocketReferenceCommandActionvi-ccommandfileOpenfile,executecommand,whichisusuallyasearchcommandorlinenum-ber(POSIX)vi+/patternfileOpenfiledirectlyatpatternexfileInvokeexonfileex-file<scriptInvokeexonfile,takingcommandsfromscript;suppressinformativemes-sagesandpromptsex-sfile<scriptInvokeexonfile,takingcommandsfromscript;suppressinformativemes-sagesandprompts(POSIX)viCommandsvicommandsareusedin“screen”mode(thedefault),whereyouusethecommandstomovearoundthescreenandtoper-formoperationsonthetext.Mostvicommandsfollowageneralpattern:[command][number]textobjectortheequivalentform:[number][command]textobjectMovementCommandsvimovementcommandsdistinguishbetweentwokindsof“words.”Thelowercasecommandsdefineawordasacontig-uoussequenceofunderscores,letters,anddigits.Theupper-casecommandsdefineawordasacontiguoussequenceofnonwhitespacecharacters.viCommands|3CommandMeaningCharacterh,j,k,lLeft,down,up,right(,,,)Textw,W,b,BForward,backwardbyworde,EEndofword),(Beginningofnext,previoussentence},{Beginningofnext,previousparagraph]],[[Beginningofnext,previoussectionLinesENTERFirstnonblankcharacterofnextline0,$First,lastpositionofcurrentline^Firstnonblankcharacterofcurrentline+,-Firstnonblankcharacterofnext,previouslinen|ColumnnofcurrentlineH,M,LTop,middle,lastlineofscreennHn(number)oflinesaftertoplinenLn(number)oflinesbeforelastlineScrollingCTRL-F,CTRL-BScrollforward,backwardonescreenCTRL-DCTRL-UScrolldown,uponehalf-screenCTRL-ECTRL-YShowonemorelineatbottom,topofwindowzENTERRepositionlinewithcursor:totopofscreenz.Repositionlinewithcursor:tomiddleofscreenz–Repositionlinewithcursor:tobottomofscreenCTRL-LRedrawscreen(withoutscrolling)4|viandVimEditorsPocketReferenceCommandMeaningSearches/patternSearchforwardforpattern?patternSearchbackwardforpatternn,NRepeatlastsearchinsame,oppositedirection/,?Repeatprevioussearchforward,backwardfxSearchforwardforcharacterxincurrentlineFxSearchbackwardforcharacterxincurrentlinetxSearchforwardtocharacterbeforexincur-rentlineTxSearchbackwardtocharacterafterxincurrentline;Repeatpreviouscurrent-linesearch,Repeatpreviouscurrent-linesearchinop-positedirectionLinenumberCTRL-GDisplaycurrentlinenumbernGMovetolinenumbernGMovetolastlineinfile:nMovetolineninfileMarkingpositionmxMarkcurrentpositionasx‘xMovecursortomarkx(graveaccent)‘‘Returntopreviousmarkorcontext(twograveaccents)’xMovetobeginningoflinecontainingmarkx(singlequote)’’Returntobeginningoflinecontainingpre-viousmark(twosinglequotes)viCommands|5EditingCommandsCommandActionInserti,aInserttextbefore,aftercursorI,AInserttextbeforebeginning,afterendoflineo,OOpennewlinefortextbelow,abovecursorChangecwChangewordccChangecurrentlinecmotionChangetextbetweenthecursorandthetar-getofmotionCChangetoendoflinerReplacesinglecharacterRTypeover(overwrite)characterssSubstitute:deletecharacterandinsertnewtextSSubstitute:deletecurrentlineandinsertnewtextDelete,movexDeletecharacterundercursorXDeletecharacterbeforecursordwDeletewordddDeletecurrentlinedmotionDeletetextbetweenthecursorandthetargetofmotionDDeletetoendoflinep,PPutdeletedtextafter,beforecursor"npPuttextfromdeletebuffernumbernaftercursor(forlastninedeletions)YankywYank(copy)word6|viandVimEditorsPocketReferenceCommandActionyyYankcurrentline"ayyYankcurrentlineintonamedbuffera(a–z);uppercasenamesappendtextymotionYanktextbetweenthecursorandthetargetofmotionp,PPutyankedtextafter,beforecursor"aPPuttextfrombufferabeforecursor(a–z)Othercommands.Repeatlasteditcommandu,UUndolastedit;restorecurrentlineJJointwolinesexeditcommands:dDeletelines:mMovelines:coor:tCopylines:.,$dDeletefromcurrentlinetoendoffile:30,60m0Movelines30through60totopoffile:.,/pattern/co$Copyfromcurrentlinethroughlinecontain-ingpatterntoendoffileExitCommandsCommandMeaning:wWrite(save)file:w!Write(save)file,overridingprotection:wqWrite(save)andquitfile:xWrite(save)andquitfileZZWrite(save)andquitfile:30,60wnewfileWritefromline30throughline60asnewfile:30,60w>>fileWritefromline30throughline60andappendtofileviCommands|7CommandMeaning:w%.newWritecurrentbuffernamedfileasfile.new:qQuitfile:q!Quitfile,overridingprotectionQQuitviandinvokeex:efile2Editfile2withoutleavingvi:nEditnextfile:e!Returntoversionofcurrentfileasoftimeoflastwrite(save):e#Editalternatefile:viInvokevieditorfromex:Invokeoneexcommandfromvieditor%Currentfilename(substitutesintoexcom-mandline)#Alternatefilename(substitutesintoexcom-mandline)SolarisviCommand-ModeTagCommandsCommandAction^]Lookupthelocationoftheidentifierunderthecursorinthetagsfileandmovetothatlocation;iftagstack-ingisenabled,thecurrentlocationisautomaticallypushedontothetagstack^TReturntothepreviouslocationinthetagstack,i.e.,popoffoneelementBufferNamesBuffernamesBufferuse1–9Thelastninedeletions,frommosttoleastrecenta–zNamedbufferstouseasneeded;uppercaselettersappendtotherespectivebuffers8|viandVimEditorsPocketReferenceBufferandMarkingCommandsCommandMeaning"bcommandDocommandwithbufferbmxMarkcurrentpositionwithx‘xMovecursortocharactermarkedbyx(graveaccent)‘‘Returntoexactpositionofpreviousmarkorcontext(twograveaccents)’xMovecursortofirstcharacteroflinemarkedbyx(singlequote)’’Returntobeginningofthelineofpreviousmarkorcontext(twosinglequotes)InputModeShortcutsviprovidestwowaystodecreasetheamountoftypingyouhavetodo:abbreviationsandmaps.WordAbbreviation:ababbrphraseDefineabbrasanabbreviationforphrase.:abListalldefinedabbreviations.:unababbrRemovedefinitionofabbr.CommandandInputModeMaps:mapxsequenceDefinecharacter(s)xasasequenceofeditingcommands.:unmapxDisablethesequencedefinedforx.:mapListthecharactersthatarecurrentlymapped.InputModeShortcuts|9:map!xsequenceDefinecharacter(s)xasasequenceofeditingcommandsortextthatwillberecognizedininsertmode.:unmap!xDisablethesequencedefinedfortheinsertmodemapx.:map!Listthecharactersthatarecurrentlymappedforinterpre-tationininsertmode.Forbothcommandandinsertmodemaps,themapnamexcantakeseveralforms:OnecharacterWhenyoutypethecharacter,viexecutestheassociatedsequenceofcommands.MultiplecharactersAllthecharactersmustbetypedwithinonesecond.Thevalueofnotimeoutchangesthebehavior.#nFunctionkeynotation:a#followedbyadigitnrepresentsthesequenceofcharacterssentbythekeyboard’sfunctionkeynumbern.ToentercharacterssuchasEscape(^[)orcarriagereturn(^M),firsttypeCTRL-V(^V).ExecutableBuffersNamedbuffersprovideyetanotherwaytocreate“macros”—complexcommandsequencesyoucanrepeatwithafewkey-strokes.Here’showit’sdone:1.Typeavicommandsequenceoranexcommandprecededbyacolon;returntocommandmode.2.Deletethetextintoanamedbuffer.3.Executethebufferwiththe@commandfollowedbythebufferletter.Theexcommand:@buf-nameworkssimilarly.10|viandVimEditorsPocketReferenceSomeversionsofvitreat*identicallyto@whenusedfromtheexcommandline.Inaddition,ifthebuffercharactersuppliedafterthe@or*commandsis*,thecommandistakenfromthedefault(unnamed)buffer.AutomaticIndentationEnableautomaticindentationwiththefollowingcommand::setautoindentFourspecialinputsequencesaffectautomaticindentation:^TAddonelevelofindentation;typedininsertmode^DRemoveonelevelofindentation;typedininsertmode^^DShiftthecursorbacktothebeginningoftheline,butonlyforthecurrentline*0^DShiftthecursorbacktothebeginningofthelineandresetthecurrentauto-indentleveltozero†Twocommandscanbeusedforshiftingsourcecode:<<Shiftalinelefteightspaces>>ShiftalinerighteightspacesThedefaultshiftisthevalueofshiftwidth,usuallyeightspaces.SubstitutionandRegularExpressionsRegularexpressions,andtheirusewiththesubstitutecom-mand,arewhatgivevimostofitssignificanteditingpower.*^^Dand0^Darenotinelvis.†Thenvi1.79documentationhasthesetwocommandsswitched,buttheprogramactuallybehavesasdescribedhere.SubstitutionandRegularExpressions|11TheSubstituteCommandThegeneralformofthesubstitutecommandis::[addr1[,addr2]]s/old/new/[flags]Omittingthesearchpattern(:s//replacement/)usesthelastsearchorsubstitutionregularexpression.Anemptyreplacementpart(:s/pattern//)“replaces”thematchedtextwithnothing,effectivelydeletingitfromtheline.SubstitutionflagsFlagMeaningcConfirmeachsubstitutiongChangealloccurrencesofoldtonewoneachline(globally)pPrintthelineafterthechangeismadeIt’softenusefultocombinethesubstitutecommandwiththeexglobalcommand,:g::g/ObjectOriented/s//Buzzwordcompliant/gviRegularExpressions.(period)Matchesanysinglecharacterexceptanewline.Rememberthatspacesaretreatedascharacters.*Matcheszeroormore(asmanyasthereare)ofthesinglecharacterthatimmediatelyprecedesit.The*canfollowametacharacter,suchas.,orarangeinbrackets.^Whenusedatthestartofaregularexpression,^requiresthatthefollowingregularexpressionbefoundatthebe-ginningoftheline.Whennotatthebeginningofaregularexpression,^standsforitself.$Whenusedattheendofaregularexpression,$requiresthattheprecedingregularexpressionbefoundattheend12|viandVimEditorsPocketReferenceoftheline.Whennotattheendofaregularexpression,$standsforitself.\Treatsthefollowingspecialcharacterasanordinarychar-acter.Use\\togetaliteralbackslash.~Matcheswhateverregularexpressionwasusedinthelastsearch.[]Matchesanyoneofthecharactersenclosedbetweenthebrackets.Arangeofconsecutivecharacterscanbespeci-fiedbyseparatingthefirstandlastcharactersintherangewithahyphen.Youcanincludemorethanonerangeinsidebracketsandspecifyamixofrangesandseparatecharacters.Mostmetacharacterslosetheirspecialmeaninginsidebrackets,soyoudon’tneedtoescapethemifyouwanttousethemasordinarycharacters.Withinbrackets,thethreemetacharactersyoustillneedtoescapeare\-].Thehyphen(-)acquiresmeaningasarangespecifier;touseanactualhyphen,youcanalsoplaceitasthefirstchar-acterinsidethebrackets.Acaret(^)hasspecialmeaningonlywhenit’sthefirstcharacterinsidethebrackets,butinthiscase,themeaningdiffersfromthatofthenormal^metacharacter.Asthefirstcharacterwithinbrackets,a^reversestheirsense:thebracketsmatchanyonecharacternotinthelist.Forexample,[^a-z]matchesanycharacterthat’snotalow-ercaseletter.CAUTIONOnmodernsystems,thelocalecanaffecttheinter-pretationofrangeswithinbrackets,causingvitomatchlettersinasurprisingfashion.ItisbettertousePOSIXbracketexpressions(see“POSIXBrack-etExpressions”onpage14)tomatchspecifickindsofcharacters,suchasalllowercaseoralluppercasecharacters.SubstitutionandRegularExpressions|13\(...\)Savesthepatternenclosedbetween\(and\)intoaspecialholdingspaceor“holdbuffer.”Youcansaveuptoninepatternsinthiswayonasingleline.Youcanalsousethe\nnotationwithinasearchorsub-stitutestring::s/\(abcd\)\1/alphabet-soup/changesabcdabcdintoalphabet-soup.‡\<\>Matchescharactersatthebeginning(\<)orend(\>)ofaword.Theendorbeginningofawordisdeterminedeitherbyapunctuationmarkorbyaspace.Unlike\(...\),thesedon’thavetobeusedinmatchedpairs.POSIXBracketExpressionsPOSIXbracketexpressionsmaycontainthefollowing:CharacterclassesAPOSIXcharacterclassconsistsofkeywordsbracketedby[:and:].Thekeywordsdescribedifferentclassesofcharacters,suchasalphabeticcharacters,controlcharac-ters,andsoon(seethefollowingtable).CollatingsymbolsAcollatingsymbolisamulticharactersequencethatshouldbetreatedasaunit.Itconsistsofthecharactersbracketedby[.and.].EquivalenceclassesAnequivalenceclasslistsasetofcharactersthatshouldbeconsideredequivalent,suchaseandè.Itconsistsofanamedelementfromthelocale,bracketedby[=and=].Allthreeconstructsmustappearinsidethesquarebracketsofabracketexpression.‡Thisworkswithvi,nvi,andVim,butnotwithelvisorvile.14|viandVimEditorsPocketReferencePOSIXcharacterclassesClassMatchingcharacters[:alnum:]Alphanumericcharacters[:alpha:]Alphabeticcharacters[:blank:]Spaceandtabcharacters[:cntrl:]Controlcharacters[:digit:]Numericcharacters[:graph:]Printableandvisible(nonspace)characters[:lower:]Lowercasecharacters[:print:]Printablecharacters(includeswhitespace)[:punct:]Punctuationcharacters[:space:]Whitespacecharacters[:upper:]Uppercasecharacters[:xdigit:]HexadecimaldigitsMetacharactersUsedinReplacementStrings\nIsreplacedwiththetextmatchedbythenthpatternpre-viouslysavedby\(and\),wherenisanumberfromonetonine,andpreviouslysavedpatterns(keptinholdbuf-fers)arecountedfromtheleftontheline.\Treatsthefollowingspecialcharacterasanordinarychar-acter.Tospecifyarealbackslash,typetwoinarow(\\).&Isreplacedwiththeentiretextmatchedbythesearchpat-ternwhenusedinareplacementstring.Thisisusefulwhenyouwanttoavoidretypingtext.~Thestringfoundisreplacedwiththereplacementtextspecifiedinthelastsubstitutecommand.Thisisusefulforrepeatinganedit.\uor\lChangesthenextcharacterinthereplacementstringtouppercaseorlowercase,respectively.SubstitutionandRegularExpressions|15\Uor\Land\eor\E\Uand\Laresimilarto\uor\l,butallfollowingcharac-tersareconvertedtouppercaseorlowercaseuntiltheendofthereplacementstringoruntil\eor\Eisreached.Ifthereisno\eor\E,allcharactersofthereplacementtextareaffectedbythe\Uor\L.MoreSubstitutionTricks•Youcaninstructvitoignorecasebytyping:setic.•Asimple:sisthesameas:s//~/.•:&isthesameas:s.Youcanfollowthe&withgtomakethesubstitutiongloballyontheline,andevenuseitwithalinerange.•Youcanusethe&keyasavicommandtoperformthe:&command,i.e.,torepeatthelastsubstitution.•The:~commandissimilartothe:&command,butwithasubtledifference.Thesearchpatternusedisthelastre

用户评论

0/200
暂无评论
上传我的资料

该用户的其它资料

关闭

请选择举报的类型

关闭

提示

提交成功!

感谢您对爱问共享资料的支持,我们将尽快核实并处理您的举报信息。

关闭

提示

提交失败!

您的举报信息提交失败,请重试!

关闭

提示

重复举报!

亲爱的用户!感觉您对爱问共享资料的支持,请勿重复举报噢!

全屏 缩小 放大
收藏
资料评价:

/ 94
所需积分:0 立即下载
返回
顶部
举报
资料
关闭

温馨提示

感谢您对爱问共享资料的支持,精彩活动将尽快为您呈现,敬请期待!