Skip to content
Aloxaf edited this page Mar 6, 2021 · 29 revisions

zstyle

fzf-tab uses zstyle for configuration. It can give you more control over fzf-tab's behavior, eg:

# disable sort when completing options of any command
zstyle ':completion:complete:*:options' sort false

# use input as query string when completing zlua
zstyle ':fzf-tab:complete:_zlua:*' query-string input

fzf-tab is configured via command like this: zstyle ':fzf-tab:{context}' tag value. fzf-tab is the top context. My English is not good. You can see zsh's doc for more information about zstyle.

You can use C-x h to get possible context for a command:

NOTE: You need to use enable-fzf-tab to active fzf-tab again after this command.

❯ rg -- # Press `C-x h` here
tags in context :completion::complete:rg::
    operand-argument-1 options  (_arguments _rg _ripgrep)
tags in context :completion::complete:rg:options:
    options  (_arguments _rg _ripgrep)
tags in context :completion::files-enhance:::
    globbed-files  (_files _files_enhance)

Here are available tags in fzf-tab context:

fzf-command

Specify the fuzzy search program.

By default, fzf-tab use orignal fzf as the fuzzy searcher. But it also provides a wrapper named ftb-tmux-popup, which can use tmux popup (require tmux 3.2) to show results.

asciicast

You can enable it with zstyle ':fzf-tab:*' fzf-command ftb-tmux-popup

Default value:

zstyle ':fzf-tab:*' fzf-command fzf

fzf-bindings

It can be used to add custom keybindings to fzf, like zstyle ':fzf-tab:*' fzf-bindings 'ctrl-j:accept' 'ctrl-a:toggle-all'

These bindings are simply passed through to fzf. See the fzf manual for more details.

You can use {_FTB_INIT_} to initialize some special variables for further usage.

Example:

zstyle ':fzf-tab:complete:*' fzf-bindings \
	'ctrl-v:execute-silent({_FTB_INIT_}code "$realpath")' \
    'ctrl-e:execute-silent({_FTB_INIT_}kwrite "$realpath")'

Default value: None

fzf-preview

The code for previewing.

For more information about previewing, please see Preview

fzf-flags

Any extra flags for fzf-command.

Default value: None

fzf-pad

How many lines does fzf's prompt occupied.

Default value: 2

popup-pad

The right and bottom padding of the popup window.

It is useful when you want to get preview in the tmux popup window.

zstyle ':fzf-tab:complete:cd:*' fzf-preview 'exa -1 --color=always $realpath'
zstyle ':fzf-tab:complete:cd:*' popup-pad 30 0

Default value: None

accept-line

It specifies the key to accept and run a suggestion in one keystroke.

Example:

zstyle ':fzf-tab:*' fzf-bindings 'space:accept'
zstyle ':fzf-tab:*' accept-line enter

Default value: None

continuous-trigger

It specifies the key to trigger a continuous completion (accept the result and start another completion immediately). It's useful when completing a long path.

Default value: zstyle ':fzf-tab:*' continuous-trigger '/'

print-query

Press this key will use current user input as the final completion result (#148).

Default value: zstyle ':fzf-tab:*' print-query alt-enter

switch-group

Switch over different groups (#183).

Default value: zstyle ':fzf-tab:*' switch-group F1 F2

query-string

The strategy for generating query string.

Possible values:

  • input: use user's input as query string, just like zsh's default behavior
  • prefix: use the longest common prefix for all candidates as the query string
  • first: just a flag. If set, the first valid query string will be used
  • longest: another flag. If set, the longest valid query string will be used

Default value: zstyle ':fzf-tab:*' query-string prefix input first

prefix

A prefix to indicate the color.

Default value: zstyle ':fzf-tab:*' prefix '·'

NOTE: If not set zstyle ':completion:*:descriptions' format, it will be set to empty.

default-color

Color when there is no group.

Default value: zstyle ':fzf-tab:*' default-color $'\033[37m' (white)

single-group

What to show when there is only one group.

Possible values:

  • prefix: show color prefix
  • color: show group color
  • header: show group header

Default value: zstyle ':fzf-tab:*' single-group color header

group-colors

Color for different groups and their descriptions.

Default value:

FZF_TAB_GROUP_COLORS=(
    $'\033[94m' $'\033[32m' $'\033[33m' $'\033[35m' $'\033[31m' $'\033[38;5;27m' $'\033[36m' \
    $'\033[38;5;100m' $'\033[38;5;98m' $'\033[91m' $'\033[38;5;80m' $'\033[92m' \
    $'\033[38;5;214m' $'\033[38;5;165m' $'\033[38;5;124m' $'\033[38;5;120m'
)
zstyle ':fzf-tab:*' group-colors $FZF_TAB_GROUP_COLORS

To choose the color you want, you can first use this function to print the palette:

# Usage: palette
palette() {
    local -a colors
    for i in {000..255}; do
        colors+=("%F{$i}$i%f")
    done
    print -cP $colors
}

And then use this helper function to get escape sequence for the color code:

# Usage: printc COLOR_CODE
printc() {
    local color="%F{$1}"
    echo -E ${(qqqq)${(%)color}}
}

show-group

When zstyle ':completion:*:descriptions' format is set, fzf-tab will display these group descriptions as headers.

Set to full to show all descriptions, set to brief to only show descriptions for groups with duplicate members.

Default value: zstyle ':fzf-tab:*' show-group full

Clone this wiki locally