6

I like to have two sessions/sets of windows side-by-side, with independent windows switching, like on the screenshot - right now I do that by launching two separate Konsole instances, each with tmux attach -t session_name_here, and AwesomeWM just puts them side by side, like any X client.

This way of achieving this kind of layout has some drawbacks, mostly around portability:

  1. It requires X, so, it cannot be used from "pure" Linux console
  2. It can be not so nice to do in other environments with non-tiling WMs (like KDE or MacOS X)

Can similar be done purely with tmux, without relying on any external application?

And how?

two sessions/windows side by side

Update: made the part about independent switching of windows bold

3 Answers3

8

Launch a tmux instance, then do Ctrl+b % to split the pane vertically. To switch between the panes use Ctrl+b arrow key

neofug
  • 205
  • 1
    But then you cannot switch windows independently for each pane, can you? – Ivan Kolmychek May 03 '16 at 20:43
  • Not sure what you mean; in a terminal environment (no X) you have a single 'window'. For a gui alternative to achieve what you want you might try Terminator (https://launchpad.net/terminator) – neofug May 03 '16 at 20:54
  • 1
    In tmux session, by tmux terminology, you can have multiple windows inside a session - you can see them listed on screenshot, right after the session name for both sessions there are 5 windows, only two of them are active, one per session. If you split the window to two panes, only that window will be affected, and when you switch to the other window (by pressing perfix - window number, for instance, or with command select-window -t), the split will not be present on the window you swtiched to. – Ivan Kolmychek May 03 '16 at 20:59
6

You could use nested tmux sessions:

┌───────────────────┐
│ ┌──────┐ ┌──────┐ │
│ │      │ │      │ │
│ │      │ │      │ │
│ │tmux 2│ │tmux 3│ │
│ └──────┘ └──────┘ │
│ tmux 1            │
└───────────────────┘

It's rather clumsy (e.g. involving prefixprefixn to switch the "inner" windows), but in recent tmux versions the status bar can indicate which instance is being controlled right now. For example, my configuration has:

set -g status-bg colour233
set -g status-fg colour250
set -g status-left "#{?client_prefix,#[fg=colour180]=#[fg=default], }#S "
set -g status-right "%b %d, %H:%M "
setw -g window-status-format ' #I #W '
setw -g window-status-current-format '#{?client_prefix,#[fg=colour0]#[bg=colour180],} #I #W '
setw -g window-status-current-bg colour166
setw -g window-status-current-fg colour0
setw -g window-status-activity-bg colour166
setw -g window-status-activity-fg colour233

(#{?client_prefix} requires tmux ≥ v1.6)

u1686_grawity
  • 452,512
  • Nice suggestion, thanks. I guess, you can also launch the "outside" tmux with different config file, including different prefix and you can also disable the status bar in it, so it would be like seamless. Let me make sure that it works all right and then accept this answer. – Ivan Kolmychek May 04 '16 at 08:13
  • Yes, it works ok, setting the "outer" tmux prefix and hiding its status panel makes it almost seamless. The only issue that I've encountered with this kind of setup for now is that colors in the "inside" tmux are messed up a little bit, but that's the separate question I think. – Ivan Kolmychek May 04 '16 at 08:27
  • 1
    set -g default-terminal "tmux-256color"; set -ga terminal-overrides ",tmux-256color:Tc" – u1686_grawity May 04 '16 at 08:29
  • should this be set for outer or inner tmux instance? – Ivan Kolmychek May 04 '16 at 08:37
  • after setting this the colors are still messed up, tried to set it in outer session config, inner session config and both. – Ivan Kolmychek May 04 '16 at 09:45
  • Maybe your tmux version is a bit older and only has the screen-256color terminfo? (It seems tmux-256color doesn't come on Debian even with the backported 2.2 for some reason…) Make sure the setting actually takes effect, by checking $TERM. – u1686_grawity May 04 '16 at 09:49
3

Alternative approach: Flip the whole thing upside-down – switch from Vim to Neovim, use :terminal, and have your terminals inside vim split windows:

enter image description here

(The default shortcut to exit terminal-input mode is C-\ C-n, or you could click another buffer.)

u1686_grawity
  • 452,512
  • That would work too, but it requires additional app and may not be suitable for all use cases - for instance, I'm more used to have different vim instances in different windows, the tmux nesting would be less painful in that setup as you have to remap less hotkeys in the outer instance. – Ivan Kolmychek May 04 '16 at 08:34