Open to line in vim from grep results

2016-07-20

I often find myself doing greps thrughout different codebases to find variables that I want to change. For example:
    Element.php:497:            case \ast\flags\UNARY_BOOL_NOT:
    Element.php:727:            case \ast\flags\UNARY_BOOL_NOT:

These results are sometimes buried in large files, and it's a pain to open them up in vim and have to search again for the variable I want to change. Wouldn't it be great if I could just use vim to open the grep formatted file:line format? Well, you can! Check it out.

Here's how to get this set up. First, since I mostly find myself using git-grep these days I needed to enable line numbers in my .gitconfig. You can do that with a config stanza:

[grep]
    linenumber = true

Next you'll want to install the file:line vim plugin. Install using your preferred method, there's nothing fancy here.

Now you're done! Enjoy opening grep results in vim and jumping directly to the correct line. Thanks to Chuck Ha for pointing me to this originally.