Mr Elokusa
tech shortcuts

fzf + ripgrep: any file in your repo in one keystroke

The 20-second alias that replaced 90% of my ls-and-grep flow. Fuzzy-search every file in the repo, preview it with syntax highlighting, open it in your editor — all bound to one shortcut.

Install the two tools

fzf is a fuzzy finder. ripgrep (rg) is a search tool that respects .gitignore by default. Together they replace find + grep for interactive work.
# macOS
brew install fzf ripgrep bat

# arch
sudo pacman -S fzf ripgrep bat

# ubuntu
sudo apt install fzf ripgrep bat

The alias

Drop this into ~/.zshrc or ~/.bashrc. Ctrl+F fuzzy-searches every tracked file, shows a syntax-highlighted preview, and opens your pick in $EDITOR.
ff() {
  local file
  file=$(rg --files --hidden --glob '!.git' | fzf \
    --preview 'bat --style=numbers --color=always --line-range :200 {}' \
    --preview-window=right:60%:wrap) && ${EDITOR:-vim} "$file"
}
bindkey -s '^f' 'ff\n'  # zsh: Ctrl+F

Bonus: search file contents

# Find files by content, preview the match, open at line
fg() {
  local line
  line=$(rg --line-number --no-heading --color=always '' | fzf --ansi \
    --delimiter=':' --preview 'bat --color=always --highlight-line {2} {1}') &&
    ${EDITOR:-vim} "+$(echo $line | cut -d: -f2)" "$(echo $line | cut -d: -f1)"
}
Learn these two and you stop thinking about file paths. The repo becomes a keyboard-navigable index.

Discussion

(0)

Join the first cohort. Unlock badges.

Sign In to Comment