Vous êtes sur la page 1sur 1

some usefull tips and command for the vi editor

vi help sheet versionof 29th Oct.2006

You  have  to  use  ESC  (escape  key)  to  get  into  the  vi  command  mode.  You  will  need  to  press  RETURN  Key  for  executing  a  command 
starting with the ponctuation character « : » or « / » or « ? ». Use CTRL+c for cancel a command. Use « . » for repeat your last 
command and « :!cmd » for execute a shell command (where cmd is the command to execute).

to get into insert mode file commands search commands

i insert text before the cursor :q quit current open file /string search forward for « string »


a append text after the cursor :q! force to quit (without  ?string search backward for « string »
saving  open file) n repeat last search
I insert text at the beginning  :w save file
of the current line :,$s/str1/str2/gc search and replace « str1 » by « str2 » 
:w file save file as « name » from the current line (a line number 
A append text at the end of the  :wq! overwrite file then quit can be specified before the comma) to 
current line the end of file. Ask for confirmation 
:x,yw file write from line « x » to  before replace.
o insert text in a new line  line « y » into « file »
below the cursor :%s/str1/str2/g replace all « str1 » by « str2 » in all 
:w >> file append buffer to « file » the file without confirmation.
O insert text in a new line  :e file edit another file :%s/str1/str2/ replace « str1 » by « str2 » for first 
below the cursor occurrence of each line of file.
:e! file edit another file without 
saving the current open 
navigation commands file edit commands
:r file insert file content at 
move cursor left the current cursor  r replace a character at the cursor position
h or  position u undo last change
l or  move cursor right :n edit next file in vi  mA set mark « A » (can be any letter, case 
k or  move cursor up  arguments file list sensitive) at the beginning of current line
y'A yank from current line to the mark « A »
j or  move cursor down  ctrl+G get file status
d'A delete from current line to the mark « A »
G goto the end of file P (caps P) put the buffer before the cursor
nG or :n goto the line number « n » You can launch vi with some arguments.  p (small p) put the buffer after the cursor
One  usefull  is  « ­c »  for  execute  vi 
0 move to the beginning of line commands  in  a  file  directly  from  the  x delete character at cursor position
command line. dw delete first word after cursor position
$ move to the end of line delete from cursor position to the end of line
d$ or D
ctrl+f move one screen forward ex.: delete curent line
vi ­c « %s/false/true/g|:wq » file.txt dd
ctrl+b move one screen backward J (caps J) join curent line with the following line
Look at :
:map for mapping a key in command mode to a group of commands (ex. :map de :,$d^M will delete all file when using de command)
:set for define or show your editor current options
:ab for define a text abreviation in insert mode (ex. :ab VIM Vi Improved will auto complete VIM in insert mode)

Shell-Tips.com vi help sheet Author : Nicolas Brousse

Vous aimerez peut-être aussi