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.

Use external program to find and select a file?

0 votes
asked May 21, 2016 in vifm by Winstr0m
edited May 21, 2016 by Winstr0m

I want to use this fuzzy file finder to search for and select a file in my current pane. Running the program brings up an interactive screen where you type in a part of a file name, and when you hit enter it prints the absolute path of the file that most closely matches your search to stdout. Adding the following command to my vifmrc file does basically what I want.

command! fzf vifm --select $(fzf)

The problem is that this opens a new vifm instance within my current one, so to quit, I have to hit :q multiple times to close out all the nested instances. Is there a better way to do this?

2 Answers

0 votes
answered May 21, 2016 by xaizek
edited Sep 2, 2016 by xaizek
 
Best answer

There is no direct way, but navigation from custom view can be used here like this:

command! fzf :execute '!fzf 2>&0 %%U' | normal! gf

It basically creates a view consisting of a single file and performs navigation to it (gf). % is doubled because it's inside user-defined command, which also performs macro expansion. stdin -> stderr redirection is needed because fzf doesn't look for terminal in stdin and vifm redirects stderr to capture errors.

UPD: Some issues with the command above have been reported here. Development version after 0.8.2 (and so the next release) has %IU macro, which should be used to prevent possible issues with interface after calling fzf:

command! fzf :execute '!fzf 2>&0 %%IU' | normal! gf
commented May 21, 2016 by Winstr0m

Thank you very much! This helps a lot, and I appreciate the quick response.

+1 vote
answered Jul 25, 2016 by tagwint
edited Jul 25, 2016 by tagwint

If you have --remote options enabled

command! fzf vifm --remote --select $(fzf)

will do it right, as long as your current vifm instance is the only one running

--remote option may not be available though, depending on the vifm installation you used.
If that is your case, you still can get it by building vifm yourself, that's easy enough,
here's the link for your conveniences https://wiki.vifm.info/index.php?title=Obtaining_Vifm#From_sources

If you would like to make a bug report or feature request consider using GitHub, SourceForge or e-mail. Posting such things here won't be considered as spam, but this is not a perfect place for it.
...