From 25bed070d83c6a230da371336829092a715edd07 Mon Sep 17 00:00:00 2001 From: Alexandre Perrin Date: Tue, 5 May 2020 17:53:11 +0200 Subject: [PATCH] Use -- before the search pattern for Ag, Rg, etc. (#1012) Before this patch, a search pattern starting with a dash like `:Rg -bang` would fail (or exhibit the wrong behaviour) because it would be treated as a option. However, this case is very common when searching for ->member in a project in C, C++, PHP, etc. Co-authored-by: Alexandre Perrin --- README.md | 6 +++--- autoload/fzf/vim.vim | 2 +- doc/fzf-vim.txt | 4 ++-- plugin/fzf.vim | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index cb69a5d..1fe93f3 100644 --- a/README.md +++ b/README.md @@ -228,7 +228,7 @@ predefined `Ag` or `Rg` using `fzf#vim#grep`. ```vim command! -bang -nargs=* GGrep \ call fzf#vim#grep( - \ 'git grep --line-number '.shellescape(), 0, + \ 'git grep --line-number -- '.shellescape(), 0, \ fzf#vim#with_preview({'dir': systemlist('git rev-parse --show-toplevel')[0]}), 0) ``` @@ -242,7 +242,7 @@ the spec argument to `fzf#vim#preview`. ```vim command! -bang -nargs=* Rg \ call fzf#vim#grep( - \ 'rg --column --line-number --no-heading --color=always --smart-case '.shellescape(), 1, + \ 'rg --column --line-number --no-heading --color=always --smart-case -- '.shellescape(), 1, \ fzf#vim#with_preview(), 0) ``` @@ -267,7 +267,7 @@ a "fuzzy finder". ```vim function! RipgrepFzf(query, fullscreen) - let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case %s || true' + let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case -- %s || true' let initial_command = printf(command_fmt, shellescape(a:query)) let reload_command = printf(command_fmt, '{q}') let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command]} diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index 8767bdc..9a44ff4 100644 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -700,7 +700,7 @@ function! fzf#vim#ag(query, ...) let query = empty(a:query) ? '^(?=.)' : a:query let args = copy(a:000) let ag_opts = len(args) > 1 && type(args[0]) == s:TYPE.string ? remove(args, 0) : '' - let command = ag_opts . ' ' . fzf#shellescape(query) + let command = ag_opts . ' -- ' . fzf#shellescape(query) return call('fzf#vim#ag_raw', insert(args, command, 0)) endfunction diff --git a/doc/fzf-vim.txt b/doc/fzf-vim.txt index 2591fc6..11ffd4d 100644 --- a/doc/fzf-vim.txt +++ b/doc/fzf-vim.txt @@ -286,7 +286,7 @@ predefined `Ag` or `Rg` using `fzf#vim#grep`. > command! -bang -nargs=* GGrep \ call fzf#vim#grep( - \ 'git grep --line-number '.shellescape(), 0, + \ 'git grep --line-number -- '.shellescape(), 0, \ fzf#vim#with_preview({'dir': systemlist('git rev-parse --show-toplevel')[0]}), 0) < {10} bin/preview.sh @@ -302,7 +302,7 @@ 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(), 1, + \ 'rg --column --line-number --no-heading --color=always --smart-case -- '.shellescape(), 1, \ fzf#vim#with_preview(), 0) < diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 0cb0f50..d039ed4 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -57,7 +57,7 @@ call s:defs([ \'command! -bar -bang Colors call fzf#vim#colors(0)', \'command! -bang -nargs=+ -complete=dir Locate call fzf#vim#locate(, s:p(0), 0)', \'command! -bang -nargs=* Ag call fzf#vim#ag(, s:p(0), 0)', -\'command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case ".shellescape(), 1, s:p(0), 0)', +\'command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case -- ".shellescape(), 1, s:p(0), 0)', \'command! -bang -nargs=* Tags call fzf#vim#tags(, 0)', \'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(, s:p(0, { "placeholder": "{2}:{3}", "options": ["-d", "\t"] }), 0)', \'command! -bar -bang Snippets call fzf#vim#snippets(0)',