SlideShare a Scribd company logo
1 of 2
Download to read offline
VI “Cheat” Sheet
                                                                                               ACNS Bulletin ED–03
                                                                                                   February 1995

                                  vi Editor “Cheat Sheet”
Invoking vi:                         vi filename
Format of vi commands:               [count][command]            (count repeats the effect of the command)

Command mode versus input mode                                   File management commands

Vi starts in command mode. The positioning commands               :w name         Write edit buffer to file name
operate only while vi is in command mode. You switch vi           :wq             Write to file and quit
to input mode by entering any one of several vi input com-        :q!             Quit without saving changes
mands. (See next section.) Once in input mode, any charac-        ZZ              Same as :wq
ter you type is taken to be text and is added to the file. You    :sh             Execute shell commands (<ctrl>d)
cannot execute any commands until you exit input mode.
To exit input mode, press the escape (Esc) key.
                                                                 Window motions
Input commands (end with Esc)                                     <ctrl>d         Scroll down (half a screen)
                                                                  <ctrl>u         Scroll up (half a screen)
 a                    Append after cursor
                                                                  <ctrl>f         Page forward
 i                    Insert before cursor
                                                                  <ctrl>b         Page backward
 o                    Open line below
                                                                  /string         Search forward
 O                    Open line above
                                                                  ?string         Search backward
 :r file              Insert file after current line
                                                                  <ctrl>l         Redraw screen
Any of these commands leaves vi in input mode until you           <ctrl>g         Display current line number and
press Esc. Pressing the RETURN key will not take you out                          file information
of input mode.
                                                                  n               Repeat search
                                                                  N               Repeat search reverse
Change commands (Input mode)                                      G               Go to last line
                                                                  nG              Go to line n
 cw                   Change word (Esc)
                                                                  :n              Go to line n
 cc                   Change line (Esc) - blanks line
                                                                  z<CR>           Reposition window: cursor at top
 c$                   Change to end of line
                                                                  z.              Reposition window: cursor in middle
 rc                   Replace character with c
                                                                  z-              Reposition window: cursor at bottom
 R                    Replace (Esc) - typeover
 s                    Substitute (Esc) - 1 char with string
 S                    Substitute (Esc) - Rest of line with       Cursor motions
                      text
                                                                  H               Upper left corner (home)
 .                    Repeat last change
                                                                  M               Middle line

Changes during insert mode
                                                                  L               Lower left corner
                                                                  h               Back a character
 <ctrl>h              Back one character                          j               Down a line
 <ctrl>w              Back one word                               k               Up a line
 <ctrl>u              Back to beginning of insert                 ^               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)
Deletion commands                                         Move text from file old to file new
dd or ndd           Delete n lines to general buffer       vi old
dw                  Delete word to general buffer          “a10yy               yank 10 lines to buffer a
dnw                 Delete n words                         :w                   write work buffer
d)                  Delete to end of sentence              :e new               edit new file
db                  Delete previous word                   “ap                  put text from a after cursor
D                   Delete to end of line                  :30,60w new          Write lines 30 to 60 in file new
x                   Delete character
                                                          Regular expressions (search strings)
Recovering deletions
                                                           ^                    Matches beginning of line
p                   Put general buffer after cursor        $                    Matches end of line
P                   Put general buffer before cursor       .                    Matches any single character
                                                           *                    Matches any previous character
Undo commands                                              .*                   Matches any character

u                   Undo last change
                                                          Search and replace commands
U                   Undo all changes on line


Rearrangement commands
                                                          Syntax:
                                                                :[address]s/old_text/new_text/
yy or Y             Yank (copy) line to general buffer
“z6yy               Yank 6 lines to buffer z              Address components:
yw                  Yank word to general buffer            .               Current line
“a9dd               Delete 9 lines to buffer a             n               Line number n
“A9dd               Delete 9 lines; Append to buffer a     .+m             Current line plus m lines
“ap                 Put text from buffer a after cursor    $               Last line
p                   Put general buffer after cursor        /string/        A line that contains "string"
P                   Put general buffer before cursor       %               Entire file
J                   Join lines                             [addr1],[addr2] Specifies a range

                                                          Examples:
Parameters
                                                            The following example replaces only the first occur-
:set list           Show invisible characters               rence of Banana with Kumquat in each of 11 lines
:set nolist         Don’t show invisible characters         starting with the current line (.) and continuing for the
                                                            10 that follow (.+10).
:set number         Show line numbers
:set nonumber       Don’t show line numbers                     :.,.+10s/Banana/Kumquat

:set autoindent  Indent after carriage return               The following example replaces every occurrence
:set noautoindentTurn off autoindent                        (caused by the g at the end of the command) of
:set showmatch   Show matching sets of                      apple with pear.
                 parentheses as they are typed
:set noshowmatch Turn off showmatch                             :%s/apple/pear/g

:set showmode       Display mode on last line of screen     The following example removes the last character from
:set noshowmode     Turn off showmode                       every line in the file. Use it if every line in the file ends
:set all            Show values of all possible             with ^M as the result of a file transfer. Execute it
                    parameters                              when the cursor is on the first line of the file.
                                                                :%s/.$//

More Related Content

What's hot

Vi reference
Vi referenceVi reference
Vi referenceaireddy
 
Mission vim possible-full
Mission vim possible-fullMission vim possible-full
Mission vim possible-fullSam Gottfried
 
Push Down Automata (PDA) | TOC (Theory of Computation) | NPDA | DPDA
Push Down Automata (PDA) | TOC  (Theory of Computation) | NPDA | DPDAPush Down Automata (PDA) | TOC  (Theory of Computation) | NPDA | DPDA
Push Down Automata (PDA) | TOC (Theory of Computation) | NPDA | DPDAAshish Duggal
 
Vim cheat-sheet-en
Vim cheat-sheet-enVim cheat-sheet-en
Vim cheat-sheet-enYue-Peng Guo
 
4 Type conversion functions
4 Type conversion functions4 Type conversion functions
4 Type conversion functionsDocent Education
 
formal definitions in theory of computation
formal definitions in theory of computationformal definitions in theory of computation
formal definitions in theory of computationkanikkk
 

What's hot (8)

Vi reference
Vi referenceVi reference
Vi reference
 
Mission vim possible-full
Mission vim possible-fullMission vim possible-full
Mission vim possible-full
 
push down automata
push down automatapush down automata
push down automata
 
Push Down Automata (PDA) | TOC (Theory of Computation) | NPDA | DPDA
Push Down Automata (PDA) | TOC  (Theory of Computation) | NPDA | DPDAPush Down Automata (PDA) | TOC  (Theory of Computation) | NPDA | DPDA
Push Down Automata (PDA) | TOC (Theory of Computation) | NPDA | DPDA
 
Vim cheat-sheet-en
Vim cheat-sheet-enVim cheat-sheet-en
Vim cheat-sheet-en
 
4 Type conversion functions
4 Type conversion functions4 Type conversion functions
4 Type conversion functions
 
formal definitions in theory of computation
formal definitions in theory of computationformal definitions in theory of computation
formal definitions in theory of computation
 
Pda
PdaPda
Pda
 

Similar to Vi cheat sheet

Similar to Vi cheat sheet (20)

vi cheat sheet
vi cheat sheetvi cheat sheet
vi cheat sheet
 
Vi cheat sheet
Vi cheat sheetVi cheat sheet
Vi cheat sheet
 
Vi cheat sheet
Vi cheat sheetVi cheat sheet
Vi cheat sheet
 
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
 
vim-cheatsheet.pdf
vim-cheatsheet.pdfvim-cheatsheet.pdf
vim-cheatsheet.pdf
 
Vi reference
Vi referenceVi reference
Vi reference
 
Vim Cheat Sheet.pdf
Vim Cheat Sheet.pdfVim Cheat Sheet.pdf
Vim Cheat Sheet.pdf
 
UNIX - Class2 - vi Editor
UNIX - Class2 - vi EditorUNIX - Class2 - vi Editor
UNIX - Class2 - vi Editor
 
Vi editor
Vi editorVi editor
Vi editor
 
vim - Tips and_tricks
vim - Tips and_tricksvim - Tips and_tricks
vim - Tips and_tricks
 
1359 Vi Editor
1359 Vi Editor1359 Vi Editor
1359 Vi Editor
 
GNU Emacs Reference Card.pdf
GNU Emacs Reference Card.pdfGNU Emacs Reference Card.pdf
GNU Emacs Reference Card.pdf
 
015-Editing-Files-With-Vi.pdf
015-Editing-Files-With-Vi.pdf015-Editing-Files-With-Vi.pdf
015-Editing-Files-With-Vi.pdf
 
Vim Cards - Keynote Format
Vim Cards - Keynote FormatVim Cards - Keynote Format
Vim Cards - Keynote Format
 
VI Editors
VI EditorsVI Editors
VI Editors
 
vim
vimvim
vim
 
Vim
VimVim
Vim
 
Emacs Cheat Sheet
Emacs Cheat SheetEmacs Cheat Sheet
Emacs Cheat Sheet
 
Lukáš Šabľa - Vim
Lukáš Šabľa - VimLukáš Šabľa - Vim
Lukáš Šabľa - Vim
 

Recently uploaded

Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 

Recently uploaded (20)

9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 

Vi cheat sheet

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