Welcome to Vifm Q&A, where you can ask questions about Vifm usage. Registration is optional, anonymous posts are moderated. GitHub or Google logins are enabled.
0 votes
in vifm by
edited by

I have a complex text serarch in files:

command! fzfinfiles :!rg --files-with-matches --no-messages "test" | fzf --preview "highlight -O ansi -l {} 2> /dev/null | rg --colors 'match:bg:yellow' --ignore-case --pretty --context 10 'test' || rg --ignore-case --pretty --context 10 'test' {}"

How can I solve it so that when the file is selected, it jumps to that file?

I try this, but not work: Invalid command name:

command! fzfinfiles :execute '!rg --files-with-matches --no-messages "test" | fzf --preview "highlight -O ansi -l {} 2> /dev/null | rg --colors 'match:bg:yellow' --ignore-case --pretty --context 10 'test' || rg --ignore-case --pretty --context 10 'test' {}"' | gf

I think there are a lot of apostrophes, but how could this be eliminated?

1 Answer

0 votes
by

You need something like this (haven't tried it):

command! fzfinfiles :let $FZF_PICK = term('rg --files-with-matches --no-messages "test" |
                                         \ fzf --preview "highlight -O ansi -l {} 2> /dev/null |
                                                        \ rg --colors match:bg:yellow --ignore-case --pretty --context 10 test || rg --ignore-case --pretty --context 10 test {}"')
                   \| if $FZF_PICK != ''
                   \|     execute 'goto' fnameescape($FZF_PICK)
                   \| endif

Could also put the long command as a script into $VIFM/scripts and just call it by name.

by

I try script and works and dont works :)

So I create .config/vifm/scripts/fzfsearchfiles.sh and insert it:
rg --files-with-matches --no-messages "$1" | fzf --preview "highlight -O ansi -l {} 2> /dev/null | rg --colors 'match:bg:yellow' --ignore-case --pretty --context 10 '$1' || rg --ignore-case --pretty --context 10 '$1' {}"

I added +x, so can run it

Then I add to vifmrc file:

command! fzfinfiles :execute '!fzfsearchfiles %a' | gf

But dont jump to the file, when select the fzf result with enter key, simple write te file name.

by

I create .config/vifm/scripts/fzfsearchfiles.sh

But:

>command! fzfinfiles :execute '!fzfsearchfiles %a' | gf

You should use .sh extention in the command as well then. And I meant this:

command! fzfinfiles :let $FZF_PICK = term('fzfsearchfiles.sh %a')
                   \| if $FZF_PICK != ''
                   \|     execute 'goto' fnameescape($FZF_PICK)
                   \| endif
by

I try this method, but I get only blank screen, and nothing happend. When I trye only fzfsearchfiles.sh in the terminal, then works well, but I insert your lines, nothing happens, only blank screen.

by

Right, I forget that fzf is idiotic, try with redirection:

command! fzfinfiles :let $FZF_PICK = term('fzfsearchfiles.sh %a 2>/dev/tty')
                   \| if $FZF_PICK != ''
                   \|     execute 'goto' fnameescape($FZF_PICK)
                   \| endif
by

Ohh my god it's working, working, workiiiing! :D
Thank u so much, and congratulations for vifm! It turned out to be a fantastic file manager, I just love it!

...