vi Commands

Editing
   
Undo last edit:
 
u
Editing between files
   
open another file:
 
:e
switch to another file:
 
:e #
copy 4 lines into f buffer:
 
“f4yy
paste from f buffer:
 
“fp
Open/Save File:
   
Open file and go to pattern:
  vi +/pattern
redraw screen:
 
ctrl L
revert to last save:
 
:e!
Exit without save:
 
:q!
Search string:
   
search forward:
  /string
search backward:
  ?string
go to beginning of doc:
  1 Shft G
String Replacement:
   
replace 1st occurance:
 
:s/old/new
replace all in current line:
 
:s/old/new/g
global replacement:
 
:%s/editer/editor/g
Remove all ^M:
 
:%s/Ctrl V Ctrl M//g
repeat last substitution:
  :s
Change Cases:
   
Ignore case:
  :set ic
Do not ignore case:
  :set noic
change case:
  ~
Others:
   
Turn vim color off
  :syn off
Delete to the end of file
  dG

References

* A good vi commands page
* Mastering the VI editor
* vi cheat sheet

This entry was posted in vi and tagged , , . Bookmark the permalink.