3

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.

AvantiC
  • 367
  • 3
  • 17
  • Huh, sorry, I forgot to reply on Reddit till now :P Anyway... yeah, I don't get that. Both `:Ack teststring` and `:Ack teststring .` work the same way for me (with `g:ackprg` set to the same thing as yours). Can you try from the command line and see if `ag --vimgrep teststring` and `ag --vimgrep teststring .` do the same thing? – Amadan Nov 17 '16 at 08:04
  • 1
    You got pretty sound advices in that thread. Why in all hell did you chose the plugin way? – romainl Nov 17 '16 at 08:48
  • @romainl Yes I read every comment and I spent yesterday playing around with grep and vimgrep. But also Ran4's comment made sense, that if you have to configure everything yourself you are likely to make mistakes, especially as a beginner (see this thread for example :D). So I'm trying out this now. @Amadan Both of your commands don't seem to do anything for me on the command line. But if I substitute the '.' with a '*' and type `ag --vimgrep teststring *` a search is run. I assume there is something wrong with my configuration? ...which is weird, because it is basically a fresh install :/ – AvantiC Nov 17 '16 at 10:02

1 Answers1

5

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!

AvantiC
  • 367
  • 3
  • 17
  • 2
    Make sure you use capital `-U` and not `-u`, or you will not take advantage of much of ag's file exclusions. I suggest using the synonym `--skip-vcs-ignores` to make it clear what it is you're intending. – Andy Lester Nov 17 '16 at 14:52
  • As an option you can use `ripgrep` instead of `ag`. It works as expected out-of-the-box. `let g:ackprg = 'rg --vimgrep --no-heading'` – Dimko Desu Dec 04 '17 at 12:37