Thursday, April 16, 2009

VI Cheat Sheet

There are plenty of VI cheatsheets out there, this one is directed at commands that I find handy when editing/seraching logs and config files.

Command Effect
:set ic ignore case while searching
/ search for
:w write out to
:g//s/// global find/replace (replaces with
dd delete line
dw delete word
d) delete rest of sentence
yy yank/copy line
p paste (from copy or delete)
wq save and quit
q! quit without saving
#G go to line #
G go to the last line in a file
:g/^$/d delete empty lines
:g//d delete lines with in them
mx mark beginning of a block "x"
d'x cut from beginning of block "x" to cursor
:%s/find/replace/ replace every occurance of the word "find" with "replace"

If you're scanning through logs with a lot of redundant information in them, it's often handy to use the pattern matching line delete from above, that way you can get rid of a lot of the extra fluff that you're sure you won't need.

No comments:

Post a Comment