Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Searching from git root #21

Closed
danihodovic opened this issue Nov 11, 2015 · 10 comments
Closed

Searching from git root #21

danihodovic opened this issue Nov 11, 2015 · 10 comments

Comments

@danihodovic
Copy link

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

@gabesoft
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

@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
Copy link
Owner

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

@danihodovic
Copy link
Author

@gabesoft 👍

@atropo
Copy link

atropo commented Jan 14, 2016

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

@danihodovic
Copy link
Author

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

@gabesoft
Copy link
Owner

@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
Copy link

atropo commented Oct 14, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants