You are on page 1of 4

The Vim commands cheat sheet

http://www.tuxles.org/linuxhelp/vimcheat.html

<TheVimcommandscheatsheet-1.2> AVimcheatsheet,listingsomeuseful,essentialandmostoftenusedVimcommands. Author:NanaLngstedt<nana.langstedtatgmail.com> tuXfilecreated:18January2003 Lastmodified:5September2009 contents Workingwithfiles Movingaroundinthefile Insertingandoverwritingtext Deletingtext Enteringvisualmode Editingblocksoftext Undoandredo Search Replace

<ThelistofVimcommands> Workingwithfiles Vimcommand :efilename :wfilename :q :q! :wq :x Action Openanewfile.YoucanusetheTabkeyforautomaticfilenamecompletion,justlikeatthe shellcommandprompt. Savechangestoafile.Ifyoudon'tspecifyafilename,Vimsavesasthefilenameyouwere editing.Forsavingthefileunderadifferentname,specifythefilename. QuitVim.Ifyouhaveunsavedchanges,Vimrefusestoexit. ExitVimwithoutsavingchanges. Writethefileandexit. Almostthesameas:wq,writethefileandexitifyou'vemadechangestothefile.Ifyouhaven't madeanychangestothefile,Vimexitswithoutwritingthefile.

Movingaroundinthefile TheseVimcommandsandkeysworkbothincommandmodeandvisualmode. Vimcommand jorUpArrow korDown Arrow horLeftArrow lorRight Arrow e Action Movethecursoruponeline. Downoneline. Leftonecharacter. Rightonecharacter. Totheendofaword.

1 of 4

Tuesday 17 January 2012 06:57 PM

The Vim commands cheat sheet

http://www.tuxles.org/linuxhelp/vimcheat.html

E b B 0 ^ $ H M L :n

Totheendofawhitespace-delimitedword. Tothebeginningofaword. Tothebeginningofawhitespace-delimitedword. Tothebeginningofaline. Tothefirstnon-whitespacecharacterofaline. Totheendofaline. Tothefirstlineofthescreen. Tothemiddlelineofthescreen. Tothethelastlineofthescreen. Jumptolinenumbern.Forexample,tojumptoline42,you'dtype:42

Insertingandoverwritingtext Vimcommand i I a A o O C r R TheESCkey Deletingtext Vimcommand x X ddor:d Action Deletecharactersunderthecursor. Deletecharactersbeforethecursor. Deletethecurrentline. Action Insertbeforecursor. Inserttothestartofthecurrentline. Appendaftercursor. Appendtotheendofthecurrentline. Openanewlinebelowandinsert. Openanewlineaboveandinsert. Changetherestofthecurrentline. Overwriteonecharacter.Afteroverwritingthesinglecharacter,gobacktocommandmode. Enterinsertmodebutreplacecharactersratherthaninserting. Exitinsert/overwritemodeandgobacktocommandmode.

Enteringvisualmode Vimcommand v V TheESCkey Action Starthighlightingcharacters.Usethenormalmovementkeysandcommandstoselecttextfor highlighting. Starthighlightinglines. Exitvisualmodeandreturntocommandmode.

2 of 4

Tuesday 17 January 2012 06:57 PM

The Vim commands cheat sheet

http://www.tuxles.org/linuxhelp/vimcheat.html

Editingblocksoftext Note:theVimcommandsmarkedwith(V)workinvisualmode,whenyou'veselectedsometext.Theother commandsworkinthecommandmode,whenyouhaven'tselectedanytext. Vimcommand ~ >(V) <(V) c(V) y(V) d(V) yyor:yorY ddor:d p P Undoandredo Vimcommand u U Ctrl+r Search Vimcommand /pattern n N Replace Vimcommand :rs/foo/bar/a Action Substitutefoowithbar.rdeterminestherangeandadeterminesthearguments. Action Searchthefileforpattern. Scanfornextsearchmatchinthesamedirection. Scanfornextsearchmatchbutoppositedirection. Action Undothelastaction. Undoallthelatestchangesthatweremadetothecurrentline. Redo. Action Changethecaseofcharacters.Thisworksbothinvisualandcommandmode.Invisualmode, changethecaseofhighlightedcharacters.Incommandmode,changethecaseofthecharacter udercursor. Shiftright(indent). Shiftleft(de-indent). Changethehighlightedtext. Yankthehighlightedtext.InWindowsterms,"copytheselectedtexttoclipboard." Deletethehighlightedtext.InWindowsterms,"cuttheselectedtexttoclipboard." Yankthecurrentline.Youdon'tneedtohighlightitfirst. Deletethecurrentline.Again,youdon'tneedtohighlightitfirst. Putthetextyouyankedordeleted.InWindowsterms,"pastethecontentsoftheclipboard".Put charactersafterthecursor.Putlinesbelowthecurrentline. Putcharactersbeforethecursor.Putlinesabovethecurrentline.

Therange(r)canbe nothing number % Workoncurrentlineonly. Workonthelinewhosenumberyougive. Thewholefile.

3 of 4

Tuesday 17 January 2012 06:57 PM

The Vim commands cheat sheet

http://www.tuxles.org/linuxhelp/vimcheat.html

Arguments(a)canbe g i I c Examples :452s/foo/bar/ :s/foo/bar/g :%s/foo/bar/g :%s/foo/bar/gi :%s/foo/bar/gc :%s/foo/bar/c Replacethefirstoccurrenceofthewordfoowithbaronlinenumber452. Replaceeveryoccurrenceofthewordfoowithbaroncurrentline. Replaceeveryoccurrenceofthewordfoowithbarinthewholefile. Thesameasabove,butignorethecaseofthepatternyouwanttosubstitute.Thisreplaces foo,FOO,Foo,andsoon. Confirmeverysubstitution. Foreachlineonthefile,replacethefirstoccurrenceoffoowithbarandconfirmevery substitution. Replacealloccurrencesintheline.Withoutthis,Vimreplacesonlythefirstoccurrencesineach line. Ignorecaseforthesearchpattern. Don'tignorecase. Confirmeachsubstitution.Youcantypeytosubstitutethismatch,ntoskipthismatch,ato substitutethisandalltheremainingmatches("Yestoall"),andqtoquitsubstitution.

Linuxhelp>Tipsandcheatsheets>TheVimcommandscheatsheet

4 of 4

Tuesday 17 January 2012 06:57 PM

You might also like