brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: in tmux copy mode, / searches forward and ? searches backward

Tmux
~/tips/tip-tmux-copy-mode-search

/error # search forward for 'error'

Finds text in a tmux pane's scrollback after Ctrl-b [, with n for the next match.

Scrollback is only useful if you can find things in it.

Ctrl-b [     # enter copy mode
/error        # search forward for 'error'
n            # next match
q            # leave

In the default emacs-style keys, Ctrl-s and Ctrl-r do the same job. After set -g mode-keys vi the slash keys work the way vi users expect.

Entering copy mode with Ctrl-b [ is the way to look at history. Searching inside it saves a lot of scrolling, especially in a long log. Type the search term after the slash, press Enter and tmux jumps to the first match, with the rest reachable by n and N.

The match is highlighted in the pane. If you have chosen vi keys with set -g mode-keys vi, you also get g and G to go to the top and bottom, and Space and Enter to select and copy.

The search covers the history limit only. With the default of 2000 lines, an older match is already gone.

Try it in a throwaway session: tmux new -s scratch, and close it afterwards with tmux kill-session -t scratch.

Further reading: tmux manual page (OpenBSD, official), tmux wiki: Getting Started (official), On this site: tmux capture-pane -p dumps the pane's text to stdout, On this site: tmux capture-pane -p dumps a pane's scrollback to a file

More Tmux tips tmux new -d -s report -x 200 -y 50 'top' tmux wait-for build-done set -g allow-passthrough on tmux kill-server Ctrl-b [ All Tmux tips (125) All topics

Link