Search code examples
vimackag

Ack.vim with ag not using current directory?


I am at the moment trying to figure out vim and craft my own .vimrc.

After some research about search-commands and plugins I decided to follow the advice of someone and try out Ack.vim with SilverSearcher/Ag for the actual searches. I encountered some problems though, but let me start from the beginning:

When I first installed Ack and tested the "native" Ack via:

:Ack teststring

everything worked fine and I got the results in the quickfix-window.

I then proceeded to install SilverSearcher and added the following to my vimrc:

if executable('ag')
  let g:ackprg = 'ag --vimgrep'
endif

...and now when I do the same command as above the search doesn't work anymore. Instead I immediately get an empty quickfix-window and nothing else happens.

However, if I add a directory to the command, e.g.

:Ack teststring mysubdirectory/

the search works.

This confused me. Shouldn't it default to the current directory if none is specified? At least that's how I understand the documentation and that's how it seems to work for the "native" as well. But as soon as I add the ag-part to my .vimrc it's not anymore.

Can anyone give me a hint at what I am missing here?

PS: In case this is important: I'm on OSX ElCapitan using the terminal-version of VIM8 in iterm2.


Solution

  • Ok, I found the problem.

    Apparently we have a .gitignore in our project where my co-workers first excluded ALL files and then went to include specific files using "!".

    As I learned now, SilverSearcher doesn't handle this to well, see here.

    When I use the command with the -U option everything works as intended.

    Thanks for helping though!