14

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.

4

3 回答 3

15

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

于 2018-03-01T15:23:10.667 回答
13
  1. 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.

  2. 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)

于 2018-06-06T22:22:28.547 回答
5

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

于 2020-01-10T22:44:27.657 回答