fzf icon indicating copy to clipboard operation
fzf copied to clipboard

How to make fzf with Ag not display files and folders from .gitignore in vim?

Open rihannarickeminem opened this issue 1 year ago • 7 comments

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

```Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } Plug 'junegunn/fzf.vim'

let g:go_imports_autosave = 0

Plug 'drmikehenry/vim-fontsize'

nmap <Leader>= <Plug>FontsizeBegin nmap <Leader>+ <Plug>FontsizeInc nmap <Leader>- <Plug>FontsizeDec nmap <Leader>0 <Plug>FontsizeDefault

" {{{ let g:fzf_nvim_statusline = 0 " disable statusline overwriting

" nnoremap :GFiles<CR> nnoremap :Files<CR> nnoremap a :Buffers<CR> nnoremap A :Windows<CR> nnoremap ; :BLines<CR> nnoremap o :BTags<CR> nnoremap O :Tags<CR> nnoremap ? :History<CR> nnoremap / :execute 'Ag ' . input('Ag/')<CR> nnoremap . :AgIn

nnoremap K :call SearchWordWithAg()<CR> vnoremap K :call SearchVisualSelectionWithAg()<CR> nnoremap gl :Commits<CR> nnoremap ga :BCommits<CR> nnoremap ft :Filetypes<CR>

" https://vi.stackexchange.com/questions/31012/what-does-plug-do-in-vim imap <C-x><C-f> (fzf-complete-file-ag) imap <C-x><C-l> (fzf-complete-line) imap <C-x><C-w> (fzf-complete-word)

function! SearchWordWithAg() execute 'Ag' expand('') endfunction

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() " }}} nnoremap f :FZF -q <C-R>=expand("")<CR><CR> function! s:getVisualSelection() let [line_start, column_start] = getpos("'<")[1:2] let [line_end, column_end] = getpos("'>")[1:2] let lines = getline(line_start, line_end)

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 f <Esc>:FZF -q <C-R>=<SID>getVisualSelection()<CR><CR> let g:fzf_history_dir = '~/.local/share/fzf-history' let $FZF_DEFAULT_COMMAND = 'ag --ignore dist -g ""'

" Open files in horizontal split nnoremap <Leader>s :call fzf#run({ \ 'down': '40%', \ 'sink': 'botright split' })<CR>

" Open files in vertical horizontal split nnoremap <Leader>v :call fzf#run({ \ 'right': winwidth('.') / 2, \ 'sink': 'vertical botright split' })<CR>

</details> 

rihannarickeminem avatar Jan 09 '25 15:01 rihannarickeminem

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 avatar Jan 10 '25 12:01 junegunn

@junegunn does not work for me =*((

rihannarickeminem avatar Jan 16 '25 01:01 rihannarickeminem

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 avatar Jan 16 '25 02:01 junegunn

@junegunn this command eval "$FZF_DEFAULT_COMMAND" gives this output:

Image

rihannarickeminem avatar Jan 30 '25 08:01 rihannarickeminem

You should check if the command in the variable works as expected on your shell. Not on vim.

junegunn avatar Jan 30 '25 08:01 junegunn

@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 (((

rihannarickeminem avatar Feb 01 '25 10:02 rihannarickeminem

You can remove them with piping to sed as last resort

Bellavene avatar Apr 03 '25 00:04 Bellavene