SlideShare a Scribd company logo
Using vi
2 Modes
Command Mode
vi starts in command mode. In command mode, everything you
type is a command to do something, like:
• move the cursor around
• save, quit, open a new file
• find and replace
• copy and paste, etc.
Insert Mode
While in insert mode, everything you type is inserted into the
document you’re editing.
Command Mode Insert Mode
i - ...at the current cursor position
I - ...at the beginning of the current line
a - ...at the next character
A - ...at the end of the current line
o - ...below the current line
O - ...above the current line
... plus lots more ways to get into insert mode
Esc
Ctrl-[
Ctrl-c
Get into insert mode:
Get into command mode:
You switch between
these two modes a lot
as you’re editing
Editing in command mode
• h j k l – Move cursor left, down, up, right
• x – Delete a character
• 5x – Delete 5 characters
• dd – Delete a line
• 5dd – Delete 5 lines
• dj – Delete the line below the cursor
• dk – Delete the line above the cursor
• u - Undo
Copy and Paste
Every time you delete something in vi, it gets
stored in a buffer that can then be pasted into
the file with p or P.
To put something into the copy buffer without
deleting it, you “yank” it using a variation of the
y command.
• yy – Yank the current line into the copy
buffer
Search and Replace
• /search_string<Enter> - Search for
“search_string” in the document. Type n to
jump to the next search result if there’s more
than 1
• :%s/aaa/a/g<Enter> - Replace all
occurrences of “aaa” with “a”.
Search and replace commands use a regex
language that supports wildcards, etc.
Using vi
Saving, quitting, and opening files
• :w, :wq, :q, :q! – Save, save-quit, quit.
Add a ! to any of these commands to force-
save or force-quit.
• :e file.js – Start editing a new file
• :sp file.js, :vsp file.js – Open a
new file in a split window, horizontally or
vertically. To move between windows, type
Ctrl-w then a direction key (h,j,k,l).

More Related Content

PDF
Linux text editors
PDF
Tuffarsi in vim
ODP
Язык программирования Тьюрингол
PPTX
Notepad Shortcuts
PDF
3.8.b vim reference card
PDF
Vi Editor in 100 minutes
PPTX
Unix - Filters/Editors
PDF
Regexp
Linux text editors
Tuffarsi in vim
Язык программирования Тьюрингол
Notepad Shortcuts
3.8.b vim reference card
Vi Editor in 100 minutes
Unix - Filters/Editors
Regexp

Viewers also liked (13)

PDF
The "vi" Text Editor
PPT
Unix Administration 1
PPTX
תהליך הרכישה באתר www.mehunan.com
PPTX
Vi editor
DOCX
Ingles
DOCX
Ingles
DOCX
Ingles
PPT
Биометрическая система идентификации
PPTX
getEUjob.com
PPTX
תלמידים מחוננים
PPTX
áLbum de fotografías
DOCX
Carta de recomendación
PDF
Exe11
The "vi" Text Editor
Unix Administration 1
תהליך הרכישה באתר www.mehunan.com
Vi editor
Ingles
Ingles
Ingles
Биометрическая система идентификации
getEUjob.com
תלמידים מחוננים
áLbum de fotografías
Carta de recomendación
Exe11
Ad

Similar to Using vi (20)

PDF
PPT
07 vi text_editor
PDF
Vi editor Linux Editors
PPT
PPTX
Presentacion vim
PDF
Vim Cheat Sheet.pdf
PDF
Linux text editors Vim nano
PDF
Vim Basics
PPTX
Vi editor
PPT
Mastering the Linux vi Editor: Essential Commands and Techniques
PPTX
Vi Vi Editor Unit 4 Power point presentation
PPTX
lectuer 21-22.pptx
DOCX
swl--3 (1).docx
PDF
Mission vim possible-full
PDF
Unix shell talk - RIT SSE
PPTX
Linux Basic commands and VI Editor
PDF
015-Editing-Files-With-Vi.pdf
PDF
1_Editors_in_Unix
PPTX
Linux basic1&amp;2
PPT
workshop_1.ppt
07 vi text_editor
Vi editor Linux Editors
Presentacion vim
Vim Cheat Sheet.pdf
Linux text editors Vim nano
Vim Basics
Vi editor
Mastering the Linux vi Editor: Essential Commands and Techniques
Vi Vi Editor Unit 4 Power point presentation
lectuer 21-22.pptx
swl--3 (1).docx
Mission vim possible-full
Unix shell talk - RIT SSE
Linux Basic commands and VI Editor
015-Editing-Files-With-Vi.pdf
1_Editors_in_Unix
Linux basic1&amp;2
workshop_1.ppt
Ad

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Machine Learning_overview_presentation.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Big Data Technologies - Introduction.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Tartificialntelligence_presentation.pptx
Encapsulation theory and applications.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Machine Learning_overview_presentation.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
NewMind AI Weekly Chronicles - August'25-Week II
Dropbox Q2 2025 Financial Results & Investor Presentation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
“AI and Expert System Decision Support & Business Intelligence Systems”
Digital-Transformation-Roadmap-for-Companies.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Programs and apps: productivity, graphics, security and other tools
Diabetes mellitus diagnosis method based random forest with bat algorithm
MIND Revenue Release Quarter 2 2025 Press Release
Big Data Technologies - Introduction.pptx
Spectral efficient network and resource selection model in 5G networks
Tartificialntelligence_presentation.pptx

Using vi

  • 2. 2 Modes Command Mode vi starts in command mode. In command mode, everything you type is a command to do something, like: • move the cursor around • save, quit, open a new file • find and replace • copy and paste, etc. Insert Mode While in insert mode, everything you type is inserted into the document you’re editing.
  • 3. Command Mode Insert Mode i - ...at the current cursor position I - ...at the beginning of the current line a - ...at the next character A - ...at the end of the current line o - ...below the current line O - ...above the current line ... plus lots more ways to get into insert mode Esc Ctrl-[ Ctrl-c Get into insert mode: Get into command mode: You switch between these two modes a lot as you’re editing
  • 4. Editing in command mode • h j k l – Move cursor left, down, up, right • x – Delete a character • 5x – Delete 5 characters • dd – Delete a line • 5dd – Delete 5 lines • dj – Delete the line below the cursor • dk – Delete the line above the cursor • u - Undo
  • 5. Copy and Paste Every time you delete something in vi, it gets stored in a buffer that can then be pasted into the file with p or P. To put something into the copy buffer without deleting it, you “yank” it using a variation of the y command. • yy – Yank the current line into the copy buffer
  • 6. Search and Replace • /search_string<Enter> - Search for “search_string” in the document. Type n to jump to the next search result if there’s more than 1 • :%s/aaa/a/g<Enter> - Replace all occurrences of “aaa” with “a”. Search and replace commands use a regex language that supports wildcards, etc.
  • 8. Saving, quitting, and opening files • :w, :wq, :q, :q! – Save, save-quit, quit. Add a ! to any of these commands to force- save or force-quit. • :e file.js – Start editing a new file • :sp file.js, :vsp file.js – Open a new file in a split window, horizontally or vertically. To move between windows, type Ctrl-w then a direction key (h,j,k,l).