Some of the most useful vi commands:

  • Insert (key) …edit mode
  • Esc (key) …exit edit mode
  • :wq or ZZ …save and exit vi (must not be in edit mode)
  • :q! …exit vi without saving (must not be in edit mode)
  • :w myfilename …save vi editor buffer to new file (must not be in edit mode)
  • yy or Y …copy a line to buffer
  • p or P …paste a line from buffer
  • i …insert single character at cursor (Esc to exit edit mode)
  • r …replace single character at cursor (Esc to exit edit mode)
  • x …delete single character at cursor (Esc to exit edit mode)
  • :sh …to switch to shell mode (use Ctrl + d to return to vi)
  • :set number/nonumber …will turn line-numbers on or off

searching text (not in edit mode):

  • /nas …will search forward for any string ‘nas’
  • ?nas …will search backward for any string ‘nas’
  • n …will go to the next found string
  • :nohlsearch …will turn-off highlight search results

copy-paste from windows to vi:

  1. ctrl + v (copy text from source in windows)
  2. :sh …to switch to shell mode
  3. cat > output + r-click (to paste what copied from windows)
  4. r: ! + r-click (from within vi)

for more commands see source at www.colorado.edu