Tuesday, July 30, 2013

Vi Editor basic user guide

vi is a screen-oriented text editor originally created for the Unix operating system.
Here are the few basic and necessary shortcuts to use vi editor effectively-
  • '0'(zero) -move cursor to start of current line
  • ':n' -move cursor to line n
  • ':$' -move cursor to last line in file
  • 'x' -delete single character under cursor
  • 'dd' -delete entire current line
  • 'dw' -delete the single word beginning with character under cursor
  • 'yy' -copy (yank, cut) the current line into the buffer
  • 'Nyy' -copy (yank, cut) the next N lines, including the current line, into the buffer
  • 'p' -put (paste) the line(s) in the buffer into the text after the current line
  • '/string' -search forward for occurrence of string in text
  • '?string' -search backward 
  • 'n'  -move to next occurrence of search string
  • 'N'  -search for previous occurrence 
  • 'u' -Undo last change
  • 'ctrl + r'  - Redo 
  • ':s/OLD/NEW/g'  -Replace OLD with NEW Globally (all) on current line
  • ':%s/OLD/NEW/g'   -Replace OLD with NEW Every occurrence in file

1 comment: