SlideShare a Scribd company logo
1 of 1
Download to read offline
Vi Reference Card                                             Yanking text                                                  Regular expressions
                                                              Like deletion, almost all yank commands are performed by      any single character except newline              . (dot)
                                                              typing y followed by a motion. For example y$ yanks to        zero or more repeats                                      *
Modes                                                         the end of line. Two other yank commands are:                 any character in set                              [...]
Vi has two modes: insertion mode, and command mode.                                                                         any character not in set                        [^ ...]
The editor begins in command mode, where cursor move-         line                                                    yy
                                                                                                                            beginning, end of line                            ^ , $
ment and text deletion and pasting occur. Insertion mode      line                                                    :y
                                                                                                                            beginning, end of word                          < , >
begins upon entering an insertion or change command.                                                                        grouping                                         (. . . )
[ESC] returns the editor to command mode (where you can       Changing text                                                 contents of n th grouping                               n
quit, for example by typing :q!). Most commands execute       The change command is a deletion command that leaves
as soon as you type them except for “colon” commands          the editor in insert mode. It is performed by typing c fol-
which execute when you press the return key.                  lowed by a motion. For example cw changes a word. A few
                                                                                                                            Counts
                                                                                                                            Nearly every command may be preceded by a number that
                                                              other change commands are:
                                                                                                                            specifies how many times it is to be performed. For exam-
Quitting                                                      to end of line                                           C    ple 5dw will delete 5 words and 3fe will move the cursor
exit, saving changes                                   :x     line                                                    cc    forward to the 3rd occurance of the letter e. Even inser-
quit (unless changes)                                  :q                                                                   tions may be repeated conveniently with this method, say
quit (force, even if unsaved)                         :q!     Putting text                                                  to insert the same line 100 times.
                                                              put after position or after line                         p
Inserting text                                                put before position or before line                       P    Ranges
insert before cursor, before line                 i   ,   I                                                                 Ranges may precede most “colon” commands and cause
append after cursor, after line                   a   ,   A   Registers                                                     them to be executed on a line or lines. For example :3,7d
open new line after, line before                  o   ,   O   Named registers may be specified before any deletion,          would delete lines 3−7. Ranges are commonly combined
replace one char, many chars                      r   ,   R   change, yank, or put command. The general prefix has           with the :s command to perform a replacement on several
                                                              the form "c where c may be any lower case letter. For         lines, as with :.,$s/pattern/string/g to make a replace-
Motion                                                        example, "adw deletes a word into register a. It may there-   ment from the current line to the end of the file.
left, down, up, right                     h , j , k , l       after be put back into the text with an appropriate put
next word, blank delimited word                    w , W                                                                    lines n-m                                          :n ,m
                                                              command, for example "ap.                                     current line                                          :.
beginning of word, of blank delimited word         b , B
end of word, of blank delimited word               e , E                                                                    last line                                             :$
                                                              Markers                                                       marker c                                            :’c
sentence back, forward                             ( , )      Named markers may be set on any line of a file. Any lower
paragraph back, forward                            { , }                                                                    all lines                                             :%
                                                              case letter may be a marker name. Markers may also be         all matching lines                          :g/pattern /
beginning, end of line                             0 , $      used as the limits for ranges.
beginning, end of file                            1G , G
line n                                         n G or :n      set marker c on this line                               mc    Files
forward, back to char c                        fc , Fc        goto marker c                                           ‘c    write file (current file if no name given)        :w file
forward, back to before char c                 tc , Tc        goto marker c first non-blank                            ’c    append file (current file if no name given)     :w >>file
top, middle, bottom of screen                 H , M , L                                                                     read file after line                             :r file
                                                              Search for strings                                            read program output                         :r !program
Deleting text                                                 search forward                                    /string     next file                                             :n
Almost all deletion commands are performed by typing d        search backward                                   ?string     previous file                                         :p
followed by a motion. For example dw deletes a word. A        repeat search in same, reverse direction            n , N     edit new file                                    :e file
few other deletions are:                                                                                                    replace line with program output             :.!program

character to right, left
                                                              Replace
                                                  x , X       The search and replace function is accomplished with the      Other
to end of line                                        D       :s command. It is commonly used in combination with           toggle upper/lower case                                ~
line                                                 dd       ranges or the :g command (below).                             join lines                                             J
line                                                 :d                                                                     repeat last text-changing command                      .
                                                              replace pattern with string :s/pattern /string /flags         undo last change, all changes on line              u , U
                                                              flags: all on each line, confirm each             g , c
                                                              repeat last :s command                              &




c 2002 Donald J. Bindner – licensed under the terms of the GNU Free Documentation License version 1.1 or later.

More Related Content

What's hot

Ruby_Coding_Convention
Ruby_Coding_ConventionRuby_Coding_Convention
Ruby_Coding_Convention
Jesse Cai
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
heoff
 
Killian Vigna Morse code
Killian Vigna Morse codeKillian Vigna Morse code
Killian Vigna Morse code
Killian Vigna
 
Doscommands
DoscommandsDoscommands
Doscommands
Durgule
 

What's hot (15)

Awk essentials
Awk essentialsAwk essentials
Awk essentials
 
Beginning with vi text editor
Beginning with vi text editorBeginning with vi text editor
Beginning with vi text editor
 
Ruby_Coding_Convention
Ruby_Coding_ConventionRuby_Coding_Convention
Ruby_Coding_Convention
 
Shell quick reference
Shell quick referenceShell quick reference
Shell quick reference
 
C# Basics Quick Reference Sheet
C# Basics Quick Reference SheetC# Basics Quick Reference Sheet
C# Basics Quick Reference Sheet
 
14 ruby strings
14 ruby strings14 ruby strings
14 ruby strings
 
strings
stringsstrings
strings
 
Characters formats &amp; strimgs
Characters formats  &amp; strimgsCharacters formats  &amp; strimgs
Characters formats &amp; strimgs
 
Licão 07 operating the shell
Licão 07 operating the shellLicão 07 operating the shell
Licão 07 operating the shell
 
String (Computer programming and utilization)
String (Computer programming and utilization)String (Computer programming and utilization)
String (Computer programming and utilization)
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
 
perltut
perltutperltut
perltut
 
Unix
UnixUnix
Unix
 
Killian Vigna Morse code
Killian Vigna Morse codeKillian Vigna Morse code
Killian Vigna Morse code
 
Doscommands
DoscommandsDoscommands
Doscommands
 

Similar to Vi CheatSheet

VI Editors
VI EditorsVI Editors
VI Editors
Deivanai
 
Lukáš Šabľa - Vim
Lukáš Šabľa - VimLukáš Šabľa - Vim
Lukáš Šabľa - Vim
webelement
 
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
Rohit Kumar
 

Similar to Vi CheatSheet (20)

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
 
vim-cheatsheet.pdf
vim-cheatsheet.pdfvim-cheatsheet.pdf
vim-cheatsheet.pdf
 
Vi help-sheet-011
Vi help-sheet-011Vi help-sheet-011
Vi help-sheet-011
 
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 editor commands
Vi editor commandsVi editor commands
Vi editor commands
 
VI Editors
VI EditorsVI Editors
VI Editors
 
Vi cheat sheet
Vi cheat sheetVi cheat sheet
Vi cheat sheet
 
Vi cheat sheet
Vi cheat sheetVi cheat sheet
Vi cheat sheet
 
Lukáš Šabľa - Vim
Lukáš Šabľa - VimLukáš Šabľa - Vim
Lukáš Šabľa - Vim
 
changing and deleting text ,change word and line under vi editor
changing and deleting text ,change word and line under vi editorchanging and deleting text ,change word and line under vi editor
changing and deleting text ,change word and line under vi editor
 
Awk --- A Pattern Scanning And Processing Language (Second Edition)
Awk --- A Pattern Scanning And Processing Language (Second Edition)Awk --- A Pattern Scanning And Processing Language (Second Edition)
Awk --- A Pattern Scanning And Processing Language (Second Edition)
 
VIM for (PHP) Programmers
VIM for (PHP) ProgrammersVIM for (PHP) Programmers
VIM for (PHP) Programmers
 
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
 
Vi Cheat Sheet v 1 00
Vi Cheat Sheet v 1 00Vi Cheat Sheet v 1 00
Vi Cheat Sheet v 1 00
 
Lecture 05 2017
Lecture 05 2017Lecture 05 2017
Lecture 05 2017
 
vim - Tips and_tricks
vim - Tips and_tricksvim - Tips and_tricks
vim - Tips and_tricks
 

Vi CheatSheet

  • 1. Vi Reference Card Yanking text Regular expressions Like deletion, almost all yank commands are performed by any single character except newline . (dot) typing y followed by a motion. For example y$ yanks to zero or more repeats * Modes the end of line. Two other yank commands are: any character in set [...] Vi has two modes: insertion mode, and command mode. any character not in set [^ ...] The editor begins in command mode, where cursor move- line yy beginning, end of line ^ , $ ment and text deletion and pasting occur. Insertion mode line :y beginning, end of word < , > begins upon entering an insertion or change command. grouping (. . . ) [ESC] returns the editor to command mode (where you can Changing text contents of n th grouping n quit, for example by typing :q!). Most commands execute The change command is a deletion command that leaves as soon as you type them except for “colon” commands the editor in insert mode. It is performed by typing c fol- which execute when you press the return key. lowed by a motion. For example cw changes a word. A few Counts Nearly every command may be preceded by a number that other change commands are: specifies how many times it is to be performed. For exam- Quitting to end of line C ple 5dw will delete 5 words and 3fe will move the cursor exit, saving changes :x line cc forward to the 3rd occurance of the letter e. Even inser- quit (unless changes) :q tions may be repeated conveniently with this method, say quit (force, even if unsaved) :q! Putting text to insert the same line 100 times. put after position or after line p Inserting text put before position or before line P Ranges insert before cursor, before line i , I Ranges may precede most “colon” commands and cause append after cursor, after line a , A Registers them to be executed on a line or lines. For example :3,7d open new line after, line before o , O Named registers may be specified before any deletion, would delete lines 3−7. Ranges are commonly combined replace one char, many chars r , R change, yank, or put command. The general prefix has with the :s command to perform a replacement on several the form "c where c may be any lower case letter. For lines, as with :.,$s/pattern/string/g to make a replace- Motion example, "adw deletes a word into register a. It may there- ment from the current line to the end of the file. left, down, up, right h , j , k , l after be put back into the text with an appropriate put next word, blank delimited word w , W lines n-m :n ,m command, for example "ap. current line :. beginning of word, of blank delimited word b , B end of word, of blank delimited word e , E last line :$ Markers marker c :’c sentence back, forward ( , ) Named markers may be set on any line of a file. Any lower paragraph back, forward { , } all lines :% case letter may be a marker name. Markers may also be all matching lines :g/pattern / beginning, end of line 0 , $ used as the limits for ranges. beginning, end of file 1G , G line n n G or :n set marker c on this line mc Files forward, back to char c fc , Fc goto marker c ‘c write file (current file if no name given) :w file forward, back to before char c tc , Tc goto marker c first non-blank ’c append file (current file if no name given) :w >>file top, middle, bottom of screen H , M , L read file after line :r file Search for strings read program output :r !program Deleting text search forward /string next file :n Almost all deletion commands are performed by typing d search backward ?string previous file :p followed by a motion. For example dw deletes a word. A repeat search in same, reverse direction n , N edit new file :e file few other deletions are: replace line with program output :.!program character to right, left Replace x , X The search and replace function is accomplished with the Other to end of line D :s command. It is commonly used in combination with toggle upper/lower case ~ line dd ranges or the :g command (below). join lines J line :d repeat last text-changing command . replace pattern with string :s/pattern /string /flags undo last change, all changes on line u , U flags: all on each line, confirm each g , c repeat last :s command & c 2002 Donald J. Bindner – licensed under the terms of the GNU Free Documentation License version 1.1 or later.