Checklist
Output of fzf --version
0.66.1
OS
Shell
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
pa under /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 /dirB
cat /dirB/pa<C-t> should search under /dirB with initial query pa, and replace pa with 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 + --query accordingly
- 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.
Checklist
man fzf)Output of
fzf --version0.66.1
OS
Shell
Problem / Steps to reproduce
In zsh, the default Ctrl-T widget (
fzf-file-widgetfromshell/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):
cat /dirB/papaunder/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‑Titself 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:
Examples:
cat /dirB/<C-t>should search under/dirBcat /dirB/pa<C-t>should search under/dirBwith initial querypa, and replacepawith the selected entry/entriesWhen 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(seeshell/key-bindings.fish).For zsh, a minimal/opt-in approach could be:
--walker-root+--queryaccordinglyIf changing default Ctrl‑T behavior is undesirable, this could be guarded behind an opt-in env var (default off) that switches
fzf-file-widgetinto this “path-prefix aware” mode.