fzf(1) | fzf - a command-line fuzzy finder | fzf(1) |
fzf - a command-line fuzzy finder
fzf [options]
fzf is a general-purpose command-line fuzzy finder.
v2 Optimal scoring algorithm (quality)
v1 Faster but not guaranteed to find the optimal result
(performance)
length Prefers line with shorter length
begin Prefers line with matched substring closer to the beginning
end Prefers line with matched substring closer to the end
index Prefers line that appeared earlier in the input stream
- Each criterion should appear only once in the list
- index is only allowed at the end of the list
- index is implicitly appended to the list when not specified
- Default is length (or equivalently length,index)
- If end is found in the list, fzf will scan each line
backwards
backward-kill-word
backward-word
forward-word
kill-word
default Display from the bottom of the screen
reverse Display from the top of the screen
reverse-list Display from the top of the screen, prompt at the
bottom
rounded Border with rounded corners (default)
sharp Border with sharp corners
horizontal Horizontal lines above and below the finder
vertical Vertical lines on each side of the finder
top
bottom
left
right
Each part can be given in absolute number or in percentage relative to the terminal size with % suffix.
e.g.
fzf --margin 10%
fzf --margin 1,5%
e.g.
fzf --margin 5% --padding 5% --border --preview 'cat {}' \
--color bg:#222222,preview-bg:#333333
default Display on the next line to the prompt
inline Display on the same line
hidden Do not display finder info
dark Color scheme for dark 256-color terminal
light Color scheme for light 256-color terminal
16 Color scheme for 16-color terminal
bw No colors (equivalent to --no-color)
COLOR NAMES:
fg Text
bg Background
preview-fg Preview window text
preview-bg Preview window background
hl Highlighted substrings
fg+ Text (current line)
bg+ Background (current line)
gutter Gutter on the left (defaults to bg+)
hl+ Highlighted substrings (current line)
info Info line (match counters)
border Border around the window (--border and --preview)
prompt Prompt
pointer Pointer to the current line
marker Multi-select marker
spinner Streaming input indicator
header Header
ANSI COLORS:
-1 Default terminal foreground/background color
(or the original color of the text)
0 ~ 15 16 base colors
16 ~ 255 ANSI 256 colors
#rrggbb 24-bit colors
ANSI ATTRIBUTES: (Only applies to foreground colors)
regular Clears previously set attributes; should precede the other
ones
bold
underline
reverse
dim
italic
EXAMPLES:
# Seoul256 theme with 8-bit colors
# (https://github.com/junegunn/seoul256.vim)
fzf --color='bg:237,bg+:236,info:143,border:240,spinner:108' \
--color='hl:65,fg:252,header:65,fg+:252' \
--color='pointer:161,marker:168,prompt:110,hl+:108'
# Seoul256 theme with 24-bit colors
fzf
--color='bg:#4B4B4B,bg+:#3F3F3F,info:#BDBB72,border:#6B6B6B,spinner:#98BC99'
\
--color='hl:#719872,fg:#D9D9D9,header:#719872,fg+:#D9D9D9' \
--color='pointer:#E12672,marker:#E17899,prompt:#98BEDE,hl+:#98BC99'
fzf exports $FZF_PREVIEW_LINES and $FZF_PREVIEW_COLUMNS so that they represent the exact size of the preview window. (It also overrides $LINES and $COLUMNS with the same values but they can be reset by the default shell, so prefer to refer to the ones with FZF_PREVIEW_ prefix.)
A placeholder expression starting with + flag will be replaced to the space-separated list of the selected lines (or the current line if no selection was made) individually quoted.
e.g.
fzf --multi --preview='head -10 {+}'
git log --oneline | fzf --multi --preview 'git show {+1}'
When using a field index expression, leading and trailing whitespace is stripped from the replacement string. To preserve the whitespace, use the s flag.
Also, {q} is replaced to the current query string, and {n} is replaced to zero-based ordinal index of the line. Use {+n} if you want all index numbers when multiple lines are selected.
A placeholder expression with f flag is replaced to the path of a temporary file that holds the evaluated list. This is useful when you multi-select a large number of items and the length of the evaluated string may exceed ARG_MAX.
e.g.
# Press CTRL-A to select 100K items and see the sum of all the
numbers.
# This won't work properly without 'f' flag due to ARG_MAX limit.
seq 100000 | fzf --multi --bind ctrl-a:select-all \
--preview "awk '{sum+=} END {print sum}' {+f}"
Note that you can escape a placeholder pattern by prepending a backslash.
Preview window will be updated even when there is no match for the current query if any of the placeholder expressions evaluates to a non-empty string.
Since 0.24.0, fzf can render partial preview content before the preview command completes. ANSI escape sequence for clearing the display (CSI 2 J) is supported, so you can use it to implement preview window that is constantly updating.
e.g.
fzf --preview 'for i in $(seq 100000); do
(( i % 200 == 0 )) && printf "\033[2J"
echo "$i"
sleep 0.01
done'
Determines the layout of the preview window. If the argument contains :hidden, the preview window will be hidden by default until toggle-preview action is triggered. Long lines are truncated by default. Line wrap can be enabled with :wrap flag. Cyclic scrolling is enabled with :cycle flag.
If size is given as 0, preview window will not be visible, but fzf will still execute the command in the background.
To change the style of the border of the preview window, specify one of rounded (border with rounded edges, default), sharp (border with sharp edges), or noborder (no border).
+SCROLL[-OFFSET] determines the initial scroll offset of the preview window. SCROLL can be either a numeric integer or a single-field index expression that refers to a numeric integer. The optional -OFFSET part is for adjusting the base offset so that you can see the text above it. It should be given as a numeric integer (-INTEGER), or as a denominator form (-/INTEGER) for specifying a fraction of the preview window height.
default resets all options previously set to the default.
# Initial scroll offset is set to the line number of each line of
# git grep output *minus* 5 lines (-5)
git grep --line-number '' |
fzf --delimiter : --preview 'nl {1}' --preview-window +{2}-5
# Preview with bat, matching line in the middle of the window (-/2)
git grep --line-number '' |
fzf --delimiter : \
--preview 'bat --style=numbers --color=always --highlight-line {2} {1}' \
--preview-window +{2}-/2
0 Normal exit
1 No match
2 Error
130 Interrupted with CTRL-C or ESC
A field index expression can be a non-zero integer or a range expression ([BEGIN]..[END]). --nth and --with-nth take a comma-separated list of field index expressions.
1 The 1st field
2 The 2nd field
-1 The last field
-2 The 2nd to last field
3..5 From the 3rd field to the 5th field
2.. From the 2nd field to the last field
..-3 From the 1st field to the 3rd to the last field
.. All the fields
Unless specified otherwise, fzf will start in "extended-search mode". In this mode, you can specify multiple patterns delimited by spaces, such as: 'wild ^music .mp3$ sbtrkt !rmx
You can prepend a backslash to a space (\ ) to match a literal space character.
A term that is prefixed by a single-quote character (') is interpreted as an "exact-match" (or "non-fuzzy") term. fzf will search for the exact occurrences of the string.
A term can be prefixed by ^, or suffixed by $ to become an anchored-match term. Then fzf will search for the lines that start with or end with the given string. An anchored-match term is also an exact-match term.
If a term is prefixed by !, fzf will exclude the lines that satisfy the term from the result. In this case, fzf performs exact match by default.
If you don't prefer fuzzy matching and do not wish to "quote" (prefixing with ') every word, start fzf with -e or --exact option. Note that when --exact is set, '-prefix "unquotes" the term.
A single bar character term acts as an OR operator. For example, the following query matches entries that start with core and end with either go, rb, or py.
e.g. ^core go$ | rb$ | py$
--bind option allows you to bind a key or an event to one or more actions. You can use it to customize key bindings or implement dynamic behaviors.
--bind takes a comma-separated list of binding expressions. Each binding expression is KEY:ACTION or EVENT:ACTION.
e.g.
fzf --bind=ctrl-j:accept,ctrl-k:kill-line
ctrl-[a-z]
ctrl-space
ctrl-\
ctrl-]
ctrl-^ (ctrl-6)
ctrl-/ (ctrl-_)
ctrl-alt-[a-z]
alt-[a-z]
alt-[0-9]
f[1-12]
enter (return ctrl-m)
space
bspace (bs)
alt-up
alt-down
alt-left
alt-right
alt-enter
alt-space
alt-bspace (alt-bs)
alt-/
tab
btab (shift-tab)
esc
del
up
down
left
right
home
end
insert
pgup (page-up)
pgdn (page-down)
shift-up
shift-down
shift-left
shift-right
left-click
right-click
double-click
or any single character
change
e.g.
# Moves cursor to the top (or bottom depending on --layout) whenever the
query is changed
fzf --bind change:top
backward-eof
e.g.
fzf --bind backward-eof:abort
A key or an event can be bound to one or more of the following actions.
ACTION: DEFAULT BINDINGS (NOTES):
abort ctrl-c ctrl-g ctrl-q esc
accept enter double-click
accept-non-empty (same as accept except that it prevents fzf
from exiting without selection)
backward-char ctrl-b left
backward-delete-char ctrl-h bspace
backward-delete-char/eof (same as backward-delete-char except
aborts fzf if query is empty)
backward-kill-word alt-bs
backward-word alt-b shift-left
beginning-of-line ctrl-a home
cancel (clear query string if not empty, abort fzf otherwise)
clear-screen ctrl-l
clear-selection (clear multi-selection)
clear-query (clear query string)
delete-char del
delete-char/eof ctrl-d (same as delete-char except
aborts fzf if query is empty)
deselect-all (deselect all matches)
down ctrl-j ctrl-n down
end-of-line ctrl-e end
execute(...) (see below for the details)
execute-silent(...) (see below for the details)
forward-char ctrl-f right
forward-word alt-f shift-right
ignore
jump (EasyMotion-like 2-keystroke movement)
jump-accept (jump and accept)
kill-line
kill-word alt-d
next-history (ctrl-n on --history)
page-down pgdn
page-up pgup
half-page-down
half-page-up
preview(...) (see below for the details)
preview-down shift-down
preview-up shift-up
preview-page-down
preview-page-up
preview-half-page-down
preview-half-page-up
previous-history (ctrl-p on --history)
print-query (print query and exit)
refresh-preview
reload(...) (see below for the details)
replace-query (replace query string with the current selection)
select-all (select all matches)
toggle (right-click)
toggle-all (toggle all matches)
toggle+down ctrl-i (tab)
toggle-in (--layout=reverse* ? toggle+up :
toggle+down)
toggle-out (--layout=reverse* ? toggle+down :
toggle+up)
toggle-preview
toggle-preview-wrap
toggle-sort
toggle+up btab (shift-tab)
top (move to the top result)
unix-line-discard ctrl-u
unix-word-rubout ctrl-w
up ctrl-k ctrl-p up
yank ctrl-y
Multiple actions can be chained using + separator.
e.g.
fzf --bind 'ctrl-a:select-all+accept'
With execute(...) action, you can execute arbitrary commands without leaving fzf. For example, you can turn fzf into a simple file browser by binding enter key to less command like follows.
fzf --bind "enter:execute(less {})"
You can use the same placeholder expressions as in --preview.
If the command contains parentheses, fzf may fail to parse the expression. In that case, you can use any of the following alternative notations to avoid parse errors.
execute[...]
execute~...~
execute!...!
execute@...@
execute#...#
execute$...$
execute%...%
execute^...^
execute&...&
execute*...*
execute;...;
execute/.../
execute|...|
execute:...
fzf switches to the alternate screen when executing a command. However, if the command is expected to complete quickly, and you are not interested in its output, you might want to use execute-silent instead, which silently executes the command without the switching. Note that fzf will not be responsive until the command is complete. For asynchronous execution, start your command as a background process (i.e. appending &).
reload(...) action is used to dynamically update the input list without restarting fzf. It takes the same command template with placeholder expressions as execute(...).
See https://github.com/junegunn/fzf/issues/1750 for more info.
e.g.
# Update the list of processes by pressing CTRL-R
ps -ef | fzf --bind 'ctrl-r:reload(ps -ef)' --header 'Press CTRL-R to
reload' \
--header-lines=1 --layout=reverse
# Integration with ripgrep
RG_PREFIX="rg --column --line-number --no-heading --color=always
--smart-case "
INITIAL_QUERY="foobar"
FZF_DEFAULT_COMMAND="$RG_PREFIX '$INITIAL_QUERY'" \
fzf --bind "change:reload:$RG_PREFIX {q} || true" \
--ansi --phony --query "$INITIAL_QUERY"
With preview(...) action, you can specify multiple different preview commands in addition to the default preview command given by --preview option.
e.g.
# Default preview command with an extra preview binding
fzf --preview 'file {}' --bind '?:preview:cat {}'
# A preview binding with no default preview command
# (Preview window is initially empty)
fzf --bind '?:preview:cat {}'
# Preview window hidden by default, it appears when you first hit '?'
fzf --bind '?:preview:cat {}' --preview-window hidden
Junegunn Choi (junegunn.c@gmail.com)
Project homepage:
Extra Vim plugin:
MIT
Nov 2020 | fzf 0.24.3 |