Skip to content

Configuring shell key bindings

Junegunn Choi edited this page Oct 8, 2016 · 12 revisions

CTRL-T

Preview

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'"

CTRL-R

Sorting and exact matching

Sorting is disabled by default to respect chronological ordering. You can dynamically enable sorting by pressing CTRL-R again, but if you like it to be enabled by default you can add --sort to FZF_CTRL_R_OPTS. Also, if you prefer to use exact (non-fuzzy) matching, add --exact.

export FZF_CTRL_R_OPTS='--sort --exact'

Preview

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 preview window.

export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:hidden --bind '?:toggle-preview'"

Directly executing the command (CTRL-X CTRL-R)

zsh

fzf-history-widget-accept() {
  fzf-history-widget
  zle accept-line
}
zle     -N     fzf-history-widget-accept
bindkey '^X^R' fzf-history-widget-accept

bash

bind "$(bind -s | grep '^"\\C-r"' | sed 's/"/"\\C-x/' | sed 's/"$/\\C-m"/')"

Dynamically choose to execute or edit

There is an open issue for this; #477. We have a solution for zsh, but not for bash.

ALT-C

Preview

Use tree command to show the content of the directory on the preview window.

export FZF_ALT_C_OPTS="--preview 'tree -C {} | head -200'"
Clone this wiki locally