-
-
Save acepukas/7600c0677d77b2aeda999fd3c3a24379 to your computer and use it in GitHub Desktop.
| # 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" |
| " 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> |
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 wirobert@linux-rhel7-64
$ gvim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled May 20 2017 00:44:30)
Included patches: 1-600
Compiled by wirobert@linux-rhel7-64
Thanks
gb
Thanks Aaron. No problem.
Will check if I can figure it out. It is not urgent now.
Good day
@gbnaidu Yes! Correct. Sorry, missed your comment there. Well now you have a thorough explanation after you already figured it out! :)