How to make fzf with Ag not display files and folders from .gitignore in vim?
Checklist
- [X] I have read through the manual page (
man fzf) - [X] I have searched through the existing issues
- [X] For bug reports, I have checked if the bug is reproducible in the latest version of fzf
Output of fzf --version
0.57.0 (0476a65)
OS
- [ ] Linux
- [X] macOS
- [ ] Windows
- [ ] Etc.
Shell
- [ ] bash
- [X] zsh
- [ ] fish
Problem / Steps to reproduce
I have specified let $FZF_DEFAULT_COMMAND = 'ag -g ""' in vim and in .zshrc i have export FZF_DEFAULT_COMMAND='ag --hidden --ignore dist node_modules .git -g ""'
but still getting an output with files from dist folder
the dist folder is in .gitignore
# build
**/dist
**/build
**/dist-zip
Mac M2 macvim
fzf --version
0.57.0 (0476a65)
at the end if it will be ignored , how can i make it include if i need ?
the only way (from here https://github.com/mileszs/ack.vim/issues/210#issuecomment-290890545) i have made it work is to add .ignore file in my project with
dist
but how to make it work for all projects this solution does not work https://github.com/junegunn/fzf.vim/issues/453#issuecomment-738321660
Here is parts for fzf in my config
let g:go_imports_autosave = 0
Plug 'drmikehenry/vim-fontsize'
nmap
" {{{ let g:fzf_nvim_statusline = 0 " disable statusline overwriting
" nnoremap
nnoremap
" https://vi.stackexchange.com/questions/31012/what-does-plug-do-in-vim
imap <C-x><C-f>
function! SearchWordWithAg()
execute 'Ag' expand('
function! SearchVisualSelectionWithAg() range let old_reg = getreg('"') let old_regtype = getregtype('"') let old_clipboard = &clipboard set clipboard& normal! ""gvy let selection = getreg('"') call setreg('"', old_reg, old_regtype) let &clipboard = old_clipboard execute 'Ag' selection endfunction
function! SearchWithAgInDirectory(...)
call fzf#vim#ag(join(a:000[1:], ' '), extend({'dir': a:1}, g:fzf#vim#default_layout))
endfunction
command! -nargs=+ -complete=dir AgIn call SearchWithAgInDirectory(
if len(lines) == 0
return ""
endif
let lines[-1] = lines[-1][:column_end - (&selection == "inclusive" ? 1 : 2)]
let lines[0] = lines[0][column_start - 1:]
return join(lines, "\n")
endfunction
vnoremap
" Open files in horizontal split
nnoremap
" Open files in vertical horizontal split
nnoremap
</details>
export FZF_DEFAULT_COMMAND='ag --hidden --ignore dist node_modules .git -g ""'
If I'm not mistaken, --ignore only takes a single argument, so the command is invalid.
cd /tmp
mkdir foo
cd foo
ag --hidden --ignore dist node_modules .git -g ""
gives errors
ERR: Error stat()ing: node_modules
ERR: Error opening directory node_modules: No such file or directory
ERR: Error stat()ing: .git
ERR: Error opening directory .git: No such file or directory
Anyway, having let $FZF_DEFAULT_COMMAND = 'ag --ignore dist -g ""' alone in .vimrc makes :FZF "gitignore" files as expected.
To make sure that :FZF is picking up the variable, I even tried changing it to
let $FZF_DEFAULT_COMMAND = 'seq 100; ag --ignore dist -g ""; seq 100'
and yes, :FZF does use it and shows numbers around the list.
@junegunn does not work for me =*((
I can't reproduce the problem. fzf simply reads the output of the command. You should make sure that the command itself is working as expected. i.e.eval "$FZF_DEFAULT_COMMAND".
@junegunn this command eval "$FZF_DEFAULT_COMMAND"
gives this output:
You should check if the command in the variable works as expected on your shell. Not on vim.
@junegunn i have
export FZF_DEFAULT_COMMAND='ag --hidden --ignore dist -g ""' . - in my .zshrc
and
eval "$FZF_DEFAULT_COMMAND" - in terminal - gives me no output (((
You can remove them with piping to sed as last resort