nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
14.92k stars 816 forks source link

grep_string does not search hidden files that are committed to git #2780

Closed dylan-chong closed 8 months ago

dylan-chong commented 8 months ago

Description

when you use grep_string in a git repo, it will not find results in a .bla file, even if it is committed

there should be a hidden and ignore options like the find_files option, or at least search them by default

Neovim version

:version
NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1692716794

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/__w/neovim/neovim/build/nvim.AppDir/usr/share/nvim"

Operating system and version

Linux DESKTOP-PP5T68A 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Telescope version / branch / rev

20bf20500c95208c3ac0ef07245065

checkhealth telescope

==============================================================================
telescope: require("telescope.health").check()

Checking for required plugins ~
- OK plenary installed.
- WARNING nvim-treesitter not found. (Required for `:Telescope treesitter`.)

Checking external dependencies ~
- OK rg: found ripgrep 13.0.0
- OK fd: found fd 8.3.1

===== Installed extensions ===== ~

Steps to reproduce

first create a file called vimrc (outside the test directory)

mkdir test
cd test
git init
echo abcNotHidden > file-not-hidden
echo abc > .file
git add .
git commit -m 'bla'
nvim "+:lua require('telescope.builtin').grep_string({ use_regex = true, search = 'abc' })" -u ../vimrc

Expected behavior

i should see the result from the hidden file

Actual behavior

i do not see the result

Minimal config

call plug#begin('~/.vim/plugged')
" Using new lua configs
Plug 'nvim-telescope/telescope.nvim' " Fuzzy finder
Plug 'nvim-lua/plenary.nvim' " Dep of telescope

" }

call plug#end()
jamestrew commented 8 months ago

This is just the default behavior of ripgrep but you can adjust this for telescope a few ways.

  1. tweak the default vimgrep_arguments. This will have grep_string and live_grep both show hidden files
    require("telescope").setup({
    defaults = {
    vimgrep_arguments = {
      "rg",
      "--color=never",
      "--no-heading",
      "--with-filename",
      "--line-number",
      "--column",
      "--smart-case",
      "--hidden", -- add this 
    }
    -- your other options
    }
    })
  2. Use the additional_args option on grep_string (also works for live_grep) to pass --hidden
    require('telescope.builtin').grep_string({
    use_regex = true,
    search = 'abc',
    additional_args = { "--hidden" },
    })

Both of these should work. Feel free to reopen if I've missed something.

martin-braun commented 3 months ago

@jamestrew How can I pass rg arguments in the vim command itself, so that I can have different arguments depending on my mapping? I basically want it to respect file_ignore_patterns, but I still want to add some arguments for one mapping to search through untracked and hidden files, while just searching normal for the other mapping.

Can this be done?

The mapping <CMD>Telescope live_grep hidden=true no_ignore=false<CR> will not work, because you don't wish to implement all the options from find_files into live_grep.

EDIT: Reading the docs is sometimes helpful. 😅

<CMD>Telescope live_grep vimgrep_arguments=rg,--color=never,--no-heading,--no-heading,--line-number,--column,--smart-case,--hidden,--no-ignore<CR>

Works!