Saturday, January 19, 2013

Practical vi Techniques

Although many places have iterated vi common commands, one may still come across with obstacles to maneuver comfortably.
The following is an ongoing list which I consider be worth recording and practicing.
  • Syntax Highlight (update your vim if this is not installed as default):
    sudo apt-get install vim
    :syntax on, :syntax off
    
  • Undo (one can undo multiple steps with the newer version)
    u
  • Replace (refer advanced regex skills):
    :s/foo/bar/g
  • Search by keyword
    /keyword
  • Go to the first line, last line, head of line, end of line
    1G, G, 0, shift+4
    
  • Backward or forward by one word
    b, e
  • Go to line n
    :n
  • New line with input mode (on next line, on previous line)
    o, shift+o
  • Multiple lines cut-and-paste, copy-and-paste
    ndd+p, nyy+p
    
  • Copy-and-paste from clipboard (using the shortcut of terminal window)
    ctrl+shift+c, ctrl+shift+v
  • Set line number and unset
    :set nu, :set nu!
  • Save the file often, override even when complaining read-only permission
    :w, :w!

No comments:

Post a Comment