This is the fzf incantation I use most. I can’t bring myself to put it in a shell function because the pleasure is in typing it out each time.
rg -l --no-ignore 'TODO' | fzf --preview 'bat --color=always --line-range :80 {}'
In plain English: use ripgrep to list every file that contains the word TODO, then feed that list into fzf. Every time I highlight a file in the left pane, the preview pane on the right runs bat on it with syntax highlighting, showing the first 80 lines. I can narrow by typing more of the filename, press Enter to pick, and then open it in my editor.
Notice how in the cast I start by highlighting internal/tui/model.go, see “TODO: virtualise the event list” in the preview, then type tui to narrow. fzf’s fuzzy matching picks the exact file I want without me needing to type the whole path. Enter prints the filename, and then $EDITOR ... +42 jumps me to the right line.
The --no-ignore is there because I want to include gitignored files — generated code sometimes has interesting TODOs too. If you don’t want that, drop it.
Callouts:
- Preview commands get the highlighted filename via
{}. You can also use{+}for multiple selections. --preview-window right:60%is a flag I sometimes add when the preview content is wide.- bat with
--color=always --line-range :80is the right form inside a preview — it respects terminal colors and doesn’t try to page.
If you combine this with --bind 'enter:become(...)' you can skip the editor-command step and just launch straight in. I don’t do that because I like seeing the filename print.