Add :RG command and fzf#vim#grep2 function

This commit is contained in:
Junegunn Choi
2023-06-04 15:22:13 +09:00
parent dc71692255
commit 87b60bb133
4 changed files with 83 additions and 68 deletions

View File

@@ -1,32 +1,31 @@
fzf-vim.txt fzf-vim Last change: January 27 2023
fzf-vim.txt fzf-vim Last change: June 4 2023
FZF-VIM - TABLE OF CONTENTS *fzf-vim* *fzf-vim-toc*
==============================================================================
fzf :heart: vim |fzf-vim-fzfheart-vim|
Rationale |fzf-vim-rationale|
Why you should use fzf on Vim |fzf-vim-why-you-should-use-fzf-on-vim|
Installation |fzf-vim-installation|
Using vim-plug |fzf-vim-using-vim-plug|
Dependencies |fzf-vim-dependencies|
Commands |fzf-vim-commands|
Customization |fzf-vim-customization|
Global options |fzf-vim-global-options|
Preview window |fzf-vim-preview-window|
Command-local options |fzf-vim-command-local-options|
Advanced customization |fzf-vim-advanced-customization|
Vim functions |fzf-vim-vim-functions|
Example: Customizing Files command |fzf-vim-example-customizing-files-command|
Example: git grep wrapper |fzf-vim-example-git-grep-wrapper|
Example: Rg command with preview window |fzf-vim-example-rg-command-with-preview-window|
Example: Advanced ripgrep integration |fzf-vim-example-advanced-ripgrep-integration|
Mappings |fzf-vim-mappings|
Completion functions |fzf-vim-completion-functions|
Custom completion |fzf-vim-custom-completion|
Reducer example |fzf-vim-reducer-example|
Status line of terminal buffer |fzf-vim-status-line-of-terminal-buffer|
Hide statusline |fzf-vim-hide-statusline|
Custom statusline |fzf-vim-custom-statusline|
License |fzf-vim-license|
fzf :heart: vim |fzf-vim-fzfheart-vim|
Rationale |fzf-vim-rationale|
Why you should use fzf on Vim |fzf-vim-why-you-should-use-fzf-on-vim|
Installation |fzf-vim-installation|
Using vim-plug |fzf-vim-using-vim-plug|
Dependencies |fzf-vim-dependencies|
Commands |fzf-vim-commands|
Customization |fzf-vim-customization|
Global options |fzf-vim-global-options|
Preview window |fzf-vim-preview-window|
Command-local options |fzf-vim-command-local-options|
Advanced customization |fzf-vim-advanced-customization|
Vim functions |fzf-vim-vim-functions|
Example: Customizing Files command |fzf-vim-example-customizing-files-command|
Example: git grep wrapper |fzf-vim-example-git-grep-wrapper|
Example: Advanced ripgrep integration |fzf-vim-example-advanced-ripgrep-integration|
Mappings |fzf-vim-mappings|
Completion functions |fzf-vim-completion-functions|
Custom completion |fzf-vim-custom-completion|
Reducer example |fzf-vim-reducer-example|
Status line of terminal buffer |fzf-vim-status-line-of-terminal-buffer|
Hide statusline |fzf-vim-hide-statusline|
Custom statusline |fzf-vim-custom-statusline|
License |fzf-vim-license|
FZF :HEART: VIM *fzf-vim-fzfheart-vim*
==============================================================================
@@ -108,7 +107,7 @@ so you can omit it if you use a plugin manager that doesn't support hooks.
COMMANDS *fzf-vim-commands*
==============================================================================
*:Files* *:GFiles* *:Buffers* *:Colors* *:Ag* *:Rg* *:Lines* *:BLines* *:Tags* *:BTags* *:Marks*
*:Files* *:GFiles* *:Buffers* *:Colors* *:Ag* *:Rg* *:RG* *:Lines* *:BLines* *:Tags* *:BTags* *:Marks*
*:Windows* *:Locate* *:History* *:Snippets* *:Commits* *:BCommits* *:Commands* *:Maps*
*:Helptags* *:Filetypes*
@@ -122,6 +121,7 @@ COMMANDS *fzf-vim-commands*
`:Colors` | Color schemes
`:Ag[PATTERN]` | {ag}{7} search result ( `ALT-A` to select all, `ALT-D` to deselect all)
`:Rg[PATTERN]` | {rg}{8} search result ( `ALT-A` to select all, `ALT-D` to deselect all)
`:RG[PATTERN]` | {rg}{8} search result; relaunch ripgrep on every keystroke
`:Lines[QUERY]` | Lines in loaded buffers
`:BLines[QUERY]` | Lines in the current buffer
`:Tags[QUERY]` | Tags in the project ( `ctags-R` )
@@ -180,6 +180,8 @@ Preview window~
Some commands will show the preview window on the right. You can customize the
behavior with `g:fzf_preview_window`. Here are some examples:
*g:fzf_preview_bash*
>
" This is the default option:
" - Preview window on the right with 50% width
@@ -235,17 +237,18 @@ Vim functions~
Each command in fzf.vim is backed by a Vim function. You can override a
command or define a variation of it by calling its corresponding function.
----------+---------------------------------------------------------------------------
Command | Vim function ~
----------+---------------------------------------------------------------------------
----------+------------------------------------------------------------------------------------------
Command | Vim function ~
----------+------------------------------------------------------------------------------------------
`Files` | `fzf#vim#files(dir,[specdict],[fullscreenbool])`
`GFiles` | `fzf#vim#gitfiles(git_options,[specdict],[fullscreenbool])`
`GFiles?` | `fzf#vim#gitfiles('?',[specdict],[fullscreenbool])`
`Buffers` | `fzf#vim#buffers([specdict],[fullscreenbool])`
`Colors` | `fzf#vim#colors([specdict],[fullscreenbool])`
`Rg` | `fzf#vim#grep(command,[has_columnbool],[specdict],[fullscreenbool])`
`RG` | `fzf#vim#grep2(command_prefix,query,[has_columnbool],[specdict],[fullscreenbool])`
... | ...
----------+---------------------------------------------------------------------------
----------+------------------------------------------------------------------------------------------
(We can see that the last two optional arguments of each function are
identical. They are directly passed to `fzf#wrap` function. If you haven't
@@ -325,23 +328,13 @@ predefined `Ag` or `Rg` using `fzf#vim#grep`.
{12} bin/preview.sh
Example: Rg command with preview window~
*fzf-vim-example-rg-command-with-preview-window*
You can see the definition of `Rg` command with `:commandRg`. With the
information, you can redefine it with the preview window enabled. In this
case, we're only interested in setting up the preview window, so we will omit
the spec argument to `fzf#vim#preview`.
>
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --smart-case -- '.shellescape(<q-args>), 1,
\ fzf#vim#with_preview(), <bang>0)
<
Example: Advanced ripgrep integration~
*fzf-vim-example-advanced-ripgrep-integration*
The example shown here is now available as the `RG` (all uppercase) command
that uses `fzf#vim#grep2(command_prefix,query,has_column,...)` function.
You no longer need to define it in your Vim configuration file.
In the default implementation of `Rg`, ripgrep process starts only once with
the initial query (e.g. `:Rgfoo`) and fzf filters the output of the process.