If you blog it they will come?

Saturday, August 8, 2009

vim zen moment

There comes a certain time in one's life to put aside the variety of editors they might use or sometimes dabble in, and perhaps choose one they like best, or see the most potential with down the road, and work monogamously toward advanced proficiency in this editor, regardless of the bumps in the road or hardships which may provoke longing for other editors along the way.

I've made this commitment to vim recently and I'm still a novice.
But I just had what may be my first true zen moment with the editor!

The problem:
* I needed to fix a single spacing annoyance in a set of over 40 php files.

The solution:
* Open all php files rooted in foo, luckily 90% were all at the same leaf level
vim /foo/*/*/*\.php
* Start recording a macro in register a
qa
* Make edits
[a fair bit of jj and dd and i etc.]
* Write changes
:w
* Open next file
:bn
* Stop recording
q

After pressing @a a few times to execute the macro, or :bn if the file could be left alone, I was done.

I've always wanted to be able to do this sort of thing so easily, but it's elusive or cumbersome with most GUI editors. Many UNIX text munging tools exist too, but it's often easier to take direct route of showing the machine what you want, rather than, say, building a DFA.

So, I'm liking the taste of vim kool-aid thus far.

No comments: