0

I'd like to just use the :Ag command to enter the interactive ag shell (as with :Files) and then start typing my search term.

However, vim won't allow me to open the ag interactive interface. If I type :Ag, it will complain with the following error:

E471: Argument required

If I write the search term (like :Ag something) it opens a new pane with the results. But that's not what I want: I want to use ag the same way as the :Files command.

More info

I'm using thoughtbot/dotfiles.

Definition of :Ag command

:verbose command Ag

    Name              Args Address Complete    Definition
|   Ag                +            file        silent! grep! <args>|cwindow|redraw!

Settings

This is the portion of my .vimrc file where ag is enabled.

" Use The Silver Searcher https://github.com/ggreer/the_silver_searcher
if executable('ag')
  " Use Ag over Grep
  set grepprg=ag\ --nogroup\ --nocolor

  " Use ag in fzf for listing files. Lightning fast and respects .gitignore
  let $FZF_DEFAULT_COMMAND = 'ag --literal --files-with-matches --nocolor --hidden -g ""'

  if !exists(":Ag")
    command -nargs=+ -complete=file -bar Ag silent! grep! <args>|cwindow|redraw!
    nnoremap \ :Ag<SPACE>
  endif
endif
Kurt Bourbaki
  • 11,984
  • 6
  • 35
  • 53
  • "I'm using thoughtbot/dotfiles." That is the cause of your problem. It is not your config so you don't know what is going on in it and when things break you don't know how to fix them. Anyway, what does `:verbose command Ag` say? – romainl Jan 01 '21 at 21:26
  • @romainl I've added the output of `:verbose command Ag` to the question above – Kurt Bourbaki Jan 01 '21 at 21:40
  • 1. That vimrc is not *your* vimrc. 2. That command is a makeshift `:Ag` added to that file by its maintainer, that requires arguments and doesn't involve fzf at all. I would expect fzf to override that command, though. – romainl Jan 01 '21 at 23:36
  • @romainl Do you have any suggestions to use `ag` in a window (simlar to CtrlP)? – Kurt Bourbaki Jan 02 '21 at 10:19
  • As I said, assuming you have a working `:Files` [provided by fzf](https://github.com/junegunn/fzf.vim/blob/master/plugin/fzf.vim#L61), I would expect fzf to define [its own `:Ag`](https://github.com/junegunn/fzf.vim/blob/master/plugin/fzf.vim#L69). If it doesn't, then there must be a problem somewhere and that ready-made config you got from the web doesn't make it easy to find out where. Maybe fzf is not correctly installed? Maybe it is something else? – romainl Jan 02 '21 at 12:39

1 Answers1

0

This portion of the .vimrc (by thoughtbot/dotfiles) was overriding the default behaviour set by fzf.vim:

if !exists(":Ag")
  command -nargs=+ -complete=file -bar Ag silent! grep! <args>|cwindow|redraw!
  nnoremap \ :Ag<SPACE>
endif

I just commented it out and things are now working as I wanted. Thanks to @romainl for giving some useful hints.

Kurt Bourbaki
  • 11,984
  • 6
  • 35
  • 53