In my tmux version 3.2a, there are indeed preset search keys (# and *) under copy-mode-vi.
bind-key -T copy-mode-vi \# send-key -FX search-backward "#{copy_cursor_word}"
bind-key -T copy-mode-vi * send-key -FX search-forward "#{copy_cursor_word}"
However, if these settings work well, there is no need to discuss them :) They make use of #{copy_cursor_word} directly as the search target, but what if the text at the cursor is a continuous entire paragraph of text (such as the value of a cmake variable)? So, you still need to perfect it. If you do this kind of search often, you'll understand that it's not that simple. We need a more precise search.
Version 1
bind-key -T copy-mode-vi \\ command-prompt -I "#{copy_cursor_word}" -p "(search up)" "send -X search-backward \"%%%\""
You can change the hotkey '\' to the appropriate key value in your tmux configuration environment.
Through this definition, you can edit the content captured by tmux and submit the search keywords you care about.
The poster did raise a good question. Maybe some readers don't realize that this is a problem in extreme environments — the first thing that comes to mind is the "system clipboard". However, at this moment, tmux is the system itself and graphics systems may not exist yet :)
I just focused on this issue. Under improvement, for reference only.
My similar working scenario is: The shell searches for keywords in files under a specific path, and then tmux traverses the values of key variables in the shell search results. The default copy-mode-vi search of tmux requires manually entering keywords — there is no way to paste easily under a pure tty environment IMHO (let’s say a linux console mode — no mouse, no GUI). Therefore, An alternative method adopted — selecting keywords in the shell search results (version 1) — this is currently not ideal and is being improved.
Improved version after introducing shell script:
Version 2
bind-key -T copy-mode-vi \\ run-shell 'tmux command-prompt -I "$(tmux show-buffer)" -p "(search up)" "send -X search-backward \"%%%\""'
A question arises here: If the copied content is a tmux script, will it seem to be executed? For example, in man tmux
#{?pane_in_mode,#[fg=white#,bg=red],#[fg=red#,bg=white]}#W .
When you yank this text under copy-mode-vi, the search box will not display anything. If it's plain-text, there's no problem.
So, version 1 isn't as bad as it looks, right?
Version 3
bind-key -T copy-mode-vi y run 'tmux send-keys -X copy-pipe "wl-copy" ; tmux set -q @buffer_content "$(tmux show-buffer)"'
bind-key -T copy-mode-vi \\ command-prompt -I '#{@buffer_content}' -p '(search up)' 'send -X search-backward "%%%"'
bind-key : command-prompt -I '#{@buffer_content}' -p '>'
This version avoids the problems of the first two versions (but still does not implement the paste action itself). I apply it to two situations: whether copying screen content into the "copy-mode-vi" mode search box or the line editor of the "command-prompt" mode interactive window, it is based on the same logic: define an additional @buffer_content to store the latest buffer variable, it will be automatically pasted into the currently executing line editor in its original form. You can edit and submit the content normally for further processing.
A related discussion
How can I search within the output buffer of a tmux shell?
xclip
utiliy.