26

I have fzf setup in vim with barely any customisation:

" fzf and ripgrep settings
set rtp+=/usr/local/opt/fzf
let g:fzf_action = {
    \ 'ctrl-t': 'tab split',
    \ 'ctrl-i': 'split',
    \ 'ctrl-s': 'vsplit'
    \ }

In my .bash_profile, I set the environment variable FZF_DEFAULT_COMMAND to show hidden, but ignore node_modules and .git:

export FZF_DEFAULT_COMMAND='rg --files --follow --no-ignore-vcs --hidden -g "!{node_modules/*,.git/*}"'

However, when I use :Files function in vim, it still searches in the folders i want ignored.

doctopus
  • 5,349
  • 8
  • 53
  • 105

7 Answers7

24

Have you tried :GFiles command?

It is one of the best FZF command that is excluding anything that is in .gitignore.

Personally I like to use it as default.

:help fzf-vim-commands
undg
  • 787
  • 4
  • 14
  • 11
    I think this is incorrect. `:GFiles` list all files that are added in the git repo. New files which have not been added yet will not show up. – Moberg Apr 03 '21 at 09:15
  • Most of the time, I know where I'm creating files, and/or I have them in `:Buffers`. Those 2 commands are solving for me 99.999% of cases related to the question. – undg Jul 01 '21 at 15:03
  • Sure, same for me! I use `:Files` when I want to look at some generated/built-in artifact – Moberg Jul 05 '21 at 08:18
  • 2
    This doesn't answer the question. – Richard Möhn Jul 22 '21 at 06:24
  • Is it possible to parametrize `git ls-files` so that it shows everything except ignored files? – schmijos Jan 11 '22 at 11:39
  • I tried `fzf --help`, I don't see any option called `GFiles` or `:GFiles`. Also I opened vim(using spacevim) and typed `:GFiles`, I dont see any command like that. Can you elaborate more instead of simply specifying `:GFiles` – theprogrammer Apr 24 '23 at 03:50
  • This is about fzf vim plugin https://github.com/junegunn/fzf.vim, not about fzf command line utility. – undg Apr 27 '23 at 15:41
22

You can ignore the node_modules (and any other folder you want to ignore) by using a custom FZF_DEFAULT_COMMAND. I use something like this:

(place it in your vimrc)

let $FZF_DEFAULT_COMMAND='find . \( -name node_modules -o -name .git \) -prune -o -print'

Kartik Rawat
  • 244
  • 2
  • 7
7

Silly me. I forgot to source ~/.bash_profile

doctopus
  • 5,349
  • 8
  • 53
  • 105
3

I suppose 'junegunn/fzf' are we tolking about.
I have success on make fzf and rg work for my need. (I'm a developer)
this is my vim 8.2 configuration:

command! -bang -nargs=* Rg
  \ call fzf#vim#grep(
  \   "rg -g '!design/' -g '!dist/' -g '!pnpm-lock.yaml' -g '!.git' -g '!node_modules' --column --line-number --no-heading --color=always --smart-case ".shellescape(<q-args>), 1,
  \   fzf#vim#with_preview({'options': '--exact --delimiter : --nth 4..'}), <bang>0)

In this configuration inside last row --exact remove all fuzzy search: how developer I like exatc metch more

to not include folder and file I do not like I use -g option:

rg -g '!design/' -g '!dist/' -g '!pnpm-lock.yaml' -g '!.git' -g '!node_modules'

The ! is to exclude
I'm excluding design, dist folder from my search base path (current directory)
and exclude il file pnpm-lock.yaml anywhare
and excluse .git and node_modules anywhare (file or folder)

hope can help, regards, Leonardo

1

You can use fzf.vim

It allows you to use default $FZF_DEFAULT_COMMAND if defined.

If you are using vim-plug for plugin management, to install fzf.vim:

Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
isAif
  • 2,126
  • 5
  • 22
  • 34
1

In case it results in:

command failed: rg --files ...

It is because it results from an rg error or you do not have it installed, for that you just have to execute

sudo apt install ripgrep -y

In case you use a script for the installation you can use:

which rg >/dev/null 2>&1 ||
    apt install ripgrep -y
myeongkil kim
  • 2,465
  • 4
  • 16
  • 22
1

Add this to your shell profile:

export FZF_DEFAULT_COMMAND='fd --type f --strip-cwd-prefix --hidden --follow --exclude .git'

That's it.

Farshid Ashouri
  • 16,143
  • 7
  • 52
  • 66