gabesoft / vim-ags

Silver searcher plugin for vim
183 stars 12 forks source link

Searching from git root #21

Closed danihodovic closed 7 years ago

danihodovic commented 9 years ago

Is it possible to search from the root folder in a directory which has a .git folder? Similar to how CtrlP works.

gabesoft commented 9 years ago

Currently that's not the case by default. But, you can specify the directory in the command as the last parameter like so :Ags search-term /my/root/dir. You would have to enter the full path, for example ~/my/dir would not work.

danihodovic commented 9 years ago

I'm not a vimscript wizard but this seems to be working for me. It searches within a git repo regardless of where your :pwd is.

nnoremap <leader>ag :AgsWrapper
command! -nargs=* -complete=file AgsWrapper    call AgsWrapper(<q-args>, '')
" This function wraps :Ags with by providing the git root folder if inside a git repo.
" It also uses -t for ag which seraches inside .gitignore folders
function! AgsWrapper(args, cmd)
  let root = systemlist('git rev-parse --show-toplevel')[0]
  " If not in a git repo, search from here
  if v:shell_error > 0
    execute 'Ags' a:args
  else
    execute 'Ags' a:args l:root '-t'
  endif
endfu!
gabesoft commented 9 years ago

Yes I think that will work. But, I'm not sure it should be part of the plugin as it could confuse some people if they are expecting to search within a particular directory. On the other hand I could add it and put it behind an option maybe disabled by default.

danihodovic commented 9 years ago

@gabesoft I don't think so either. I was mostly posting in case someone else runs into the same issue and searches the issues.

I do however think it would be nice to expose an option to do this as per https://github.com/rking/ag.vim#configuration

gabesoft commented 9 years ago

Thanks @dani-h that makes sense. I'll add an option similar to ag.vim when I get a chance.

danihodovic commented 9 years ago

@gabesoft :+1:

atropo commented 8 years ago

Is this feature request still open? It would be very useful to have this feature so it's a +1 for me.

danihodovic commented 8 years ago

@atropo You might want to look at https://github.com/airblade/vim-rooter

gabesoft commented 8 years ago

@atropo yes this is still open. I haven't had a chance to work on it. But, it's on my list as soon as other stuff clears up.

atropo commented 8 years ago

The vim-rooter plugin does the trick, thanks @danihodovic