Welcome back for another episode of the ABC's of NSM.  What's NSM you say?  We'll go with Network and System Management, but you abc_2_4 could throw Security in there as well.  We'll work our way through the alphabet over  the next several weeks looking at  tools and concepts along the way for all the administrators out there.   By the way, you can thank Joe for the format & Don for the title  (I  couldn't for the life of me come up with one.)

Today's letter V is for Vim. Vim is a cross-platform console and GUI text editor that is backwards compatible with the unix shell vi, from which it gets its name (Vi Improved).  There are an abundance of features in Vim that are not in vi, but mostly I like Vim for the syntax highlighting and the unlimited undo.  Other than that, Vim or vi, doesn't much matter to me--as long as one is available.  There is a learning curve with vi, but like any good tool, whole new worlds open up to you once you are comfortable with the basics.  Besides, editing text in vi is just plain fun.  And I'm always learning something new.  Just yesterday I was trying to find all occurrences of a string that started and ended the same but had two characters that changed (representing an object type).  I knew already how to find this string: hash_..0019.  What I didn't know how to do was to avoid changing the two unique characters in the middle of the string when I did the global replace.  Enter grouping.  By grouping parts of the string in your search parameters, you can then print the desired group as is and just change the necessary part:

Original Strings: hash_010019, hash_050019, hash_090019, hash_100019

Final String: hash_010014, hash050014, hash_090014, hash_100014

Vi Command: :%s/\(hash_..\)\(0019\)/\10014/g

Breaking that down, we have:


The search string is broken in two groups: hash_.. & 0019 (The parentheses are escaped)

The replace string is \1 for the first group, and then I want the 0019 replaced with 0014.

Vi is cool, isn't it?


Follow me on Twitter Follow me on LinkedIn Follow me on Facebook Add to Technorati Favorites