ignore named sub directories vim telescope

6k views Asked by At

This question concerns telescope in vim. I can see any info as to the type of regex being used.

With the following setting I can achieve to ignore node_modules only if I start the explorer at the root level where node_modules exist.

telescope.nvim.vim

lua << EOF
require('telescope').setup{
   ...
   file_ignore_patterns = {"node_modules"},
   ...
}
EOF

How can I achieve the outcome where node_modules is ignored recursively - so ignore any deeply nested node_modules. "node_modules/*" is not working. Unless I can make telescope respect .gitignore would also be a solution.

Thank you in advance for helping.

3

There are 3 answers

0
l3lackheart On

I know this seems late, but the probs in your config is, file_ignore_patterns should be defined in defaults objects, like this

require'telescope'.setup({
    defaults = {
        file_ignore_patterns = { "^./.git/", "^node_modules/", "^vendor/" },
    }
})
0
garwil On

From the documentation here, it looks like you can use % as a wildcard as well as *. I was able to exclude image files in this way:

file_ignore_patterns = {'%.jpeg'}

I've also been able to get this working:

file_ignore_patterns = {'node_modules/.*'}

If you're still having problems, the git_files builtin supports .gitignore out of the box, so use :Telescope git_files instead of :Telescope find_files if you're in a git repo.

Finally, you can set the find_command option in the Telescope setup, so if you're using something like ripgrep you could tell it to ignore node_modules from there.

0
Anzumana On

Make sure you have https://github.com/BurntSushi/ripgrep installed. This is the grep replacement telescope uses to search and if its installed it will ignore the node_modules.

Most likely telescope uses grep as a fallback.

In my case it was literally just installing ripgrep with brew and like magic the node_modules disappeared :)