Skip to content

Instantly share code, notes, and snippets.

@mrnugget
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save mrnugget/f49439a968015943bd41 to your computer and use it in GitHub Desktop.

Select an option

Save mrnugget/f49439a968015943bd41 to your computer and use it in GitHub Desktop.
fzz.vim - Use fzz and the_silver_searcher in Vim.
function! Fzz(...)
let l:fzz_executable = "fzz"
if !executable(l:fzz_executable)
echoe "Fzz command '" . l:fzz_executable . "' not found. Is in your $PATH?"
return
endif
let l:ag_cmd = "ag --nogroup --nocolor"
let l:ag_executable = get(split(l:ag_cmd, " "), 0)
if !executable(l:ag_executable)
echoe "Fzz command '" . l:ag_executable . "' not found. Is in your $PATH?"
return
endif
let l:lastarg = a:000[-1]
if isdirectory(l:lastarg)
let l:fzzdir = l:lastarg
let l:fzzargs = join(a:000[:-2], ' ')
else
let l:fzzdir = ""
let l:fzzargs = join(a:000, ' ')
end
let l:fzzprg = l:fzz_executable . " " . l:ag_cmd . " {{$*}} " . l:fzzdir
let grepprg_bak=&grepprg
try
let &grepprg=l:fzzprg
execute "grep " . escape(l:fzzargs, '|')
finally
let &grepprg=grepprg_bak
endtry
endfunction
command! -nargs=+ -complete=file Fzz call Fzz(<f-args>)
@mrnugget
Copy link
Copy Markdown
Author

In contrast to this

set grepprg=fzz\ ag\ --nogroup\ --nocolor\ \{\{\$*}\}

the code above allows you to tell fzz and ag in which directory to search. You can do this:

:Fzz foo bar /home/foobar/directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment