Closed danihodovic closed 7 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.
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!
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.
@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
Thanks @dani-h that makes sense. I'll add an option similar to ag.vim
when I get a chance.
@gabesoft :+1:
Is this feature request still open? It would be very useful to have this feature so it's a +1 for me.
@atropo You might want to look at https://github.com/airblade/vim-rooter
@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.
The vim-rooter plugin does the trick, thanks @danihodovic
Is it possible to search from the root folder in a directory which has a .git folder? Similar to how CtrlP works.