fzf Fuzzy Finder Snippets
Some snippets are bash shell specific
# Search all files in current directory (default)fzf
# Search files using find and selections to filefind * -type f | fzf > selected
# Search only directories, change directory into themcd (fd --type directory | fzf)cd (find -type d | fzf)
# Search all files including hidden filesfzf -a
# Preview files with batfzf --preview 'bat --color=always {}'## Restrict linesfzf --preview 'bat --style=numbers --color=always --line-range :500 {}'
# Open searched file with vim# Can be used with any other commandvim $(fzf)vim $(find . -type f | fzf)
# Change to directorycd $(find . -type d | fzf)
# Copy searched file to a specific locationcp $(fzf) /path/to/destination
# Use fzf auto-completion with other commands like vim, ssh, variables, kill## Requires shell integrationvim ** <TAB>ssh ** <TAB>unset ** <TAB>kill -9 ** <TAB># Command will give a pop up for search on:# - files# - known hosts# - environment variables, aliases# - processes# For more, see https://github.com/junegunn/fzf#fuzzy-completion-for-bash-and-zsh
# fzf key bindings, source appropriate file for your shell# Fedora - see DNF package information, example:source /usr/share/fzf/shell/key-bindings.bash# See Ubuntu Debian per /usr/share/doc/fzf/README.Debian# For more, see https://github.com/junegunn/fzf/tree/master/shell
# Nushell: Open fzf selected file with a helixhx (fzf)
Search and Filters
Section titled “Search and Filters”# fzf extended search - default setting# https://github.com/junegunn/fzf#search-syntax
# fuzzy-match Items that match sbtrktfzf sbtrkt
# exact-match Items that match wild (uses ')fzf \'wildfzf -e
# Limit scope to nth field of the entry, accepts rangesfzf --nth## Example## Display a number before each entry using CLI command nl, for number of lines# But we don’t want our queries to match these numbersvim $(find . -type f | nl | fzf --nth=2)
# Regex to change field delimiter which is space by defaultfzf --delimiter## Examplevim $(find . -type f | nl -s ',' | fzf --nth=2 --delimiter=',')
# Case insensitivefzf -i# Case sensitivefzf +i
# items matching wild and wold exact patternsfzf \'wild \'world# prefix-exact-match - items that start with musicfzf ^music# suffix-exact-match Items that end with .mp3fzf .mp3$# inverse-exact-match Items that do not include firefzf !fire# inverse-prefix-exact-match Items that do not start with musicfzf !^music# inverse-suffix-exact-match Items that do not end with .mp3!.mp3$
fzf Useful Aliases
Section titled “fzf Useful Aliases”Sources:
- GitHub - kelleyma49/PSFzf: A PowerShell wrapper around the fuzzy finder fzf
- fzf/ADVANCED.md at master · junegunn/fzf · GitHub
# fe - Starts an editor for the selected files in the fuzzy finderfzf | xargs $EDITORfzf | xargs nvim
# fkill - Stops process selected by the user in fzf.ps -ef | fzf | awk '{print $2}' | xargs kill -9
fzf on PowerShell
Section titled “fzf on PowerShell”# Edit a file# Replace notepad with another program to open a file with that programGet-ChildItem . -Recurse -Attributes !Directory | Invoke-Fzf | % { notepad $_ }