Escape some characters in vim rip-grep search

This commit is contained in:
Michael Campagnaro 2023-01-22 08:34:29 -05:00
parent 12969578aa
commit 9e07b24cf7

13
vimrc
View File

@ -197,7 +197,7 @@ call plug#begin('~/.vim/plugged')
" MISC
"////////////////////////////////////////////////////////////////
Plug 'bling/vim-airline' " Enhanced status/tabline.
Plug 'vim-airline/vim-airline' " Enhanced status/tabline.
Plug 'embear/vim-localvimrc' " Add a .lvimrc to a folder to override .vimrc config.
Plug 'tpope/vim-obsession' " Continuously updated session files (tracks window positions, open folds, etc).
Plug 'tpope/vim-fugitive' " Git wrapper (I particularly like :Gblame, which I've wrapped as :Blame)
@ -352,7 +352,9 @@ set wildmenu
set wildmode=longest,list,full
set wildignore+=*/log/*,*.so,*.swp,*.zip,*/rdoc/*
set grepprg=rg\ --vimgrep " Requires ripgrep to be installed.
if executable('rg')
set grepprg=rg\ --vimgrep\ --hidden " Requires ripgrep to be installed.
endif
set list listchars=tab:»·,trail" Show trailing whitespace.
@ -1427,7 +1429,12 @@ function! Search(path, search_args, case_insensitive=0)
let l:rg_args .= " --ignore-case"
endif
exec 'Rg ' . l:rg_args . ' -e "' . l:term . '"' . ' ' . a:path
" Some characters need to be escaped.
let l:escaped_term = substitute(l:term, '[#%]', '\\\\\\&', 'g')
let l:format = 'Rg ' . l:rg_args . ' ' . a:path . ' -e %s'
let l:cmd = printf(l:format, shellescape(l:escaped_term))
exec l:cmd
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""