Skip to content

Latest commit

 

History

History
79 lines (55 loc) · 3.38 KB

fzf.asciidoc

File metadata and controls

79 lines (55 loc) · 3.38 KB

fzf.kak

fzf is a command line fuzzy finder that allows fast search and selection of strings within a big collection. It’s a good replacement for the builtin file completion menu in kakoune, particularly when opening files several directory levels afar from the current working directory, or looking for a file whose location is unknown.

The script requires kakoune to have been started within a tmux session, as fzf will be run into a seperate pane whenever needed. The utils.kak also have to have been loaded by kakoune in order for the fzf-cached command to work.

Variables

fzf_filesearch_cmd

Command to use to get a list to select from. Defaults to an ag command (the %s string in the variable’s value will be replaced with the path to search), but other classical tools can be used as well, e.g. find '%s' -type f.

fzf_options

Options that will be passed to fzf-tmux after the candidates list has been generated/read. Defaults to -m to allow multiple selections.

fzf_cache_filename

Name of the file that contains the cached candidates that fzf will allow the user to select from.

fzf_cache_path

This variable is hidden, and contains the path to the latest cache file (whose base name is stored in the fzf_cache_filename variable) that was used by fzf to generate the list of candidates.

Commands

fzf

This function takes a list of directory paths as argument (if no argument is passed, then the current working directory of the buffer is used instead), spawns a tmux pane containing the candidates list handled by fzf, and then opens the selected paths as kakoune buffers. The list of candidates is generated by running the content of the fzf_filesearch_cmd variable, whose output will be passed unfiltered to fzf-tmux (multiple selections are enabled within the fzf selection menu).

If no path is selected (e.g. hitting ^D in the fzf selection menu), then no buffer is opened.

Example: opening a main.c file located somewhere in the remote ~/work/test directory

:fzf ~/work/test
type 'main.c$'
hit return on the path to select, moving up/down with the arrow keys

fzf-cached

This function works similarly to the fzf function, except that it will use the paths passed as arguments as starting points, and then look upward for a file whose name is stored in the fzf_cache_filename variable. Once that file has been found, the function feeds its content to fzf-tmux to allow the user to select entries from the list.

This function avoids spawning a process (e.g. ag or find) that will make a list of all the files within the directories passed as argument, which can hurt performance very harshly when coding over a network filesystem, or in a directory containing a big amount of subdirectories.

Example: caching files for selection, and using the cache file to open a main.c file

ag -g '' > ~/work/test/paths
cd ~/work/test/some/sub/dir
:fzf-cached
type 'main.c$'
hit return on the path to select, moving up/down with the arrow keys