Sie sind auf Seite 1von 7

11/4/2016 VimCommandsCheatSheet

VimCommandsCheatSheet

HowtoExit
:q[uit] QuitVim.Thisfailswhenchangeshavebeenmade.
:q[uit]! Quitwithoutwriting.
:cq[uit] Quitalways,withoutwriting.
:wq Writethecurrentfileandexit.
:wq! Writethecurrentfileandexitalways.
:wq{file} Writeto{file}.Exitifnoteditingthelast
:wq!{file} Writeto{file}andexitalways.
:[range]wq[!] [file]Sameasabove,butonlywritethelinesin[range].
ZZ Writecurrentfile,ifmodified,andexit.
ZQ Quitcurrentfileandexit(sameas":q!").

EditingaFile
Editthecurrentfile.Thisisusefultoreeditthecurrentfile,whenithasbeenchangedoutsideof
:e[dit]
Vim.
Editthecurrentfilealways.Discardanychangestothecurrentbuffer.Thisisusefulifyouwantto
:e[dit]!
startalloveragain.
:e[dit]
Edit{file}.
{file}
:e[dit]!
Edit{file}always.Discardanychangestothecurrentbuffer.
{file}
gf Editthefilewhosenameisunderorafterthecursor.Mnemonic:"gotofile".

InsertingText
a Appendtextafterthecursor[count]times.
A Appendtextattheendoftheline[count]times.
i Inserttextbeforethecursor[count]times.
I Inserttextbeforethefirstnonblankintheline[count]times.
gI Inserttextincolumn1[count]times.
o Beginanewlinebelowthecursorandinserttext,repeat[count]times.
O Beginanewlineabovethecursorandinserttext,repeat[count]times.

https://www.fprintf.net/vimCheatSheet.html 1/7
11/4/2016 VimCommandsCheatSheet

Insertingafile
:r[ead][name] Insertthefile[name]belowthecursor.
:r[ead]!{cmd} Execute{cmd}andinsertitsstandardoutputbelowthecursor.

DeletingText
<Del>or
Delete[count]charactersunderandafterthecursor
x
X Delete[count]charactersbeforethecursor
d{motion} Deletetextthat{motion}movesover
dd Delete[count]lines
D Deletethecharactersunderthecursoruntiltheendoftheline
{Visual}xor
Deletethehighlightedtext(for{Visual}seeSelectingText).
{Visual}d
{Visual}CTRLHor
WheninSelectmode:Deletethehighlightedtext
{Visual}
{Visual}Xor
Deletethehighlightedlines
{Visual}D
:[range]d[elete] Delete[range]lines(default:currentline)
:[range]d[elete]{count} Delete{count}lines,startingwith[range]

Changing(orReplacing)Text
r{char} replacethecharacterunderthecursorwith{char}.
R EnterInsertmode,replacingcharactersratherthaninserting
Switchcaseofthecharacterunderthecursorandmovethecursortotheright.Ifa[count]isgiven,
~
dothatmanycharacters.
~
switchcaseof{motion}text.
{motion}
{Visual}~ Switchcaseofhighlightedtext

Substituting
:[range]s[ubstitute]/{pattern}/{string}/[c]
Foreachlinein[range]replaceamatchof{pattern}with{string}.
[e][g][p][r][i][I][count]
:[range]s[ubstitute][c][e][g][r][i][I] Repeatlast:substitutewithsamesearchpatternandsubstitute
[count]:[range]&[c][e][g][r][i][I][count] string,butwithoutthesameflags.Youmayaddextraflags

https://www.fprintf.net/vimCheatSheet.html 2/7
11/4/2016 VimCommandsCheatSheet

Theargumentsthatyoucanuseforthesubstitutecommands:
[c]Confirmeachsubstitution.Vimpositionsthecursoronthematching
string.Youcantype:
'y'tosubstitutethismatch
'n'toskipthismatch
toskipthismatch
'a'tosubstitutethisandallremainingmatches{notinVi}
'q'toquitsubstituting{notinVi}
CTRLEtoscrollthescreenup{notinVi}
CTRLYtoscrollthescreendown{notinVi}.
[e]Whenthesearchpatternfails,donotissueanerrormessageand,in
particular,continueinmapsasifnoerroroccurred.
[g]Replacealloccurrencesintheline.Withoutthisargument,
replacementoccursonlyforthefirstoccurrenceineachline.
[i]Ignorecaseforthepattern.
[I]Don'tignorecaseforthepattern.
[p]Printthelinecontainingthelastsubstitute.

CopyingandMovingText
"{azAZ0 Useregister{azAZ09.%#:"}fornextdelete,yankorput(useuppercasecharacterto
9.%#:"} appendwithdeleteandyank)({.%#:}onlyworkwithput).
:reg[isters] Displaythecontentsofallnumberedandnamedregisters.
:reg[isters]
Displaythecontentsofthenumberedandnamedregistersthatarementionedin{arg}.
{arg}
:di[splay][arg] Sameas:registers.
["x]y{motion} Yank{motion}text[intoregisterx].
["x]yy Yank[count]lines[intoregisterx]
["x]Y yank[count]lines[intoregisterx](synonymforyy).
{Visual}["x]y Yankthehighlightedtext[intoregisterx](for{Visual}seeSelectingText).
{Visual}["x]Y Yankthehighlightedlines[intoregisterx]
:[range]y[ank]
Yank[range]lines[intoregisterx].
[x]
:[range]y[ank] Yank{count}lines,startingwithlastlinenumberin[range](default:currentline),[into
[x]{count} registerx].
["x]p Putthetext[fromregisterx]afterthecursor[count]times.
["x]P Putthetext[fromregisterx]beforethecursor[count]times.
["x]gp Justlike"p",butleavethecursorjustafterthenewtext.
["x]gP Justlike"P",butleavethecursorjustafterthenewtext.
:[line]pu[t][x] Putthetext[fromregisterx]after[line](defaultcurrentline).
:[line]pu[t]![x] Putthetext[fromregisterx]before[line](defaultcurrentline).

Undo/Redo/Repeat
u Undo[count]changes.
:u[ndo] Undoonechange.

https://www.fprintf.net/vimCheatSheet.html 3/7
11/4/2016 VimCommandsCheatSheet

CTRLR Redo[count]changeswhichwereundone.
:red[o] Redoonechangewhichwasundone.
U Undoalllatestchangesononeline.{Vi:whilenotmovedoffofit}
. Repeatlastchange,withcountreplacedwith[count].

MovingAround
Basicmotioncommands:

k
hl
j

hor [count]characterstotheleft(exclusive).
lor
[count]characterstotheright(exclusive).
or
kor
or [count]linesupward
CTRLP
jor
or
CTRLJor [count]linesdownward(linewise).
or
CTRLN
0 Tothefirstcharacteroftheline(exclusive).
<Home> Tothefirstcharacteroftheline(exclusive).
^ Tothefirstnonblankcharacteroftheline
$or
Totheendofthelineand[count1]linesdownward
<End>
Whenlineswrap('wrapon):Tothefirstcharacterofthescreenline(exclusive).Differsfrom
g0or "0"whenalineiswiderthanthescreen.Whenlinesdon'twrap('wrap'off):Totheleftmost
g<Home> characterofthecurrentlinethatisonthescreen.Differsfrom"0"whenthefirstcharacterof
thelineisnotonthescreen.
Whenlineswrap('wrap'on):Tothefirstnonblankcharacterofthescreenline(exclusive).
Differsfrom"^"whenalineiswiderthanthescreen.Whenlinesdon'twrap('wrap'off):Tothe
g^
leftmostnonblankcharacterofthecurrentlinethatisonthescreen.Differsfrom"^"whenthe
firstnonblankcharacterofthelineisnotonthescreen.
Whenlineswrap('wrap'on):Tothelastcharacterofthescreenlineand[count1]screenlines
g$or downward(inclusive).Differsfrom"$"whenalineiswiderthanthescreen.Whenlinesdon't
g<End&gr wrap('wrap'off):Totherightmostcharacterofthecurrentlinethatisvisibleonthescreen.
Differsfrom"$"whenthelastcharacterofthelineisnotonthescreenorwhenacountisused.
f{char} To[count]'thoccurrenceof{char}totheright.Thecursorisplacedon{char}(inclusive).
F{char} Tothe[count]'thoccurrenceof{char}totheleft.Thecursorisplacedon{char}(inclusive).
Tillbefore[count]'thoccurrenceof{char}totheright.Thecursorisplacedonthecharacter
t{char}
leftof{char}(inclusive).
Tillafter[count]'thoccurrenceof{char}totheleft.Thecursorisplacedonthecharacterright
T{char}
of{char}(inclusive).
https://www.fprintf.net/vimCheatSheet.html 4/7
11/4/2016 VimCommandsCheatSheet

Repeatlatestf,t,ForT[count]times.
, Repeatlatestf,t,ForTinoppositedirection[count]times.
<minus> [count]linesupward,onthefirstnonblankcharacter(linewise).
+or
CTRLMor [count]linesdownward,onthefirstnonblankcharacter(linewise).
<CR>
_
[count]1linesdownward,onthefirstnonblankcharacter(linewise).
<underscore>
<CEnd>or
Gotoline[count],defaultlastline,onthefirstnonblankcharacter.
G
<CHome>
or Gotoline[count],defaultfirstline,onthefirstnonblankcharacter.
gg
<SRight>or
[count]wordsforward
w
<CRight>or
[count]WORDSforward
W
e Forwardtotheendofword[count]
E ForwardtotheendofWORD[count]
<SLeft>or
[count]wordsbackward
b
<CLeft>or
[count]WORDSbackward
B
ge Backwardtotheendofword[count]
gE BackwardtotheendofWORD[count]
ThesecommandsmoveoverwordsorWORDS.

Awordconsistsofasequenceofletters,digitsandunderscores,orasequenceofothernonblankcharacters,
separatedwithwhitespace(spaces,tabs,).Thiscanbechangedwiththe'iskeyword'option.

AWORDconsistsofasequenceofnonblankcharacters,separatedwithwhitespace.Anemptylineisalso
consideredtobeawordandaWORD.

( [count]sentencesbackward
) [count]sentencesforward
{ [count]paragraphsbackward
} [count]paragraphsforward
[count]sectionsforwardortothenext'{'inthefirstcolumn.Whenusedafteranoperator,thenthe'}'inthe
]]
firstcolumn.
][ [count]sectionsforwardortothenext'}'inthefirstcolumn
[[ [count]sectionsbackwardortotheprevious'{'inthefirstcolumn
[] [count]sectionsbackwardortotheprevious'}'inthefirstcolumn

Screenmovementcommands

z. Centerthescreenonthecursor
https://www.fprintf.net/vimCheatSheet.html 5/7
11/4/2016 VimCommandsCheatSheet

zt Scrollthescreensothecursorisatthetop
zb Scrollthescreensothecursorisatthebottom

Marks
Setmark{azAZ}atcursorposition(doesnotmovethecursor,thisisnotamotion
m{azAZ}
command).
m'or Setthepreviouscontextmark.Thiscanbejumpedtowiththe"''"or"``"command(doesnot
m` movethecursor,thisisnotamotioncommand).
:[range]ma[rk]
Setmark{azAZ}atlastlinenumberin[range],column0.Defaultiscursorline.
{azAZ}
:[range]k{azA
Sameas:mark,butthespacebeforethemarknamecanbeomitted.
Z}
'{az} Tothefirstnonblankcharacteronthelinewithmark{az}(linewise).
'{AZ09} Tothefirstnonblankcharacteronthelinewithmark{AZ09}inthecorrectfile
`{az} Tothemark{az}
`{AZ09} Tothemark{AZ09}inthecorrectfile
:marks Listallthecurrentmarks(notamotioncommand).
:marks{arg} Listthemarksthatarementionedin{arg}(notamotioncommand).Forexample:

Searching
/{pattern}[/] Searchforwardforthe[count]'thoccurrenceof{pattern}
Searchforwardforthe[count]'thoccurrenceof{pattern}andgo{offset}linesupor
/{pattern}/{offset}
down.
/<CR> Searchforwardforthe[count]'thlatestusedpattern
Searchforwardforthe[count]'thlatestusedpatternwithnew.If{offset}isemptyno
//{offset}<CR>
offsetisused.
?{pattern}[?]<CR> Searchbackwardforthe[count]'thpreviousoccurrenceof{pattern}
?{pattern}?{offset} Searchbackwardforthe[count]'thpreviousoccurrenceof{pattern}andgo{offset}
<CR> linesupordown
?<CR> Searchbackwardforthe[count]'thlatestusedpattern
Searchbackwardforthe[count]'thlatestusedpatternwithnew{offset}.If{offset}is
??{offset}<CR>
emptynooffsetisused.
n Repeatthelatest"/"or"?"[count]times.
N Repeatthelatest"/"or"?"[count]timesinoppositedirection.

SelectingText(VisualMode)

https://www.fprintf.net/vimCheatSheet.html 6/7
11/4/2016 VimCommandsCheatSheet

Toselecttext,entervisualmodewithoneofthecommandsbelow,andusemotioncommandstohighlightthe
textyouareinterestedin.Then,usesomecommandonthetext.
Theoperatorsthatcanbeusedare:
~switchcase
ddelete
cchange
yyank
>shiftright
<shiftleft
!filterthroughexternalcommand
=filterthrough'equalprg'optioncommand
gqformatlinesto'textwidth'length

v startVisualmodepercharacter.
V startVisualmodelinewise.
<Esc> exitVisualmodewithoutmakinganychanges

HowtoSuspend
SuspendVim,like":stop".WorksinNormalandinVisualmode.InInsertandCommandline
CTRLZ
mode,theCTRLZisinsertedasanormalcharacter.
:sus[pend] SuspendVim.Ifthe'!'isnotgivenand'autowrite'isset,everybufferwithchangesandafilename
[!]or iswrittenout.Ifthe'!'isgivenor'autowrite'isnotset,changedbuffersarenotwritten,don'tforget
:st[op][!] tobringVimbacktotheforegroundlater!

DanielGryniewicz/dang@fprintf.net

https://www.fprintf.net/vimCheatSheet.html 7/7