September 20, 2011

TODO? vim ♥ ack

One pattern I frequently find myself following is acking for a very specific set of results...

ack -a 'uri_for.*(contact|address|phone)'

Then I launch vim to start editing the files that were matched here...

vim `ack -la 'uri_for.*(contact|address|phone)'`

Then I rewrite the search term using vim's regular expressions instead of Perl's far superior syntax...

/uri_for.*\(contact\|address\|phone\)

Then finally I get along with my editing, using both n and :bn to advance to the each match as needed.

It's generally at the "mentally translate the Perl regex to vim" stage where I just say fuck it and fudge it a little bit. There's gotta be something better here. How do you do this? Do you somehow have an editor that works better for this than mine? Surely there's room enough in this world for an ack + vim lovechild that not only loads the proper files into vim, but also automatically starts you off with the (translated!) regex in your search buffer, cursor already waiting at the first result.

Do I have to write this thing myself?

Update: apparently the answer is no! Thomas Sibley wrote a new tool called viack and I'm happy with how simple it is. \v gives a close enough approximation of Perl regexes.