How to make Telescope ignore files inside node_modules?
Asked Answered
M

4

13

I'm new in the VIM / NEOVIM world so I probably am doing something else wrong, but from the docs it says that Telescope will ignore all the files registered in the .gitignore file, which is definitively there but it still searches in node_modules

So this is what I do:

  1. I cd into my project folder
  2. Hit nvim
  3. hit <leader>ff
  4. Telescope opens and I start typing, but searches are really slow because they are including node_modules

These are the plugins that I have for setting up telescope

" Telescope
Plug 'nvim:solua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'

And then my remaps right from the docs:

" Find files using Telescope command-line sugar.
nnoremap <leader>ff <cmd>Telescope find_files<cr>
nnoremap <leader>fg <cmd>Telescope live_grep<cr>
nnoremap <leader>fb <cmd>Telescope buffers<cr>
nnoremap <leader>fh <cmd>Telescope help_tags<cr>

All this is running in a WSL terminal with Ubuntu. What am I missing?

Multiangular answered 28/7, 2021 at 15:17 Comment(0)
L
34

Just add

require('telescope').setup{ 
  defaults = { 
    file_ignore_patterns = { 
      "node_modules" 
    }
  }
}

to your init.lua

Leacock answered 11/11, 2021 at 6:12 Comment(0)
M
6

I had the same issue, if the file finder does not ignore your .gitignore files you need to install BurntSushi/ripgrep, if your error continue after that, use :checkhealth telescope for more info about plugin errors.

Good luck!! and sorry for my bad english...

Mildred answered 8/4, 2023 at 2:0 Comment(1)
This is the right solution I believe. file_ignore_patterns make it very slow.Hartsell
A
4

Install BurntSushi/ripgrep See telescope readme under Suggested dependencies Then put node_modules in your .gitignore and your good to go.

Arnuad answered 30/6, 2022 at 6:10 Comment(0)
C
1

You need some customization for rg:

--ignore-file <PATH>...                  
    Specifies a path to one or more .gitignore format rules files. These patterns
    are applied after the patterns found in .gitignore and .ignore are applied
    and are matched relative to the current working directory. Multiple additional
    ignore files can be specified by using the --ignore-file flag several times.
    When specifying multiple ignore files, earlier files have lower precedence
    than later files.

Add to config for nvim:

require('telescope').setup{
  defaults = {
    vimgrep_arguments = {
      'rg',
      '--color=never',
      '--no-heading',
      '--with-filename',
      '--line-number',
      '--column',
      '--smart-case',
      '--ignore-file',
      '.gitignore'
    },
Chui answered 29/7, 2021 at 6:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.