Vim Cheat Sheet

These are notes I’m taking as I play vim golf; this is meant to be useful to me, maybe not you

  • Record a macro:  q<letter> <do stuff> q
    • playback that macro @<letter>
  • :set number (show lines numbers)
  • :g/<searchString>/norm <vimcommands>  (search for searchstring and run vim commands)
  • :g/<searchString>/<ex command>  (d delete) (multiple ex commands sep by | )
  • <ctrl-r> = <MATH EXPRESION> (while in insert mode does math and prints answer)
  • <ctrl-r> % (insert the file name)
  • <ctrl-r> = “\escapecode \x73\x75\x70\x65″  (will un-escape the escape codes)
  • * (jump to the next occurrence of the word you are currently on top of)
  • %s//<replace>  (replace your last search with <replace>)
  • *%s//<replace>  (replace all occurrences of what is under your cursor with <replace>)
  • Replace all tabs with 2 spaces : :set et ts=2<CR>:ret<CR>
  • ctrl-v : visual “block”  select a box (not entire lines)
  • f <char>  : jump to next <char>
  • v (enter visual mode) <select>  then :s/search/replace  (replace in visual selection)

Leave a Reply

Your email address will not be published. Required fields are marked *

*


eight × 1 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>