Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pains connecting fzf, MacVim and ripgrep #315

Closed
6 tasks
chew-z opened this issue Feb 19, 2017 · 10 comments
Closed
6 tasks

Pains connecting fzf, MacVim and ripgrep #315

chew-z opened this issue Feb 19, 2017 · 10 comments
Labels

Comments

@chew-z
Copy link

chew-z commented Feb 19, 2017

  • Category
    • Question
    • Bug
    • [ x] Suggestion
  • OS
    • Linux
    • [ x] macOS
    • Windows
    • Etc.
  • Vim
    • [ x] Vim
    • Neovim

This isn't an issue with fzf.vim per se but result of few lost hours connecting fzf, MacVim and ripgrep.

When using ripgrep glob with negation I had to escape ! character not once but twice - '--glob "\!.git/*". Otherwise no luck. There is probably logical explanation for that as the command is passed via shell [zsh], applescript and shell again.

However terminal vim does not tolerate even single escaping (it should). I have ended up with this:

if has("gui_running")
" for MacVim with script we have to escape '!' character twice (no joking) in --glob option 
" - otherwise we getting errors caused by bash/zsh expansion of !
    command! -bang -nargs=* Rg
        \ call fzf#vim#grep(
        \   'rg --column --color=always --no-heading --smart-case --hidden --follow --glob "\\!.git/*" '.shellescape(<q-args>), 1,
        \   <bang>0 ? fzf#vim#with_preview('up:60%')
        \           : fzf#vim#with_preview('right:50%:hidden', '?'),
        \   <bang>0)
else
    command! -bang -nargs=* Rg
        \ call fzf#vim#grep(
        \   'rg --column --color=always --no-heading --smart-case --hidden --follow --glob "!.git/*" '.shellescape(<q-args>), 1,
        \   <bang>0 ? fzf#vim#with_preview('up:60%')
        \           : fzf#vim#with_preview('right:50%:hidden', '?'),
        \   <bang>0)
endif

Perhaps someone will make use of it.

@junegunn
Copy link
Owner

I'll see why it works inconsistently, but I believe you're better off using single quotes around the argument either with "rg ... --glob '!.git/*' ... " or with 'rg ... --glob ''!.git/*'' ... '.

@junegunn
Copy link
Owner

Hmm, I found that :echo system("echo '!'") gives ! as expected, but :!echo '!' expands the exclamation mark, and the expansion is done by Vim.

:!{cmd}			Execute {cmd} with the shell.  See also the 'shell'
			and 'shelltype' option.

			Any '!' in {cmd} is replaced with the previous
			external command (see also 'cpoptions').  But not when
			there is a backslash before the '!', then that
			backslash is removed.  Example: ":!ls" followed by
			":!echo ! \! \\!" executes "echo ls ! \!".

That explains the problem you run into. I'll see what I can do.

@junegunn
Copy link
Owner

I updated the vim plugin of the main repo to escape ! when using :! to execute the command (it's used when you start fzf in fullscreen mode, or in GVim). Can you update and check if it fixes the problem?

@chew-z
Copy link
Author

chew-z commented Feb 20, 2017

Wow, you have narrowed that down really quick.

I must report that progress has been made. I have updated the plugin and removed "if" statement so now I have only one version. It works in both MacVim and terminal (brew vim) but only with double '\\!' on MacVim.

So the difference is that before vim was probably breaking and didn't show any results with MacVim (double '\\!') variant and it works fine now. But I still have to double escape.

without escaping with '\' in MacVim the commandline looks following:

rg --column --color=always --no-heading --smart-case --hidden --follow --glob "clear 2> /dev/null.git/*" 'Kasia'|"/usr/local/Cellar/fzf/0.16.5/bin/fzf" --ansi --delimiter : --nth 4..,.. --prompt "Rg> " --multi --bind alt-a:select-all,alt-d:deselect-all --color hl:68,hl+:110 --preview-window right:50%:hidden --preview "'/Users/rrj/.vim/plugged/fzf.vim/bin/preview.rb'"\ \ {} --bind '?:toggle-preview' --expect=ctrl-v,ctrl-x,ctrl-t > /var/folders/jf/p_jxvfqs3hxdk31qydzjhszw0000gn/T/vqNSRj5/0 && exit

MacVim breaks and vim works OK

with single escaping '\'

rg --column --color=always --no-heading --smart-case --hidden --follow --glob "!.git/*" 'Kasia'|"/usr/local/Cellar/fzf/0.16.5/bin/fzf"  --ansi --delimiter : --nth 4..,.. --prompt "Rg> " --multi --bind alt-a:select-all,alt-d:deselect-all --color hl:68,hl+:110  --preview-window right:50%:hidden --preview "'/Users/rrj/.vim/plugged/fzf.vim/bin/preview.rb'"\ \ {} --bind '?:toggle-preview' --expect=ctrl-v,ctrl-x,ctrl-t > /var/folders/jf/p_jxvfqs3hxdk31qydzjhszw0000gn/T/vonzHLv/0 && exit
zsh: event not found: .git/ 

MacVim breaks (notice the "zsh: event not found: .git/" message) and vim works fine

with double escaping '\'

rg --column --color=always --no-heading --smart-case --hidden --follow --glob "\!.git/*" 'Kasia'|"/usr/local/Cellar/fzf/0.16.5/bin/fzf" --ansi --delimiter : --nth 4..,.. --prompt "Rg> " --multi --bind alt-a:select-all,alt-d:deselect-all --color hl:68,hl+:110 --preview-window right:50%:hidden --preview "'/Users/rrj/.vim/plugged/fzf.vim/bin/preview.rb'"\ \ {} --bind '?:toggle-preview' --expect=ctrl-v,ctrl-x,ctrl-t > /var/folders/jf/p_jxvfqs3hxdk31qydzjhszw0000gn/T/vLz2uAn/0 && exit

MacVim works fine and vim as well.

I am using this MacVim - fzf glue script.

I have attached screenshot with second scenario (after pressing Esc).

screen shot 2017-02-20 at 14 17 25

@chew-z
Copy link
Author

chew-z commented Feb 20, 2017

Unfortunately what I have reported above isn't universal. I am using two laptops at the moment, Pro and a Macbook. They are (should be) identical clones regarding .vimrc, .zshrc, scripts et all.

What I have reported above works on Pro. On a Macbook it is the oposite. Version with double as well as single escaping works OK on MacVim (and fails without escaping) but breaks (shows no results) on brew vim.

It works fine without escaping with vim and breaks MacVim.

So it seems I cannot even reproduce this behavior consistently.

@tandrewnichols
Copy link

So . . . what was the resolution to this? I have the same problem . . . any pattern negated within a -g or --glob doesn't get ignored. And furthermore, when using rg through fzf in vim, my .ripgreprc isn't even used, so there's literally no way to exclude directories.

@tandrewnichols
Copy link

Okay, FINALLY. See here: BurntSushi/ripgrep#830. A change was made to ripgrep at some point so that, basically, you don't want to use !node_modules/* but rather !node_modules. So basically every blog post you read about how to use ripgrep in vim with fzf is wrong because they suggest the globstar pattern.

@indeedwatson
Copy link

@tandrewnichols I'm having the same problems that you describe, except even what you said isn't working.

I'm trying to ignore ~/.vim/undodir. In my fzf vim command I have tried !undodir !**/undodir !./vim/undodir !**/.vim/undodir and a few more, and the directory just keeps showing up.

So far it only works if I set it to !undodir and then open nvim in ~/.vim/, but I want to ignore that folder even if I'm at the home directory. Am I missing something?

@tandrewnichols
Copy link

I don't know. I would think !undodir should ignore undodir everywhere. That's how !node_modules is working for me. From my conversation in that other issue, it sounds like the place to start is man gitignore to understand how negated patterns work.

@indeedwatson
Copy link

I figured it out, it was due to some confusion of mine in regards to the shell and vim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants