alacritty / alacritty

A cross-platform, OpenGL terminal emulator.
https://alacritty.org
Apache License 2.0
53.72k stars 2.94k forks source link

vi mode search wrap #7976

Closed bebecue closed 2 weeks ago

bebecue commented 2 weeks ago

Searching in vi mode wraps around

for example, search for foo and press n to go to next match

foo1
bar1
foo2
^
bar2

press n again

foo1
^
bar1
foo2
bar2

^ is the highlighted match

in vim, set nowrapscan will disable wrapping around and stop at the last match. This can be useful while searching from long-running command's output in terminal.

The same behavior can be achieved by pipeing to a pager like less and then searching from that. However, it doesn't work if the interested command is already running.

So it wound be nice if alacritty provides this function natively.

After some digging, I found it seems alacritty will always wraps around while searching at here

Will this feature also be useful to someone else?

chrisduerr commented 2 weeks ago

Will this feature also be useful to someone else?

I think this is the key point here. I don't think it's worth it to add an option for that, but it should be simple to patch if you want it changed. If there's some huge interest I might reconsider, but I doubt that.

bebecue commented 2 weeks ago

Just in case someone also want this, Here is the patch I got it working.

diff --git a/alacritty_terminal/src/term/search.rs b/alacritty_terminal/src/term/search.rs
index 585e191c..b4f4e8e2 100644
--- a/alacritty_terminal/src/term/search.rs
+++ b/alacritty_terminal/src/term/search.rs
@@ -156,6 +156,8 @@ impl<T> Term<T> {
             _ => end.sub(self, Boundary::None, 1),
         };

+        end.line = self.bottommost_line();
+
         let mut regex_iter = RegexIter::new(start, end, Direction::Right, self, regex).peekable();

         // Check if there's any match at all.