Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable AG in vim + fzf

Tags:

vim

ag

fzf

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.

like image 468
odbhut.shei.chhele Avatar asked Mar 01 '18 15:03

odbhut.shei.chhele


Video Answer


2 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

like image 89
nbari Avatar answered Oct 02 '22 19:10

nbari


  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)

like image 43
gregory Avatar answered Oct 02 '22 20:10

gregory