Git a Grep on Vim

UPDATECombination of .gitignore and .agignore will do just fine (though it falls short on subdirectory specific ignores). So ignore the rest of this post.

I’ve been a happy user of ag.vim for years until recently I started to work on a phonegap project. Two things are special about it:

./node_modules

compiled source files

Both of these are included when grepping the project and, man, this is annoying. And slow.

So today I’ve had enough and decided to do something. Surprisingly, quick googling didn’t reveal anything I could just copypaste somewhere, so I had to put on my bash pyjamas and sort this out like a pro.

I’ve heard of git-grep and the plan was to bolt it in instead of a stock ag, but only if current vim folder is a git project (or a subfolder of one). This way none of the aformentioned types of files will be included in the search.