-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Configuring shell key bindings
The key bindings use --height 40%
option to display fzf finder below your cursor, but it's configurable.
If you prefer to run fzf in fullscreen mode, add --no-height
to your $FZF_DEFAULT_OPTS
like follows:
export FZF_DEFAULT_OPTS='--no-height --no-reverse'
You can preview the content of the file under the cursor by setting --preview
option.
# Using highlight (http://www.andre-simon.de/doku/highlight/en/highlight.html)
export FZF_CTRL_T_OPTS="--preview '(highlight -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 2> /dev/null | head -200'"
export FZF_CTRL_T_OPTS="--select-1 --exit-0"
--select-1
automatically selects the item if there's only one so that you don't have to press enter key. Likewise, --exit-0
automatically exits when the list is empty. These options are also useful in FZF_ALT_C_OPTS
.
Sorting by relevance is enabled by default. You can dynamically switch to chronological order by pressing CTRL-R
again, but if you like it to be enabled by default, add --no-sort
to FZF_CTRL_R_OPTS
. Likewise, if you prefer to use exact (non-fuzzy) matching, add --exact
.
export FZF_CTRL_R_OPTS='--no-sort --exact'
Commands that are too long are not fully visible on screen. We can use --preview
option to display the full command on the preview window. In the following example, we bind ?
key for toggling the preview window.
export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:hidden:wrap --bind '?:toggle-preview'"
fzf-history-widget-accept() {
fzf-history-widget
zle accept-line
}
zle -N fzf-history-widget-accept
bindkey '^X^R' fzf-history-widget-accept
bind "$(bind -s | grep '^"\\C-r"' | sed 's/"/"\\C-x/' | sed 's/"$/\\C-m"/')"
There is an open issue for this; #477. We have a solution for zsh, but not for bash.
The following example uses tree
command to show the entries of the directory.
export FZF_ALT_C_OPTS="--preview 'tree -C {} | head -200'"