Fuzzy Filter lines in files ( helm-swoop ) #38606
Replies: 4 comments 4 replies
-
|
For the interested, achieving the swoop feature with Television (and Nushell): {
"label": "Find in File",
"command": "bat --style=numbers --color=always --theme=TwoDark --paging=never $env.ZED_FILE | tv --ansi --input-header=$\"($env.ZED_RELATIVE_FILE)\" | ansi strip | str trim | split row \" \" | first | zeditor $\"($env.ZED_FILE):($in)\"",
"hide": "always",
"allow_concurrent_runs": true,
"use_new_terminal": true,
"shell": { "program": "nu" }
} |
Beta Was this translation helpful? Give feedback.
-
|
This is super awesome; thank you. I find it useful to also have one that pipes from {
"label": "find git files",
"command": "git ls-files | fzf --multi --preview 'bat --color=always --line-range=:100 {}' --reverse --input-border=rounded --info=inline-right | xargs -I{} zed {}",
"use_new_terminal": true,
"allow_concurrent_runs": false,
"reveal": "always",
"hide": "always",
"shell": { "program": "bash" }
},Also, I added |
Beta Was this translation helpful? Give feedback.
-
|
I completely updated the original post. Swoop now goes directly to the beginning of the word, and file previews are improved. It also now properly supports selected text as the initial input. |
Beta Was this translation helpful? Give feedback.
-
|
thanks for posting this! I originally found a feature like this in LiteXL. the 'go to line' action is a fuzzy search by line text, and I always really enjoyed that. it is using ripgrep for the search so it is exact matches only. i managed to put a task together that uses fzf for fuzzy searching lines and i am very happy with how it works thanks for the inspiration! #!/bin/sh
rg --line-number --color=always --colors 'match:none' . "$ZED_FILE" | \
fzf \
--query "$ZED_SELECTED_TEXT" \
--ansi \
--height=100% \
--border=none \
--info=inline-right \
--delimiter : \
--bind="enter:become(
parse_column {q} {1};
)"# parse_column()
query="$1"
line="$2"
first="${query:0:1}"
text=$(sed -n "${line}p" "$ZED_FILE")
idx=1
for (( i=0; i<${#text}; i++ )); do
if [[ "${text:$i:1}" == "$first" ]]; then
idx=$(expr $i + 1)
break
fi
done
zed "$ZED_FILE:$line:$idx"
i couldn't get it working just writing the script in the task json. there were too many issues with quotations. so both of these have to be in your path to get this to work. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Inspired by @baldwindavid in #22581. And following up on the telescope feature request #8279.
I'm sharing 2 tasks I created that both use a combination of fzf and bat. These both work well enough for me in place of a built in telescope in zed.
Swoop is essentially, fuzzy filtering the lines in a file and jumping to it. The name and pattern is inspired by an emacs package - helm-swoop - that I started using over a decade ago. I find the pattern to be more intuitive and faster in general than searching in most cases. This pattern may also go a long way to scratch the itch for the people (myself included) that want either #4930 or #14801. I use the builtin vim sneak functionality for precise movement to the beginning of a word on screen, and then this swoop pattern for larger motions in a file.
In this demo, the first commands are swoop, and the latter are find files.
EDIT: I completely updated this. Swoop now goes directly to the beginning of the word, and file previews are improved. It also now properly supports selected text as the initial input.
These require the following script to be available in your PATH:
fzf-bat-preview
Ensure this in script is available in your PATH. I put this in:
~/.local/bin/fzf-bat-previewHere is the
tasks.json. Take any one or all 3 of these related tasks.{ "label": "swoop", "env": { "RG_PREFIX": "rg --column --line-number --no-heading --color=always --smart-case" }, "command": "fzf --ansi --disabled --wrap --list-border=bottom --input-border=rounded --preview-border=rounded --header='\n' --info=inline-right --height=100% --prompt=\"$ZED_FILENAME > \" --border=rounded --border-label=\"Swoop\" --bind \"start:reload:${RG_PREFIX} {q} \"$ZED_FILE\"\" --bind \"change:reload:sleep 0.001; ${RG_PREFIX} {q} \"$ZED_FILE\" || true\" --delimiter : --with-nth '1,3..' --preview \"FZF_PREVIEW_CONTEXT=10 echo && fzf-bat-preview \"$ZED_FILE\" {1}\" --preview-window='down,50%,noinfo' --preview-label=\"$ZED_FILENAME\" --bind 'enter:become(zed \"$ZED_FILE\":{1}:{2})' --query ${ZED_SELECTED_TEXT:\"\"}", "use_new_terminal": true, "allow_concurrent_runs": true, "reveal": "always", "hide": "always", "shell": { "program": "sh" } }, { "label": "find file", "command": "( rg --files --hidden --follow --glob '!.git/*'; rg --files --hidden --no-ignore --glob '*.env*' ) | fzf --ansi --border-label=\"find file\" --no-scrollbar --border=rounded --wrap --preview-window='down,50%,noinfo' --preview 'echo && bat --style=numbers --theme=TwoDark --color=always --line-range=:50 {}' --height=100% --header=\"\n\" --margin=1 --list-border=bottom --bind 'result:transform-preview-label:echo {1}' --bind 'focus:transform-preview-label:echo {1}' --bind 'enter:become(zed {1})' --reverse --input-border=rounded --info=inline-right", "use_new_terminal": true, "allow_concurrent_runs": true, "reveal": "always", "hide": "always", "shell": { "program": "sh" } }, { "label": "search", "env": { "RG_PREFIX": "rg --column --line-number --no-heading --color=always --smart-case --hidden -g '!.git/**'" }, "command": "fzf --ansi --disabled --border=rounded --no-scrollbar --border-label=\"Search in project\" --input-border=rounded --info=inline-right --wrap --height=100% --list-border=bottom --header=\"\n\" --bind \"start:reload:${RG_PREFIX} {q}\" --bind \"change:reload:sleep 0.001; ${RG_PREFIX} {q} || true\" --delimiter : --with-nth '1,4..' --preview-window='down,50%,noinfo' --preview-label-pos=0,top --preview \"echo && fzf-bat-preview {1} {2}\" --bind 'result:transform-preview-label:echo {1}' --bind 'focus:transform-preview-label:echo {1}' --bind 'enter:become(zed {1}:{2}:{3})' --query ${ZED_SELECTED_TEXT:\"\"}", "use_new_terminal": true, "allow_concurrent_runs": true, "reveal": "always", "hide": "always", "shell": { "program": "sh" } },And
keymap.jsonSome tips that I've found related to this:
"reveal_target": "center"works well for an in-window display and"reveal_target": "dock"works well for the entire window. Conceptually, for in file scoped operations and project scoped operations respectively. This is demoed in the video above.shas the shell program makes for faster startup time and minimal latency when using these commands.Open to feedback, improvements and discussion. Hope this helps someone!
Original config for reference
Here is the
tasks.json{ "label": "swoop", "command": "bat --style=numbers --color=always --theme=TwoDark --paging=never $ZED_FILE | fzf --ansi --tiebreak=index --layout=reverse --input-border=rounded --info=inline-right --height=100% --border=rounded --margin=4 --color=bg+:#262930 --header=\"\n\" --prompt=\"$ZED_FILENAME > \" | awk '{print $1}' | xargs -I{} zed $ZED_FILE:{}", "use_new_terminal": true, "allow_concurrent_runs": true, "reveal": "always", "hide": "always", "shell": { "program": "sh" } }, { "label": "find file", "command": "fzf --preview 'bat --style=numbers --theme=TwoDark --color=always --line-range=:100 {}' --height=100% --header=\"\n\" --margin=4 --reverse --input-border=rounded --info=inline-right | xargs -I{} zed {}", "use_new_terminal": true, "allow_concurrent_runs": true, "reveal": "always", "hide": "always", "shell": { "program": "sh" } }And
keymap.jsonBeta Was this translation helpful? Give feedback.
All reactions