You are on page 1of 1

vi basic commands

Summary of most useful commands


Copyright 2013-2005, Free Electrons, http !!free-electrons"com" #atest update $ar 2%, 201& Free to share under the terms of the Creati'e Commons (ttri)ution-Share(li*e 3"0 license" Sources, translations and updates on our free training materials http !!free-electrons"com!training!intro+uni,+linu," -han*s to #iu)o Chen"

dw D dd .

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 2nd the 2rst occurrence of string after the cursor. ?string 2nd the 2rst occurrence of string )efore the cursor" n 2nd 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 0or left arro/ *ey1 mo'e the cursor left" l 0or right arro/ *ey1 mo'e the cursor right" j 0or do/n arro/ *ey1 mo'e the cursor do/n" k 0or up arro/ *ey1 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 2rst 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 2le" nG go to line num)er n. [Ctrl] G display the name of the current 2le and the cursor position in it"

Replacing strings
Can also )e done manually, searching and replacing once, and then using n 0ne,t occurrence1 and . 0repeat last edit1" n,ps/str1/str2/g )et/een line num)ers n and p, su)stitute all 0g glo)al1 occurrences of str1 )y str2" 1,$s/str1/str2/g in the /hole 2le 04 last line1, 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 30 lines" change & words from the cursor" go to the 2rst line in the 2le"

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 0does not enter edit mode1" 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 0yan*1 the current line to the copy!paste )u3er" paste the copy!paste )u3er after the current line" Paste the copy!paste )u3er )efore the current line"

Misc
[Ctrl] l redra/ the screen" J join the current line /ith the ne,t one u undo the last action

Replacing characters, lines and words

E iting and saving


ZZ :w :w file :q! sa'e current 2le and e,it 'i" write 0sa'e1 to the current 2le" write 0sa'e1 to the file 2le" quit 'i /ithout sa'ing changes"

Copying and pasting

!oing further
vi has much more 5e,i)ility and many more commands for po/er users6 7t can ma*e you e,tremely producti'e in editing and creating te,t" #earn more )y ta*ing the 8uic* tutorial 9ust type vimtutor"

Deleting characters, words and lines


(ll deleted characters, /ords and lines are copied to the copy!paste )u3er" x delete the character at the cursor location"

You might also like