Skip to content

Cookbook

Patrick Fong edited this page Nov 16, 2023 · 29 revisions

How can I use a specific release of fzf.fish?

Does the latest version contain bugs or changes that don't jibe with your workflow? Please open a new discussion and we can chat about it. And in the meantime, feel free to use an older version. For example:

# first, uninstall the current version or fisher will complain about conflicting files
fisher remove patrickf1/fzf.fish
# install and freeze the plugin version at v6.5; subsequent calls to `fisher update` will not cause it to update
fisher install patrickf1/[email protected]

I recommend taking a look at ensuing releases to make sure the release you picked doesn't contain not-yet-fixed impactful bugs.

How can I check which version of fzf.fish I'm on?

Unfortunately, I have not built in an easy way to check the version of the plugin that you are running (there's not a simple, easy and clean way of doing it and fisher doesn't provide support for it either). The best way is to look at the git history of the repo and check which of the changes have been loaded into your fish shell by running functions on the function files. For example, the HEAD of v8.1 is this commit and it contains a patch to _fzf_search_processes. You can run functions _fzf_search_processes to check if it contains that patch.

How can I view my key bindings?

  • If you're using the default bindings, you can quickly find them by running fzf_configure_bindings -h
  • If you're using custom bindings, you can cat your config.fish to see what key sequences you passed to fzf_configure_bindings
  • Alternatively, you can just run bind --user and inspect them. They should be near the bottom.

How can I configure Search Directory to open up the current file in $EDITOR

From #273.

# set -gx $EDITOR "nvim" # or "vim", or "code", etc.
set fzf_directory_opts --bind "ctrl-o:execute($EDITOR {} &> /dev/tty)

How can I open fzf in a new Tmux-pane?

Unlike jethrokuan/fzf, fzf.fish does not integrate with fzf-tmux. And this is because it requires minimal effort. Simply make the following function accessible, whether by defining it in your config.fish or in ~/.config/fish/functions/fzf.fish (so that it will be autoloaded):

function fzf --wraps=fzf --description="Use fzf-tmux if in tmux session"
  if set --query TMUX
    fzf-tmux $argv
  else
    command fzf $argv
  end
end

How can I exclude the command timestamp from the search scope when in Search History?

From #169. While being able to search the command timestamp can be useful to find the commands executed on a particular day, you may want to exclude it to make use of fzf's prefix matcher ^. To do this, we can take advantage of --nth option to show the timestamps but exclude them from the search scope:

set --export fzf_history_opts "--nth=4.."

How can I hide the command timestamp from Search History?

From #193. You can use the --with-nth flag to transform the input passed into fzf and exclude the timestamp. Pass it into the search history flag using its custom fzf options flag:

set fzf_history_opts --with-nth=4..

How can I customize file previews based on the file type?

While the fzf_preview_file_cmd only allows you to specify one command to execute to preview files, you can use that to specify a custom function defined by you that can handle different file types. Here is a well-thought-out example submitted by @kidonng. And here is another idea also from @kidonng.

How can I change the colors used by Search Directory?

The colors shown in Search Directory are set by fd and then piped to fzf. Fd's colors can be configured by setting the LS_COLORS variable. See https://github.com/sharkdp/fd#colorized-output and #170.

How can I disable the fzf preview pane for a particular command?

Use custom fzf options feature to pass --preview="" to the command. --preview will override the preview and result in no command being executed to generate the preview.

How can I toggle the preview window on and off while in fzf?

From #266. Use the --bind option to assign a keybinding to call the toggle-preview action. e.g. set fzf_directory_opts --bind ctrl-h:toggle-preview will allow you to toggle the search file preview on and off using Ctrl+H. If you want to make the key binding available in all fzf windows, then add that option to FZF_DEFAULT_OPTS instead.

How can I make history respect chronological order?

From #272. You can turn off sorting by best match and only filter with set fzf_history_opts --no-sort.

How can I bind a search command to Ctrl+Space?

This is currently not supported by fzf_configure_bindings but can be done manually using bind -k. See #279 for more details.

How can I create one shortcut for searching files, one for searching directories?

See #303.