0% found this document useful (0 votes)
103 views2 pages

Vi Editor Cheat Sheet: Movement Commands

The document provides a cheat sheet of common commands for the vi text editor, grouped into the following categories: 1) Movement commands for navigating text by characters, words, lines, sentences, paragraphs, and screens. 2) Editing commands for inserting, changing, deleting, moving, and yanking/copying text. 3) Commands for invoking vi to open and edit files, as well as exiting and saving files.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views2 pages

Vi Editor Cheat Sheet: Movement Commands

The document provides a cheat sheet of common commands for the vi text editor, grouped into the following categories: 1) Movement commands for navigating text by characters, words, lines, sentences, paragraphs, and screens. 2) Editing commands for inserting, changing, deleting, moving, and yanking/copying text. 3) Commands for invoking vi to open and edit files, as well as exiting and saving files.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ViEditorCheatSheet

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

You might also like