Guia rápida de “vi”

Aqui os pongo una guia hecha en 3 minutos con la fabulosa tecnica denominada Cut&Paste, 3 fabulosos capitulos en los que os podreis adentrar en las maravillas de vi, el editor que usaban nuestros abuelos en aquellos fabulosos ordenadores qeu no tenian display o si lo tenian era de 1 linea. Eso si, ligero como el solo.

Vi: Start-up, Modes, Save and Quit

To enter Vi type:

 vi FILENAME

Vi has two modes: Normal (command) mode and edit mode.

 Switch to normal mode:     <ESC>
 Switch to edit mode:       i or a

Getting out of Vi (change to normal mode <ESC>):

 Exit Vi:                       :q
 Exit Vi (ignore changes):      :q!
 Save:                          :w
 Save and Exit:                 :wq

Switch to (edit) an other file:

:edit FILENAME

Vi: Move, Delete and Paste

Change to normal mode with <ESC>.


Move:

Use either the arrow keys or the hjkl keys:

 h (left)    j (down)    k (up)    l (right) 

 Getlocation and file status:   Ctrl-g  
 Moves to end of the file:      Shift-G  
 Moves line NUMBER:             NUMBER Shift-G  


Delete:

 Delete a character:     x
 Delete a line:          dd

For multiple deletion precede command with a number.

 Delete 5 characters:     5 x
 Delete 7 lines:          7 dd


Paste:

inserts all you deleted with the preceding delete.

 Paste:	                 p 

Vi: Search and Replace

Change to normal mode with <ESC>.

Search (Wraped around at end of file):

  Search STRING forward :   / STRING.
  Search STRING backward:   ? STRING.

  Repeat search:   n
  Repeat search in opposite direction:  N  (SHIFT-n)

Replace: Same as with sed,
Replace OLD with NEW:

 
 First occurrence on current line:      :s/OLD/NEW
  
 Globally (all) on current line:        :s/OLD/NEW/g 

 Between two lines #,#:                 :#,#s/OLD/NEW/g
  
 Every occurrence in file:              :%s/OLD/NEW/g 

This entry was posted in linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *