I am new to vim. I read online that one of the best fuzzy finder in vim is fzf. I have started using it. But whenever I write the command :Ag I get ag is not found. I don't know what it means and I don't know how to fix it.
- 19,824
 - 17
 - 99
 - 186
 
- 5,834
 - 16
 - 69
 - 109
 
3 Answers
You need to install ag, in case you are on a mac:
brew install the_silver_searcher
As another option for testing fzf you could also use ctrl p to call :Files by using this map:
nnoremap <c-p> :Files<CR>
And you could  use ripgrep when calling :Files, for this you will need to modify the default FZF_DEFAULT_COMMAND:
export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow --glob "!.git/*"'
You can find more information here: https://github.com/junegunn/fzf#usage
- 25,603
 - 10
 - 76
 - 131
 
By default, fzf uses the system's "find" command. You can change that by altering the env variable $FZF_DEFAULT_COMMAND to a third-party utility. The advantage to using these tools is that they observe ignore files. Using silver searcher (i.e. ag), you're default command would look something like the following:
$echo $FZF_DEFAULT_COMMAND ag -l --path-to-ignore ~/.ignore --nocolor --hidden -g ""Regardless of the FZF command used, at the shell you're gathering up file names that match your criteria.
FZF+Vim, an extra plugin in addition to fzf, provides an :Ag command to use in (g)vim. The :Ag command lets you search the contents of files, opposed to its :Files command, which only searches file names.
There is some .vimrc customization one might want when using FZF+Vim. For example, the tweak I like is the option to run :Ag with a full screen search and preview window (use :Ag! instead of :Ag):
command! -bang -nargs=* Ag \ call fzf#vim#ag(<q-args>, \ <bang>0 ? fzf#vim#with_preview('up:60%') \ : fzf#vim#with_preview('right:50%:hidden', '?'), \ <bang>0)
- 10,969
 - 2
 - 30
 - 42
 
To have a preview window for the file under cursor during search, you can add below to the .vimrc or init.vim
command! -bang -nargs=* Ag
  \ call fzf#vim#grep(
  \   'ag --column --numbers --noheading --color --smart-case '.shellescape(<q-args>), 1,
  \   fzf#vim#with_preview(), <bang>0)
Then use :Ag mySearchTerm to see the result with a preview on the right side. 
You can also map ctrl-g to it for convenience: 
map <C-g> :Ag
- 9,388
 - 1
 - 65
 - 59