Friday, March 11, 2011

Vim Tips

  • To beautify code (or pretty print, or auto indent), type ESC gg = SHIFT-G. This means:
    • ESC --> back to mode
    • gg --> go to first line
    • = --> indenting
    • SHIFT G --> to end of file.
(Courtesy snipplr.)
  •  To search and replace starting from the cursor type ESC :.,$s/foo/bar/gc. This means:
    • ESC --> back to mode
    • : --> command mode
    • .,$ --> from current line (.) till (,) end of file ($)
    • s --> substitute (foo with bar)
    • g --> all occurrences in a line
    • c --> confirm before replacing
 (Courtesy wikia.)

No comments:

Post a Comment