Difference between revisions of "How to integrate fzf for fuzzy finding"
m (Several minor corrections) |
|||
Line 1: | Line 1: | ||
− | <code>vifm</code> | + | <code>vifm</code> already has powerful search features such as <code>:grep</code> and <code>:locate</code>. However, it is possible to further expand its capabilities with fun and powerful programs such as <code>fzf</code> "a general-purpose command-line fuzzy finder." |
== Prerequisites == | == Prerequisites == | ||
Line 11: | Line 11: | ||
=== Commands === | === Commands === | ||
− | We can add the following two commands to <code> | + | We can add the following two commands to <code>vifmrc</code>: |
<source lang="vim"> | <source lang="vim"> | ||
Line 21: | Line 21: | ||
=== Options === | === Options === | ||
− | <code>vifm</code> will run its built in <code>:goto</code> however other commands like <code>:cd</code> should work if an appropriate list is piped to <code>fzf</code>. As this is an example of process substitution (using the output of a command or commands as an argument for another command), we need to use the <code>system()</code> function to run our searching/listing <code>fzf</code> pipeline. To prevent visual artifacts in the terminal, we use the command macro <code>%IU</code> and | + | <code>vifm</code> will run its built in <code>:goto</code> however other commands like <code>:cd</code> should work if an appropriate list is piped to <code>fzf</code>. As this is an example of process substitution (using the output of a command or commands as an argument for another command), we need to use the <code>system()</code> function to run our searching/listing <code>fzf</code> pipeline. To prevent visual artifacts in the terminal, we use the command macro <code>%IU</code> and a call to <code>:redraw</code> for extra safety. |
=== Mappings === | === Mappings === | ||
Line 32: | Line 32: | ||
</source> | </source> | ||
− | In this example I have chosen < | + | In this example I have chosen <kbd>CTRL-g</kbd> and <kbd>CTRL-f</kbd>. |
== Discussions == | == Discussions == |
Revision as of 10:57, 16 December 2018
vifm
already has powerful search features such as :grep
and :locate
. However, it is possible to further expand its capabilities with fun and powerful programs such as fzf
"a general-purpose command-line fuzzy finder."
Prerequisites
You need to have fzf installed. This method creates pipelines using the find
and locate
commands which are present in most Linux distributions.
Considerations
fzf
is a powerful and quick interactive filter in addition to working as a file searching utility by default. This method focuses on piping the output from locate $HOME
for quick traversal though the user's $HOME
directory and the output from find
for recursive traversal.
Examples
Commands
We can add the following two commands to vifmrc
:
command! FZFlocate :execute 'goto "'.system('locate $HOME | fzf --height 10 2>/dev/tty ').'"%IU' | redraw
command! FZFfind :execute 'goto "'.system('find | fzf --height 10 2>/dev/tty ').'"%IU' | redraw
In both examples fzf
will pop up on the bottom and allow us to filter the output of the feeder command. Once our selection is made, fzf
will close and vifm
will advance the active pane to the directory of the selected file with the cursor highlighting it.
Options
vifm
will run its built in :goto
however other commands like :cd
should work if an appropriate list is piped to fzf
. As this is an example of process substitution (using the output of a command or commands as an argument for another command), we need to use the system()
function to run our searching/listing fzf
pipeline. To prevent visual artifacts in the terminal, we use the command macro %IU
and a call to :redraw
for extra safety.
Mappings
We can then add the following mappings to run these commands from normal mode:
nnoremap <c-g> :FZFlocate<cr>
nnoremap <c-f> :FZFfind<cr>
In this example I have chosen CTRL-g and CTRL-f.
Discussions
Here are some further links to discussion of fzf
and the system()
function: