Last active
January 12, 2022 17:26
-
-
Save acepukas/7600c0677d77b2aeda999fd3c3a24379 to your computer and use it in GitHub Desktop.
Convenient commands for ripgrep and fzf.vim integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RIPGREP config (this is the environment variable that vim is reading when building the rg command) | |
# In this case the shell is zsh. Adjust accordingly based on preferred shell and needs. | |
export RG_COMMAND_BASE='rg --ignore-file ~/.ignore --hidden --follow' | |
# Minimal FZF config. Shares the RG_COMMAND_BASE env var. | |
[ -f $HOME/.fzf.zsh ] && source $HOME/.fzf.zsh | |
export FZF_DEFAULT_COMMAND="$RG_COMMAND_BASE --files" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" set up an rg command with options for reuse. Refer to the other gist file (.zshrc) for details on $RG_COMMAND_BASE | |
let g:rg_command = $RG_COMMAND_BASE . ' --column --line-number --no-heading --color "always"' | |
" concatenate together all the necessary options for the final call to the rg command | |
fun! BuildRgCommand(opts, qargs) | |
let l:list = [g:rg_command] + a:opts + ['--', shellescape(a:qargs)] | |
return join(l:list, ' ') | |
endfun | |
" construct the rg command and pass it to the fzf grep command with all necessary options | |
fun! Fzf_grep(opts, qargs, bang) abort | |
let l:rg = BuildRgCommand(a:opts, a:qargs) | |
call fzf#vim#grep(l:rg, 1, {}, a:bang) | |
endfun | |
" custom commands | |
" Search literal string recursive ignoring case | |
command! -bang -nargs=* RG call Fzf_grep(['--ignore-case', '--fixed-strings'], <q-args>, <bang>0) | |
" Search literal string recursive case sensitive | |
command! -bang -nargs=* RGS call Fzf_grep(['--fixed-strings'], <q-args>, <bang>0) | |
" Search recursive case sensitive as RegExp (using ripgrep RegExp engine, _not_ vim RegExp engine) | |
command! -bang -nargs=* RGX call Fzf_grep([], <q-args>, <bang>0) | |
" Seach literal string recursive case sensitive with word boundaries | |
command! -bang -nargs=* RGSW call Fzf_grep(['-w', '--fixed-strings'], <q-args>, <bang>0) | |
" Search files for word under cursor | |
nnoremap <leader>* "zyiw :let cmd = 'RGSW ' . @z <bar> call histadd("cmd", cmd) <bar> execute cmd<cr> | |
" Search files for visually selected text | |
xnoremap <leader>* "zy :let cmd = 'RGS ' . @z <bar> call histadd("cmd", cmd) <bar> execute cmd <cr> |
Author
acepukas
commented
Sep 22, 2020
via email
Hi GB,
I'm well thanks.
Based on the error that you have there it *seems* like the fzf.vim plugin,
particularly the fzf#run function is having trouble with indexing an array.
I honestly can't say I know what's happening there. I don't normally run
GVIM. What I would do in this case is try to use the stock functionality
that comes with fzf.vim without any of the custom commands I made and see
if you still experience any issues with it, just to rule out any
incompatibilities between fzf.vim and GVIM. If everything works fine, then
we know that the custom commands are an issue somehow.
Aaron
…On Tue, Sep 22, 2020 at 10:12 AM G B Naidu ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Hi Aaron,
How are you?
I came across one strange issue.
The above gist you had shared is working fine without any issue in VIM.
However, if I try "RG <pattern" in GVIM, I am getting errors.
What I am observing is GVIM doesn't seem to be able to get the files based
on the pattern given. It is showing all the files in a separate window. I
verified that the rg command is working correctly if I run manually.
rg command being used: rg --ignore-file ~/.ignore --hidden --follow
--column --line-number --no-heading --color "always" --ignore-case
--fixed-strings -- 'master'
FZF_DEFAULT_COMMAND is: rg --ignore-file ~/.ignore --hidden --follow
--files
If I select one of those files, I get the below error:
Error detected while processing function Fzf_grep[3]..fzf#vim#grep[25]..42_
fzf[18]..fzf#run[63]..15_callback:
line 21:
Vim(let):E684: list index out of range: 1
Here are the details of versions:
$ vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled May 20 2017 00:44:30)
Included patches: 1-600
Compiled by ***@***.***
$ gvim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled May 20 2017 00:44:30)
Included patches: 1-600
Compiled by ***@***.***
Thanks
gb
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/7600c0677d77b2aeda999fd3c3a24379#gistcomment-3463089>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAP5WVMJJ35AIFG7J33SHL3SHCWC7ANCNFSM4Q7LOCSQ>
.
Thanks Aaron. No problem.
Will check if I can figure it out. It is not urgent now.
Good day
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment