broot icon indicating copy to clipboard operation
broot copied to clipboard

Context lines for content matches

Open 9999years opened this issue 2 years ago • 2 comments

When searching file content with c/..., I can open the preview pane and then cycle through matches, but I only get the exact line that matched. I'd really like to have the matching line centered in a regular preview and to be able to cycle through the matches that way. Alternatively, having n lines of context before and after the match (like rg) would be nice.

9999years avatar Oct 09 '23 20:10 9999years

In the same vein, this might require separate verbs for previous_match_in_file and next_match_in_file, as this would make line_up and line_down operate on file lines rather than match lines.

9999years avatar Oct 09 '23 20:10 9999years

Right now, the way to cycle is to do another ctrl-right to see the text at the match position, then ctrl-left to see all matches. I describe it there: https://dystroy.org/blog/broot-c-search/

But cycling with a key is an interesting idea that I should try.

Canop avatar Oct 10 '23 05:10 Canop

A configurable option for $n$ lines of context would really help. For my use case, I often deal with Markdown files, which have nested lists. Just seeing the child item isn't very helpful without also seeing the line above.

stevenxxiu avatar Apr 02 '24 02:04 stevenxxiu

You mean when a file containing one or several matches is selected, you'd like to initially have in the right panel not just the matching lines but to have them surrounded by some context ?

(this may have been the initial request and I didn't understand it)

Canop avatar Apr 02 '24 07:04 Canop

You mean when a file containing one or several matches is selected, you'd like to initially have in the right panel not just the matching lines but to have them surrounded by some context ?

Yes that's what I mean. I believe this was the initial request. So see $n$ lines before and after the matching line.

stevenxxiu avatar Apr 02 '24 07:04 stevenxxiu

@9999years @stevenxxiu Can you check PR https://github.com/Canop/broot/pull/866 ?

Canop avatar Apr 06 '24 15:04 Canop

@stevenxxiu Why did you remove your comment ? It made sense to me.

Canop avatar Apr 08 '24 15:04 Canop

Ah I just moved it to the PR.

stevenxxiu avatar Apr 08 '24 15:04 stevenxxiu