live_grep without ripgrep
I would really like to use telescope and it's live_grep picker without the extra dependency. I'm trying to replace ripgrep with the regular (gnu) grep and this is for now – as far as I know – the only way:
vimgrep_arguments = {
"grep",
"--color=never",
"--with-filename",
"--line-number",
"-b", -- grep doesn't support a `--column` option :(
"--ignore-case",
"--recursive",
"--no-messages",
},
Because grep doesn't have a --column option I have to include the -b option, which outputs the byte offset so the grep output can match with the internal regex.
https://github.com/nvim-telescope/telescope.nvim/blob/b3d3d938696a533c199031418e0da553a8424a46/lua/telescope/make_entry.lua#L165
It would be great to either have an option to configure this internal regex, or to maybe code it as to not impose practically a hard dependency.
I use
vimgrep_arguments = {
"grep",
"--extended-regexp",
"--color=never",
"--with-filename",
"--line-number",
"-b", -- grep doesn't support a `--column` option :(
"--ignore-case",
"--recursive",
"--no-messages",
"--exclude-dir=*cache*",
"--exclude-dir=*.git",
"--exclude=.*",
"--binary-files=without-match"
-- git grep also works but limits to only git directories,the above works perfectly
-- "git", "grep", "--full-name", "--line-number", "--column", "--extended-regexp", "--ignore-case",
-- "--no-color", "--recursive", "--recurse-submodules", "-I"
},
The git grep version respects .gitignore files. @mknurs I believe it would be better if we
could find a way to make the default vimgrep_arguments command git grep and only fallback to gnu grep
when not in a git dir
I would really like to use Ag which does have the correct options AFAIK. However whenever I try to set it up the results of live grep are garbage. It would be really nice to not have to rely on ripgrep and it's rust dependency when building my stack from scratch. I'm kind of new to neovim/lua though so maybe I'm setting things up wrong. 🤷♂️
@Ultra-Code do you add that vimgrep_argument , inside the telescope.setup ?
like so ?
require('telescope').setup {
defaults = require('telescope.themes').get_ivy {
mappings = {
i = { ["<C-h>"] = "which_key" }
}
},
-- Use grep wihtout rg dependency
vimgrep_arguments = {
"grep",
"--extended-regexp",
"--color=never",
"--with-filename",
"--line-number",
"-b", -- grep doesn't support a `--column` option :(
"--ignore-case",
"--recursive",
"--no-messages",
"--exclude-dir=*cache*",
"--exclude-dir=*.git",
"--exclude=.*",
"--binary-files=without-match"
},
}
@motorto vimgrep_arguments is in the default table .ie something like this
Thanks, works now !
For anyone interested in here is the setup I used to get it working with ag aka the silver searcher:
require('telescope').setup{
defaults = {
vimgrep_arguments = {
"ag",
"--nocolor",
"--noheading",
"--numbers",
"--column",
"--smart-case",
"--silent",
"--vimgrep",
}
}
}
On macOs high sierra (10.13.6), trying to configure with native grep (grep (BSD grep) 2.5.1-FreeBSD) with above psakievich setup, but without success. Currently in lua/telescope/builtin/__files.lua:231 function files.find_files there are checks for commands, maybe it's worth to implement in files.live_grep also check for commands and set finder accordingly? Could be:
if 1 == vim.fn.executable "rg" then
if grep_open_files then
search_list = filelist
elseif search_dirs then
search_list = search_dirs
end
return flatten { args, "--", prompt, search_list }
elseif 1 == vim.fn.executable "grep" then
return flatten { "grep", "-rbisn", prompt, opts.cwd }
elseif 1 == vim.fn.executable "findstr" then
return flatten { "findstr", "/s /n /o /p", prompt, opts.cwd .. "*.*" } --windows native
end