rking / ag.vim

Vim plugin for the_silver_searcher, 'ag', a replacement for the Perl module / CLI script 'ack'
1.74k stars 131 forks source link

How to search within specific subdirectories? #137

Closed airblade closed 8 years ago

airblade commented 8 years ago

I have this bash function to search all the stylesheets in a Rails app:

ags() {
  ag "$@" app/assets/stylesheets/ lib/assets/stylesheets/ vendor/assets/stylesheets/
}

I'd like to replicate that in Vim, i.e. be able to type :Ags TEXT and have the plugin search the three stylesheets directories.

What's the best way to achieve this? With a new command, or a map, or something else?

losingkeys commented 8 years ago

You can use :Ag search-for app/assets/stylesheets/ lib/assets/stylesheets/ vendor/assets/stylesheets/ or (if you want spaces in your search query) :Ag "search for" app/assets/stylesheets/ lib/assets/stylesheets/ vendor/assets/stylesheets/.

This is a pretty thin wrapper around ag, so you even do things like pass in command line options (e.g. :Ag "search for" --literal dir/).

airblade commented 8 years ago

Thanks – however I was after a way to pass all the directories automatically. For example:

:CustomAgCommand search for

– which would then do the equivalent of:

:Ag "search for" app/assets/stylesheets lib/assets/stylesheets vendor/assets/stylesheets

airblade commented 8 years ago

Never mind, this does what I want:

command -nargs=1 Ags Ag <args> app/assets/stylesheets lib/assets/stylesheets vendor/assets/stylesheets
command -nargs=1 Agj Ag <args> app/assets/javascripts lib/assets/javascripts vendor/assets/javascripts