Last active
August 29, 2015 14:11
-
-
Save mrnugget/f49439a968015943bd41 to your computer and use it in GitHub Desktop.
fzz.vim - Use fzz and the_silver_searcher in Vim.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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>) | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In contrast to this
the code above allows you to tell
fzzandagin which directory to search. You can do this: