Support regular expressions in copy mode search

53 views
Skip to first unread message

Anindya Mukherjee

unread,
Nov 11, 2019, 3:16:18 PM11/11/19
to tmux-users
Hi, I often find myself typing regular expressions in copy mode search only to realise that they are not supported. Of course, one could just rerun the command with grep or similar, i.e., there is often a workaround. However, I wonder how desirable is it to have regexp support directly in tmux. I for one would find it useful.

I'd love to give it a try if no one is working on it! It seems the current search is matching grid cell by cell, essentially char by char. So it might not be trivial. I noticed it's a "medium" todo. Thoughts?

Thanks!

Nicholas Marriott

unread,
Nov 11, 2019, 3:34:25 PM11/11/19
to Anindya Mukherjee, tmux-users
Sure. I think you need to stringify each line and do the regex search, the difficulty will be to map the result back to the cells for highlighting, but you could do that just by repeating the stringify process until you meet the cell that matches the start point of the search.



--
You received this message because you are subscribed to the Google Groups "tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/tmux-users/CAN%2Bi5iN5LKAmoqasRJGe9yQVymQXW_0cxr64PuvCfTwwBMrpEQ%40mail.gmail.com.

Anindya Mukherjee

unread,
Nov 11, 2019, 3:59:59 PM11/11/19
to Nicholas Marriott, tmux-users
Thank you! Also, I noticed that if I have a line which wraps thereby breaking up a string, then the search in copy mode does not find it, as a result of the line by line approach to searching. When the pane or window is resized to accommodate the string all on a single line, search finds and highlights it. This is a bit counter intuitive; if this was vi or less with a narrow display the string would still be found.

Nicholas Marriott

unread,
Nov 12, 2019, 5:03:27 AM11/12/19
to Anindya Mukherjee, tmux-users
Yes that's how it works at the moment.

Anindya Mukherjee

unread,
Nov 12, 2019, 11:27:13 AM11/12/19
to Nicholas Marriott, tmux-users
Thanks for clarifying!

Nicholas Marriott

unread,
Nov 12, 2019, 11:50:22 AM11/12/19
to Anindya Mukherjee, tmux-users
If you are adding regex search it would be a perfect opportunity to
fix that also :-).

On Tue, 12 Nov 2019 at 16:27, Anindya Mukherjee <anin...@gmail.com> wrote:
>
> Thanks for clarifying!

Anindya Mukherjee

unread,
Nov 12, 2019, 12:29:18 PM11/12/19
to Nicholas Marriott, tmux-users
Yes my thoughts exactly :D

Anindya Mukherjee

unread,
Nov 20, 2019, 3:59:43 PM11/20/19
to Nicholas Marriott, tmux-users
Following up, is it desirable to add a new command to do regexp search and leave the old commands as they are? This would mean window_copy_regexp_search_... variants of some of the existing functions and associated UI hookup.

I was able to fix the line wrapped search issue mentioned above, still doing character wise comparison, of course. Wondering if it deserves a separate commit to the existing search infrastructure?

Thanks!

Nicholas Marriott

unread,
Nov 20, 2019, 4:01:02 PM11/20/19
to Anindya Mukherjee, tmux-users
I think search-forward/backward should change to use regexps but incremental should not.

Anindya Mukherjee

unread,
Nov 21, 2019, 2:07:39 AM11/21/19
to Nicholas Marriott, tmux-users
Thanks! So say I start a / or Ctrl-S search with the regular expression "a..d", to pick a concrete example. If the text has multiple matches such as "axxd", "ayzd", they will all be highlighted. Then if the user presses n, incremental search runs with the first exact match, in this case "axxd". So in this case all "axxd" will be highlighted and "ayzd" will not. Basically incremental will run with the first match encountered using that as the search string (not regexp). Does that make sense?

Nicholas Marriott

unread,
Nov 21, 2019, 3:09:01 AM11/21/19
to Anindya Mukherjee, tmux-users
No that is not incremental search, that is search-again, it should use regexps. Incremental search is search-forward-incremental where it updates the search every time you change the search term not only when you press Enter. Try C-r with mode-keys set to Emacs.

Anindya Mukherjee

unread,
Nov 21, 2019, 10:44:36 AM11/21/19
to Nicholas Marriott, tmux-users
Ah great, sorry I misunderstood. That makes sense, thanks!

Anindya Mukherjee

unread,
Nov 24, 2019, 1:43:14 PM11/24/19
to Nicholas Marriott, tmux-users
Hi, in vi the incremental search is regex aware by default (unless we use the nomagic option), while in emacs we can do C-r for non-regex and C-Meta-r for regex incremental search. The latter is actually quite useful, and I wonder if we can add this mode to tmux as well. Apart from a slight refactoring it should not be too much additional trouble to implement.

Best,
Anindya

Nicholas Marriott

unread,
Nov 24, 2019, 1:45:56 PM11/24/19
to Anindya Mukherjee, tmux-users
If you want to add it, go for it, but the default C-r needs to stay
non-regexp like emacs.

I suggest doing these changes in pieces rather than in one go.

Thanks

Anindya Mukherjee

unread,
Nov 24, 2019, 2:16:00 PM11/24/19
to Nicholas Marriott, tmux-users
Agreed, thank you! I'm just trying things out at the moment on my spare time to see what's feasible. I'll add incremental regex once the basic stuff works and is accepted. C-r will have the existing emacs behaviour, of course.
Reply all
Reply to author
Forward
0 new messages