You are on page 1of 1

vi basic commands

Summary of most useful commands


Copyright 2006-2005, Free Electrons, http: free-electrons!com! "atest update: Sep #5, 200$ Free to share under the terms of the Creati%e Commons &ttri'ution-Share&li(e 2!5 license )http: creati%ecommons!org licenses 'y-sa 2!5 * Sources, translations and updates on our free training materials: http: free-electrons!com training intro+uni,+linu, -han(s to: "iu'o Chen!

x dw D dd .

delete the character at the cursor location! delete the current word! delete the remainder of the line after the cursor! delete the current line! repeat the last insertion, replacement or delete command!

Repeating commands Looking for strings


/string find the first occurrence of string after the cursor! ?string find the first occurrence of string 'efore the cursor! n find the ne,t occurrence in the last search!

Entering command mode


[Esc] E,it editing mode! .ey'oard (eys no/ interpreted as commands!

Moving the cursor


h )or left arro/ (ey* mo%e the cursor left! l )or right arro/ (ey* mo%e the cursor right! j )or do/n arro/ (ey* mo%e the cursor do/n! k )or up arro/ (ey* mo%e the cursor up! [Ctrl] f mo%e the cursor one page for/ard ! [Ctrl] b mo%e the cursor one page bac(/ard! ^ mo%e cursor to the first non-/hite character in the current line! $ mo%e the cursor to the end of the current line! G go to the last line in the file! nG go to line num'er n! [Ctrl] G display the name of the current file and the cursor position in it!

Replacing strings
Can also 'e done manually, searching and replacing once, and then using n )ne,t occurrence* and . )repeat last edit*! n,ps/str1/str2/g 'et/een line num'ers n and p, su'stitute all )g: glo'al* occurrences of str1 'y str2! 1,$s/str1/str2/g in the /hole file )0: last line*, su'stitute all occurrences of str1 'y str2!

Applying a command several times - E amples


5j 30dd 4cw 1G mo%e the cursor 5 lines do/n! delete 10 lines! change 2 words from the cursor! go to the first line in the file!

Entering editing mode


i a o O r s cw C yy p P insert ne/ te,t 'efore the cursor! append ne/ te,t after the cursor! start to edit a ne/ line after the current one! start to edit a ne/ line 'efore the current one! replace the current character )does not enter edit mode*! enter edit mode and su'stitute the current character 'y se%eral ones! enter edit mode and change the word after the cursor! enter edit mode and change the rest of the line after the cursor! copy )yan(* the current line to the copy paste 'uffer! paste the copy paste 'uffer after the current line! Paste the copy paste 'uffer 'efore the current line!

Misc
[Ctrl] l redra/ the screen! J join the current line /ith the ne,t one

Replacing characters, lines and words

E iting and saving


ZZ :w :w file :q! sa%e current file and e,it %i! write )sa%e* to the current file! write )sa%e* to the file file! quit %i /ithout sa%ing changes!

Copying and pasting

!oing further
vi has much more fle,i'ility and many more commands for po/er users3 4t can ma(e you e,tremely producti%e in editing and creating te,t! "earn more 'y ta(ing the 5uic( tutorial: 6ust type vimtutor! Find many more resources on the net3

Deleting characters, words and lines


&ll deleted characters, /ords and lines are copied to the copy paste 'uffer!

You might also like