1

When I bring up the scrollback buffer (enter copy mode) and press ? I can enter text and search backwards through the buffer. However I can't work out how to paste something previously added to the paste buffer into the search field. I can paste from the system buffer but often the contents of the TMUX buffer is what I want to search for.

When I try pasting from the buffer (for me its C-]) nothing appears. However if I exit copy mode the buffer pastes just fine.

Does anyone know if this is possible?

2
  • Not the most satisfying answer but here's a description of a workaround involving system clipboard: unix.stackexchange.com/a/731838/111090
    – raindev
    Commented Sep 26, 2023 at 21:19
  • Thanks @raindev; I'd rather not use the system clipboard, but it's good to learn new things about TMUX. Also I don't use a window manager (I'm CLI only) so I don't have access to the xclip utiliy.
    – Scott
    Commented Sep 29, 2023 at 3:52

1 Answer 1

-1

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?

Not the answer you're looking for? Browse other questions tagged or ask your own question.