XeIte
XeIte

Reputation: 197

How to scroll in nested tmux?

Sometimes, I have to use nested tmux session (tmux in tmux). Scrolling by copy-mode does not work in inner tmux session, so it makes me very inconvenient in inner session.

I heard there is meta-key to send tmux command to inner session. Any effective key bind to scroll in inner session?

Upvotes: 5

Views: 1065

Answers (2)

Andrew
Andrew

Reputation: 982

I had this issue too but realized my local tmux.conf was using vi keybindings for copy-mode and my remote (nested) session wasn't. You can use vi keybindings for both sessions by adding the following to your local and remote tmux.conf.

# Use vim keybindings in copy mode
setw -g mode-keys vi

Then either do prefix + prefix + [ to enter copy-mode in the nested session and use vi keybindings to move around, or you could map a certain keystroke to send the prefix to the nested session by putting this in your local tmux.conf:

# Use Ctrl-a to send prefix to nested session
bind-key -n C-a send-prefix

Upvotes: 1

Fernando Cordeiro
Fernando Cordeiro

Reputation: 403

tmux copy-mode will do it. Running the command will change to copy-mode in the inner session, and you can scroll as usual.

Another option is using bind and send-prefix, to bind some key to the send-prefix action, which sends the prefix to a nested session. In my case, it is:

set -g prefix C-a
bind a send-prefix

The default prefix is C-b, in that case it may be more reasonable to use b.

With that, you just Control+A (Or B or whatever) and then release Control and hit the same key again (A in my case, B seems better for people using the default C-b prefix, IMHO). That sends the prefix to the inner session. And now whatever you press will trigger a command in the inner session. i.e.: [Control+A] then [%] splits the window vertically for me. That's in the outer session, of course. Then with the send-prefix binding I mentioned, I can do [Control+A] then [A] then [%], and it splits the window in the inner session.

It's pretty nifty, useful for scrolling stuff, searching etc when connected to a server, and once you get used to it it becomes pretty much muscle-memory. Plus you can do [Ctrl+A] then [A] then [D] to detach the inner session, which will either let you exit an ssh connection or end the SSH connection entirely if you have a configuration that automaGically start tmux upon connecting.

And of course, you can bind send-prefix to some other key, possibly with -n so you can have something like [Ctrl+A] as the prefix and something like [Ctrl+S] to send the prefix to an inner session.

Upvotes: 2

Related Questions