From 2ef89f4e81a8c6a58f92eae8149d78180c3ee57a Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Fri, 23 Jun 2023 15:21:37 +0200 Subject: [PATCH] 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. --- .config/vim/vimrc.d/20-plugins.vim | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.config/vim/vimrc.d/20-plugins.vim b/.config/vim/vimrc.d/20-plugins.vim index 29d59f8..f2ac9ee 100644 --- a/.config/vim/vimrc.d/20-plugins.vim +++ b/.config/vim/vimrc.d/20-plugins.vim @@ -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(), 1, - \ fzf#vim#with_preview(), 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