Vi Editor Cheat Sheet: Movement Commands
Vi Editor Cheat Sheet: Movement Commands
MovementCommands
Character
h,j,k,l Left,down,up,right
Text
w,W,b,B Forward,backwardbyword
e,E Endofword
(,) Beginningofnext,previoussentence
{,} Beginningofnext,previousparagraph
[[,]] Beginningofnext,previoussection
Lines
0,$ First,lastpositionofcurrentline
^ Firstnonblankcharacterofcurrentline
+,- Firstcharacterofnext,previousline
H Toplineofscreen
M Middlelineofscreen
L Lastlineofscreen
n H,n L Linen fromtop,bottomofscreen
Scrolling
[Ctrl]F,[Ctrl]B Scrollforward,backwardonescreen
[Ctrl]D,[Ctrl]U Scrolldown,uponehalfscreen
[Ctrl]E,[Ctrl]Y Showonemorelineatbottom,topofwindow
z[Enter] Scrolluntillinewithcursorisattopofscreen
z. Scrolluntillinewithcursorisatmiddleofscreen
z- Scrolluntillinewithcursorisatbottomofscreen
Searches
/pattern Searchforwardforpattern
?pattern Searchbackwardforpattern
n,N Repeatlastsearchinsame,oppositedirection
/,? Repeatprevioussearchforward,backward
fx searchforwardforcharacterxincurrentline
Fx searchbackwardforcharacterxincurrentline
tx searchforwardforcharacterbeforexincurrentline
Tx searchbackwardforcharacterafterxincurrentline
; Repeatpreviouscurrentlinesearch
, Repeatpreviouscurrentlinesearchinoppositedirection
LineNumber
[Ctrl]G Displaycurrentlinenumber
nG Movetolinenumbern
G Movetolastlineinfile
:n movetolinenumbern
MarkingPosition
mx Markcurrentpositionasx
`x Movecursortox
`` Returntopreviousmarkorcontext
'x Movetobeginningoflinecontainingmarkx
'' Returntobegginingoflinecontainingpreviousmark
EditingCommands
Insert
i,a Inserttextbefore,aftercursor
I,A Inserttextatbeginning,endofline
o,O Opennewlinefortextbelow,abovecursor
Change
r Replacewithnexttypedcharacer
~ Changebetweenuppercaseandlowercase
cm Changetextblockdefinedbymovementcommandm (e.g.,cwchangesnextword)
cc Changecurrentline
C Changetoendofline
R Typeovercharacters
s Deletecharacterandcontinuetyping
S Deletecurrentlineandcontinuetyping
Delete,Move
x Deletecharacter
X Deletecharactertotheleftofthecursor
dm Deletetextblockdefinedbymovementcommandm (e.g.,dwdeletesnextword)
dd Deletecurrentline
D Deletetoendofline
p,P Putdeletedtextbefore,aftercursor
"n p Puttextfromdeletebuffernumbern aftercursor(forlastninedeletions)
Yank(copy)
ym Yank(copy)textblockdefinedbymovementcommandm (e.g.,ywyanksnextword)
yy,Y Yankcurrentline
"ayy Yankcurrentlineintonamedbuffera
p,P Putyankedtextbefore,aftercursor
"aP Puttextfrombufferabeforecursor
OtherCommands
. Repeatlasteditcommand
u Undolastedit
U Undochangestocurrentline
J Jointwolines
[Ctrl]L,[Ctrl]R Redrawscreen
Invokingvi
vi file Invokevieditoronfile
vi file1 file2 Invokevieditoronfilessequentially
view file Invokevieditoronfile inreadonlymode
vi -R file Invokevieditoronfile inreadonlymode
vi -r file Recoverfile andrecenteditsaftersystemcrash
vi + file Openfile atlastline
vi +n file Openfile atlinenumbern
vi +/pattern file Openfile atpattern
ExitandSaveCommands
ZZ Savefileandquit
:x Savefileandquit
:wq Save("write")fileandquit
:w Savefile
:w! Savefile(overridingprotection)
:30,60w newfile Savelines30through60asfilenewfile
:30,60w>> file Appendlines30through60tofilefile
:w %.new Savecurrentbuffernamedfile asfile.new
:q Quit
:q! Quit,discardinganychanges
Q Quitviandinvokeex
:e file2 Editfile2 withoutleavingvi
:e! file2 Discardchangestocurrentfile,theneditfile2 withoutleavingvi
:n Editnextfile
:e! Discardallchangessincelastsave
:e# Editalternatefile