-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Checklist
- I have read through the manual page (
man fzf) - I have searched through the existing issues
- For bug reports, I have checked if the bug is reproducible in the latest version of fzf
Output of fzf --version
0.66.1
OS
- Linux
- macOS
- Windows
- Etc.
Shell
- bash
- zsh
- fish
Problem / Steps to reproduce
In zsh, the default Ctrl-T widget (fzf-file-widget from shell/key-bindings.zsh) always searches relative to $PWD and appends the selection(s) to the end of $LBUFFER.
This makes Ctrl‑T awkward when the cursor is already inside a path prefix (common workflow):
- Type:
cat /dirB/pa - Press Ctrl‑T
- Ctrl‑T still searches from $PWD, and appends results to the end (instead of completing/replacing
paunder/dirB/).
Related discussion: #2791
In that thread, the suggested solution is to use fuzzy completion / dedicated completion key (e.g. /dirB/**<TAB>), which works but uses a different keybinding and a different mechanism than Ctrl‑T. I’d like Ctrl‑T
itself to handle the “path prefix is present” case.
Proposed behavior (zsh Ctrl‑T)
When Ctrl‑T is invoked and the current token (under cursor) looks like a path prefix:
- Treat the directory part as the search root
- Seed fzf’s initial query with the basename fragment already typed
- Replace the token under cursor with the selected path(s) (rather than appending to the end of LBUFFER)
Examples:
cat /dirB/<C-t>should search under/dirBcat /dirB/pa<C-t>should search under/dirBwith initial querypa, and replacepawith the selected entry/entries
When there is no path prefix, keep current behavior unchanged.
Implementation sketch
fish already does something similar by parsing the current token into (dir, query, prefix) and invoking fzf with --walker-root=$dir --query=$query (see shell/key-bindings.fish).
For zsh, a minimal/opt-in approach could be:
- detect the current token (ideally under cursor; at minimum, last whitespace-delimited token)
- if it contains a valid dir prefix, pass
--walker-root+--queryaccordingly - replace the token under cursor with selections
If changing default Ctrl‑T behavior is undesirable, this could be guarded behind an opt-in env var (default off) that switches fzf-file-widget into this “path-prefix aware” mode.