SlideShare a Scribd company logo
1 of 2
Download to read offline
VI “Cheat” Sheet
ACNS Bulletin ED–03
February 1995
File management commands
:w name Write edit buffer to file name
:wq Write to file and quit
:q! Quit without saving changes
ZZ Same as :wq
:sh Execute shell commands (<ctrl>d)
Window motions
<ctrl>d Scroll down (half a screen)
<ctrl>u Scroll up (half a screen)
<ctrl>f Page forward
<ctrl>b Page backward
/string Search forward
?string Search backward
<ctrl>l Redraw screen
<ctrl>g Display current line number and
file information
n Repeat search
N Repeat search reverse
G Go to last line
nG Go to line n
:n Go to line n
z<CR> Reposition window: cursor at top
z. Reposition window: cursor in middle
z- Reposition window: cursor at bottom
Cursor motions
H Upper left corner (home)
M Middle line
L Lower left corner
h Back a character
j Down a line
k Up a line
^ Beginning of line
$ End of line
l Forward a character
w One word forward
b Back one word
fc Find c
; Repeat find (find next c)
Command mode versus input mode
Vi starts in command mode. The positioning commands
operate only while vi is in command mode. You switch vi
to input mode by entering any one of several vi input com-
mands. (See next section.) Once in input mode, any charac-
ter you type is taken to be text and is added to the file. You
cannot execute any commands until you exit input mode.
To exit input mode, press the escape (Esc) key.
Input commands (end with Esc)
a Append after cursor
i Insert before cursor
o Open line below
O Open line above
:r file Insert file after current line
Any of these commands leaves vi in input mode until you
press Esc. Pressing the RETURN key will not take you out
of input mode.
Change commands (Input mode)
cw Change word (Esc)
cc Change line (Esc) - blanks line
c$ Change to end of line
rc Replace character with c
R Replace (Esc) - typeover
s Substitute (Esc) - 1 char with string
S Substitute (Esc) - Rest of line with
text
. Repeat last change
Changes during insert mode
<ctrl>h Back one character
<ctrl>w Back one word
<ctrl>u Back to beginning of insert
vi Editor “Cheat Sheet”
Invoking vi: vi filename
Format of vi commands: [count][command] (count repeats the effect of the command)
Deletion commands
dd or ndd Delete n lines to general buffer
dw Delete word to general buffer
dnw Delete n words
d) Delete to end of sentence
db Delete previous word
D Delete to end of line
x Delete character
Recovering deletions
p Put general buffer after cursor
P Put general buffer before cursor
Undo commands
u Undo last change
U Undo all changes on line
Rearrangement commands
yy or Y Yank (copy) line to general buffer
“z6yy Yank 6 lines to buffer z
yw Yank word to general buffer
“a9dd Delete 9 lines to buffer a
“A9dd Delete 9 lines; Append to buffer a
“ap Put text from buffer a after cursor
p Put general buffer after cursor
P Put general buffer before cursor
J Join lines
Parameters
:set list Show invisible characters
:set nolist Don’t show invisible characters
:set number Show line numbers
:set nonumber Don’t show line numbers
:set autoindent Indent after carriage return
:set noautoindent Turn off autoindent
:set showmatch Show matching sets of
parentheses as they are typed
:set noshowmatch Turn off showmatch
:set showmode Display mode on last line of screen
:set noshowmode Turn off showmode
:set all Show values of all possible
parameters
Move text from file old to file new
vi old
“a10yy yank 10 lines to buffer a
:w write work buffer
:e new edit new file
“ap put text from a after cursor
:30,60w new Write lines 30 to 60 in file new
Regular expressions (search strings)
^ Matches beginning of line
$ Matches end of line
. Matches any single character
* Matches any previous character
.* Matches any character
Search and replace commands
Syntax:
:[address]s/old_text/new_text/
Address components:
. Current line
n Line number n
.+m Current line plus m lines
$ Last line
/string/ A line that contains "string"
% Entire file
[addr1],[addr2] Specifies a range
Examples:
The following example replaces only the first occur-
rence of Banana with Kumquat in each of 11 lines
starting with the current line (.) and continuing for the
10 that follow (.+10).
:.,.+10s/Banana/Kumquat
The following example replaces every occurrence
(caused by the g at the end of the command) of
apple with pear.
:%s/apple/pear/g
The following example removes the last character from
every line in the file. Use it if every line in the file ends
with ^M as the result of a file transfer. Execute it
when the cursor is on the first line of the file.
:%s/.$//

More Related Content

What's hot

M|18 Deep Dive: InnoDB Transactions and Write Paths
M|18 Deep Dive: InnoDB Transactions and Write PathsM|18 Deep Dive: InnoDB Transactions and Write Paths
M|18 Deep Dive: InnoDB Transactions and Write PathsMariaDB plc
 
Php(report)
Php(report)Php(report)
Php(report)Yhannah
 
Software engineering interview questions
Software engineering interview questionsSoftware engineering interview questions
Software engineering interview questionsMuhammadTalha436
 
Tweaking the interactive grid
Tweaking the interactive gridTweaking the interactive grid
Tweaking the interactive gridRoel Hartman
 
Advanced rac troubleshooting
Advanced rac troubleshootingAdvanced rac troubleshooting
Advanced rac troubleshootingRiyaj Shamsudeen
 
T codes
T codesT codes
T codesRAJ P
 
Modeling with Hadoop kdd2011
Modeling with Hadoop kdd2011Modeling with Hadoop kdd2011
Modeling with Hadoop kdd2011Milind Bhandarkar
 
Prise en main de Dreamweaver
Prise en main de DreamweaverPrise en main de Dreamweaver
Prise en main de DreamweaverAbdoulaye Dieng
 
DB2 Basic Commands - UDB
DB2 Basic Commands - UDBDB2 Basic Commands - UDB
DB2 Basic Commands - UDBSrinimf-Slides
 
Cours+sql++ +base+de+données+-+bac+informatique+(2009-2010)++elève++khmiri+zied
Cours+sql++ +base+de+données+-+bac+informatique+(2009-2010)++elève++khmiri+ziedCours+sql++ +base+de+données+-+bac+informatique+(2009-2010)++elève++khmiri+zied
Cours+sql++ +base+de+données+-+bac+informatique+(2009-2010)++elève++khmiri+ziedWajdi Ben Helal
 
Docker at Spotify - Dockercon14
Docker at Spotify - Dockercon14Docker at Spotify - Dockercon14
Docker at Spotify - Dockercon14dotCloud
 
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsMongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsSpringPeople
 
List Processing in ABAP
List Processing in ABAPList Processing in ABAP
List Processing in ABAPsapdocs. info
 

What's hot (20)

Ceph on Windows
Ceph on WindowsCeph on Windows
Ceph on Windows
 
M|18 Deep Dive: InnoDB Transactions and Write Paths
M|18 Deep Dive: InnoDB Transactions and Write PathsM|18 Deep Dive: InnoDB Transactions and Write Paths
M|18 Deep Dive: InnoDB Transactions and Write Paths
 
Php(report)
Php(report)Php(report)
Php(report)
 
Software engineering interview questions
Software engineering interview questionsSoftware engineering interview questions
Software engineering interview questions
 
MySQL Backup & Recovery
MySQL Backup & RecoveryMySQL Backup & Recovery
MySQL Backup & Recovery
 
Tweaking the interactive grid
Tweaking the interactive gridTweaking the interactive grid
Tweaking the interactive grid
 
Advanced rac troubleshooting
Advanced rac troubleshootingAdvanced rac troubleshooting
Advanced rac troubleshooting
 
T codes
T codesT codes
T codes
 
Mongo DB Presentation
Mongo DB PresentationMongo DB Presentation
Mongo DB Presentation
 
Modeling with Hadoop kdd2011
Modeling with Hadoop kdd2011Modeling with Hadoop kdd2011
Modeling with Hadoop kdd2011
 
[O'Reilly] HTML5 Design
[O'Reilly] HTML5 Design[O'Reilly] HTML5 Design
[O'Reilly] HTML5 Design
 
Prise en main de Dreamweaver
Prise en main de DreamweaverPrise en main de Dreamweaver
Prise en main de Dreamweaver
 
sap script overview
sap script overviewsap script overview
sap script overview
 
DB2 Basic Commands - UDB
DB2 Basic Commands - UDBDB2 Basic Commands - UDB
DB2 Basic Commands - UDB
 
Cours+sql++ +base+de+données+-+bac+informatique+(2009-2010)++elève++khmiri+zied
Cours+sql++ +base+de+données+-+bac+informatique+(2009-2010)++elève++khmiri+ziedCours+sql++ +base+de+données+-+bac+informatique+(2009-2010)++elève++khmiri+zied
Cours+sql++ +base+de+données+-+bac+informatique+(2009-2010)++elève++khmiri+zied
 
Docker at Spotify - Dockercon14
Docker at Spotify - Dockercon14Docker at Spotify - Dockercon14
Docker at Spotify - Dockercon14
 
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsMongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
 
List Processing in ABAP
List Processing in ABAPList Processing in ABAP
List Processing in ABAP
 
HTML & CSS
HTML & CSSHTML & CSS
HTML & CSS
 
Algorithmes de jeux
Algorithmes de jeuxAlgorithmes de jeux
Algorithmes de jeux
 

Similar to Vi cheat sheet

Similar to Vi cheat sheet (20)

Vi reference
Vi referenceVi reference
Vi reference
 
Vi reference
Vi referenceVi reference
Vi reference
 
Vi editor commands
Vi editor commandsVi editor commands
Vi editor commands
 
vim-cheatsheet.pdf
vim-cheatsheet.pdfvim-cheatsheet.pdf
vim-cheatsheet.pdf
 
API TEST
API TESTAPI TEST
API TEST
 
API TEST
API TESTAPI TEST
API TEST
 
Vi Cheat Sheet
Vi Cheat SheetVi Cheat Sheet
Vi Cheat Sheet
 
Vi cheat sheet
Vi cheat sheetVi cheat sheet
Vi cheat sheet
 
Beginning with vi text editor
Beginning with vi text editorBeginning with vi text editor
Beginning with vi text editor
 
vim
vimvim
vim
 
Vim Cheat Sheet.pdf
Vim Cheat Sheet.pdfVim Cheat Sheet.pdf
Vim Cheat Sheet.pdf
 
VI Editors
VI EditorsVI Editors
VI Editors
 
Using vi editor
Using vi editorUsing vi editor
Using vi editor
 
Using VI Editor in Red Hat by Rohit Kumar
Using VI Editor in Red Hat by Rohit KumarUsing VI Editor in Red Hat by Rohit Kumar
Using VI Editor in Red Hat by Rohit Kumar
 
GNU Emacs Reference Card.pdf
GNU Emacs Reference Card.pdfGNU Emacs Reference Card.pdf
GNU Emacs Reference Card.pdf
 
101 3.8.2 vim reference card
101 3.8.2 vim reference card101 3.8.2 vim reference card
101 3.8.2 vim reference card
 
3.8.b vim reference card
3.8.b vim reference card3.8.b vim reference card
3.8.b vim reference card
 
Vi help-sheet-011
Vi help-sheet-011Vi help-sheet-011
Vi help-sheet-011
 
Vim
VimVim
Vim
 
Vi editor
Vi editorVi editor
Vi editor
 

Recently uploaded

Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfNirmal Dwivedi
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxakanksha16arora
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfstareducators107
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonhttgc7rh9c
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use CasesTechSoup
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesSHIVANANDaRV
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 

Recently uploaded (20)

Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 

Vi cheat sheet

  • 1. VI “Cheat” Sheet ACNS Bulletin ED–03 February 1995 File management commands :w name Write edit buffer to file name :wq Write to file and quit :q! Quit without saving changes ZZ Same as :wq :sh Execute shell commands (<ctrl>d) Window motions <ctrl>d Scroll down (half a screen) <ctrl>u Scroll up (half a screen) <ctrl>f Page forward <ctrl>b Page backward /string Search forward ?string Search backward <ctrl>l Redraw screen <ctrl>g Display current line number and file information n Repeat search N Repeat search reverse G Go to last line nG Go to line n :n Go to line n z<CR> Reposition window: cursor at top z. Reposition window: cursor in middle z- Reposition window: cursor at bottom Cursor motions H Upper left corner (home) M Middle line L Lower left corner h Back a character j Down a line k Up a line ^ Beginning of line $ End of line l Forward a character w One word forward b Back one word fc Find c ; Repeat find (find next c) Command mode versus input mode Vi starts in command mode. The positioning commands operate only while vi is in command mode. You switch vi to input mode by entering any one of several vi input com- mands. (See next section.) Once in input mode, any charac- ter you type is taken to be text and is added to the file. You cannot execute any commands until you exit input mode. To exit input mode, press the escape (Esc) key. Input commands (end with Esc) a Append after cursor i Insert before cursor o Open line below O Open line above :r file Insert file after current line Any of these commands leaves vi in input mode until you press Esc. Pressing the RETURN key will not take you out of input mode. Change commands (Input mode) cw Change word (Esc) cc Change line (Esc) - blanks line c$ Change to end of line rc Replace character with c R Replace (Esc) - typeover s Substitute (Esc) - 1 char with string S Substitute (Esc) - Rest of line with text . Repeat last change Changes during insert mode <ctrl>h Back one character <ctrl>w Back one word <ctrl>u Back to beginning of insert vi Editor “Cheat Sheet” Invoking vi: vi filename Format of vi commands: [count][command] (count repeats the effect of the command)
  • 2. Deletion commands dd or ndd Delete n lines to general buffer dw Delete word to general buffer dnw Delete n words d) Delete to end of sentence db Delete previous word D Delete to end of line x Delete character Recovering deletions p Put general buffer after cursor P Put general buffer before cursor Undo commands u Undo last change U Undo all changes on line Rearrangement commands yy or Y Yank (copy) line to general buffer “z6yy Yank 6 lines to buffer z yw Yank word to general buffer “a9dd Delete 9 lines to buffer a “A9dd Delete 9 lines; Append to buffer a “ap Put text from buffer a after cursor p Put general buffer after cursor P Put general buffer before cursor J Join lines Parameters :set list Show invisible characters :set nolist Don’t show invisible characters :set number Show line numbers :set nonumber Don’t show line numbers :set autoindent Indent after carriage return :set noautoindent Turn off autoindent :set showmatch Show matching sets of parentheses as they are typed :set noshowmatch Turn off showmatch :set showmode Display mode on last line of screen :set noshowmode Turn off showmode :set all Show values of all possible parameters Move text from file old to file new vi old “a10yy yank 10 lines to buffer a :w write work buffer :e new edit new file “ap put text from a after cursor :30,60w new Write lines 30 to 60 in file new Regular expressions (search strings) ^ Matches beginning of line $ Matches end of line . Matches any single character * Matches any previous character .* Matches any character Search and replace commands Syntax: :[address]s/old_text/new_text/ Address components: . Current line n Line number n .+m Current line plus m lines $ Last line /string/ A line that contains "string" % Entire file [addr1],[addr2] Specifies a range Examples: The following example replaces only the first occur- rence of Banana with Kumquat in each of 11 lines starting with the current line (.) and continuing for the 10 that follow (.+10). :.,.+10s/Banana/Kumquat The following example replaces every occurrence (caused by the g at the end of the command) of apple with pear. :%s/apple/pear/g The following example removes the last character from every line in the file. Use it if every line in the file ends with ^M as the result of a file transfer. Execute it when the cursor is on the first line of the file. :%s/.$//