aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/news.txt1
-rw-r--r--runtime/doc/options.txt15
-rw-r--r--runtime/doc/vim_diff.txt1
-rw-r--r--runtime/lua/nvim/health.lua14
-rw-r--r--runtime/lua/vim/_defaults.lua8
-rw-r--r--runtime/lua/vim/_meta/options.lua12
-rw-r--r--src/nvim/options.lua15
7 files changed, 62 insertions, 4 deletions
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index d320db4e51..966d50c382 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -375,6 +375,7 @@ The following changes to existing APIs or features add new behavior.
correctly without it. (Use |gF| for filepaths suffixed with ":line:col").
• 'comments' includes "fb:•".
• 'shortmess' includes the "C" flag.
+ • 'grepprg' defaults to using ripgrep if available.
• Automatic linting of treesitter query files (see |ft-query-plugin|).
Can be disabled via: >lua
vim.g.query_lint_on = {}
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 54333ee85d..7b5e3a1c49 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -2851,9 +2851,10 @@ A jump table for the options with a short description can be found at |Q_op|.
This is a scanf-like string that uses the same format as the
'errorformat' option: see |errorformat|.
+ If ripgrep ('grepprg') is available, this option defaults to `%f:%l:%c:%m`.
+
*'grepprg'* *'gp'*
-'grepprg' 'gp' string (default "grep -n ",
- Unix: "grep -n $* /dev/null")
+'grepprg' 'gp' string (default see below)
global or local to buffer |global-local|
Program to use for the |:grep| command. This option may contain '%'
and '#' characters, which are expanded like when used in a command-
@@ -2870,6 +2871,16 @@ A jump table for the options with a short description can be found at |Q_op|.
apply equally to 'grepprg'.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.
+ This option defaults to:
+ - `rg --vimgrep -uuu $* ...` if ripgrep is available (|:checkhealth|),
+ - `grep -n $* /dev/null` on Unix,
+ - `findstr /n $* nul` on Windows.
+ Ripgrep can perform additional filtering such as using .gitignore rules
+ and skipping hidden or binary files. This is disabled by default (see the -u option)
+ to more closely match the behaviour of standard grep.
+ You can make ripgrep match Vim's case handling using the
+ -i/--ignore-case and -S/--smart-case options.
+ An |OptionSet| autocmd can be used to set it up to match automatically.
*'guicursor'* *'gcr'* *E545* *E546* *E548* *E549*
'guicursor' 'gcr' string (default "n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20")
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt
index 82f3fe9b1b..d426f8151f 100644
--- a/runtime/doc/vim_diff.txt
+++ b/runtime/doc/vim_diff.txt
@@ -52,6 +52,7 @@ Defaults *nvim-defaults*
- 'encoding' is UTF-8 (cf. 'fileencoding' for file-content encoding)
- 'fillchars' defaults (in effect) to "vert:│,fold:·,foldsep:│"
- 'formatoptions' defaults to "tcqj"
+- 'grepprg' defaults to using ripgrep if available
- 'hidden' is enabled
- 'history' defaults to 10000 (the maximum)
- 'hlsearch' is enabled
diff --git a/runtime/lua/nvim/health.lua b/runtime/lua/nvim/health.lua
index 35d293bee6..d4670eab6c 100644
--- a/runtime/lua/nvim/health.lua
+++ b/runtime/lua/nvim/health.lua
@@ -383,6 +383,19 @@ local function check_terminal()
end
end
+local function check_external_tools()
+ health.start('External Tools')
+
+ if vim.fn.executable('rg') == 1 then
+ local rg = vim.fn.exepath('rg')
+ local cmd = 'rg -V'
+ local out = vim.fn.system(vim.fn.split(cmd))
+ health.ok(('%s (%s)'):format(vim.trim(out), rg))
+ else
+ health.warn('ripgrep not available')
+ end
+end
+
function M.check()
check_config()
check_runtime()
@@ -390,6 +403,7 @@ function M.check()
check_rplugin_manifest()
check_terminal()
check_tmux()
+ check_external_tools()
end
return M
diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua
index 5ada64a358..68ad95b725 100644
--- a/runtime/lua/vim/_defaults.lua
+++ b/runtime/lua/vim/_defaults.lua
@@ -496,3 +496,11 @@ if tty then
end
end
end
+
+--- Default 'grepprg' to ripgrep if available.
+if vim.fn.executable('rg') == 1 then
+ -- Match :grep default, otherwise rg searches cwd by default
+ -- Use -uuu to make ripgrep not do its default filtering
+ vim.o.grepprg = 'rg --vimgrep -uuu $* ' .. (vim.fn.has('unix') == 1 and '/dev/null' or 'nul')
+ vim.o.grepformat = '%f:%l:%c:%m'
+end
diff --git a/runtime/lua/vim/_meta/options.lua b/runtime/lua/vim/_meta/options.lua
index 5e40851457..e10eb305b1 100644
--- a/runtime/lua/vim/_meta/options.lua
+++ b/runtime/lua/vim/_meta/options.lua
@@ -2625,6 +2625,8 @@ vim.go.gd = vim.go.gdefault
--- This is a scanf-like string that uses the same format as the
--- 'errorformat' option: see `errorformat`.
---
+--- If ripgrep ('grepprg') is available, this option defaults to `%f:%l:%c:%m`.
+---
--- @type string
vim.o.grepformat = "%f:%l:%m,%f:%l%m,%f %l%m"
vim.o.gfm = vim.o.grepformat
@@ -2649,6 +2651,16 @@ vim.go.gfm = vim.go.grepformat
--- apply equally to 'grepprg'.
--- This option cannot be set from a `modeline` or in the `sandbox`, for
--- security reasons.
+--- This option defaults to:
+--- - `rg --vimgrep -uuu $* ...` if ripgrep is available (`:checkhealth`),
+--- - `grep -n $* /dev/null` on Unix,
+--- - `findstr /n $* nul` on Windows.
+--- Ripgrep can perform additional filtering such as using .gitignore rules
+--- and skipping hidden or binary files. This is disabled by default (see the -u option)
+--- to more closely match the behaviour of standard grep.
+--- You can make ripgrep match Vim's case handling using the
+--- -i/--ignore-case and -S/--smart-case options.
+--- An `OptionSet` autocmd can be used to set it up to match automatically.
---
--- @type string
vim.o.grepprg = "grep -n $* /dev/null"
diff --git a/src/nvim/options.lua b/src/nvim/options.lua
index 1d81b570b7..c22bce04c8 100644
--- a/src/nvim/options.lua
+++ b/src/nvim/options.lua
@@ -3368,6 +3368,8 @@ return {
Format to recognize for the ":grep" command output.
This is a scanf-like string that uses the same format as the
'errorformat' option: see |errorformat|.
+
+ If ripgrep ('grepprg') is available, this option defaults to `%f:%l:%c:%m`.
]=],
full_name = 'grepformat',
list = 'onecomma',
@@ -3382,8 +3384,7 @@ return {
condition = 'MSWIN',
if_false = 'grep -n $* /dev/null',
if_true = 'findstr /n $* nul',
- doc = [["grep -n ",
- Unix: "grep -n $* /dev/null"]],
+ doc = [[see below]],
},
desc = [=[
Program to use for the |:grep| command. This option may contain '%'
@@ -3401,6 +3402,16 @@ return {
apply equally to 'grepprg'.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.
+ This option defaults to:
+ - `rg --vimgrep -uuu $* ...` if ripgrep is available (|:checkhealth|),
+ - `grep -n $* /dev/null` on Unix,
+ - `findstr /n $* nul` on Windows.
+ Ripgrep can perform additional filtering such as using .gitignore rules
+ and skipping hidden or binary files. This is disabled by default (see the -u option)
+ to more closely match the behaviour of standard grep.
+ You can make ripgrep match Vim's case handling using the
+ -i/--ignore-case and -S/--smart-case options.
+ An |OptionSet| autocmd can be used to set it up to match automatically.
]=],
expand = true,
full_name = 'grepprg',