vim:plugins: Redefine :Rg programmatically

Instead of setting a hard coded value, get the current definition of
:Rg, add `-g "!.git"`, and redefine the command.
This commit is contained in:
2023-06-23 15:21:37 +02:00
parent 2411a42e32
commit 2ef89f4e81

View File

@@ -33,9 +33,17 @@ endif
if (get(g:, 'loaded_fzf'))
" Redefine :Rg to ignore the .git directory
" See fzf.vim/plugin/fzf.vim for the original definition
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --smart-case -g "!.git" -- '.shellescape(<q-args>), 1,
\ fzf#vim#with_preview(), <bang>0)
let s:rg_desc = nvim_get_commands({})['Rg']
if s:rg_desc['definition'] !~ " -g '!.git' "
let s:rg_definition = substitute(s:rg_desc['definition'], ' -- ',
\ " -g '!.git' -- ", '')
" See :h command-attributes
" TODO: what is complete_arg?
let s:opts = filter(copy(s:rg_desc),
\ {key, val -> -1 < index(['nargs', 'complete', 'range', 'count',
\ 'addr', 'bang', 'bar', 'register',
\ 'keepscript'], key)
\ })
call nvim_create_user_command('Rg', s:rg_definition, s:opts)
endif
endif