While using tmux in iTerm2 (both normally and using -CC native integration), I noticed that tmux window is of a different style compared to the original iTerm2 window. Specifically, the color theme (Material) is preserved as I see (deep blue background of a window), but the command line itself (hence, I suppose this is oh-my-zsh configs) are not preserved. See the picture attached.
I'd like to know why, and how to make them of one style.
iTerm2 original window:
tmux window inside iTerm2:
When using touchpad, my palms tend to trigger a slight mouse scroll, so I've disable mouse altogether in tmux using set -g mouse off. When I do this, however, mouse-wheel events will scroll history instead of scrolling the window. It only does this inside tmux (if I detach, the behavior goes away). Anyone know how to disable this? I'm using Arch Linux and Gnome Terminal.
Problem: "C-b left/right" key combination is not switching between panes in tmux, it is resizing the pane.
tmux version: 1.8
OS: BackBox 4.4
Tried to find the 'tmux.conf' in the home directory or in the '/etc' folder, no success.
Archwiki says that left/right keys are for resizing panes. Ok, so if that's the case how ill I move between panes?
C-b-<left> resizes the pane while C-b <left> switches pane. So you need to release C-b before pressing <left> to be able to do the switch.
Are there any options to control the background color of the active or inactive panes in Tmux?
It seems that tmux-2.1 (released 18 October 2015) now allows the colours of individual panes to be specified. From the changelog:
* 'select-pane' now understands '-P' to set window/pane background colours.
e.g. [from the manual] to change pane 1's foreground (text) to blue and background to red use:
select-pane -t:.1 -P 'fg=blue,bg=red'
To mimic iTerm colour scheme:
To answer the original question, I use the following lines in my ~/.tmux.conf for setting the background/foreground colours to mimic the behaviour in iTerm:
#set inactive/active window styles
set -g window-style 'fg=colour247,bg=colour236'
set -g window-active-style 'fg=colour250,bg=black'
# set the pane border colors
set -g pane-border-style 'fg=colour235,bg=colour238'
set -g pane-active-border-style 'fg=colour51,bg=colour236'
I hadn't seen the window-style and window-active-style commands before, but maybe they were available in previous tmux versions.
Also, these two lines are pretty useful for splitting panes easily:
bind | split-window -h
bind - split-window -v
EDIT: as Jamie Schembri mentions in the comments, tmux version 2.1 (at least) will now be installed with:
brew install tmux
EDIT (Oct 2017): brew now installs tmux 2.6, and the above still works.
EDIT Vim panes: If you find that the "inactive colouring" does not work with a Vim pane, it might be due to the colourscheme you are using. Try with the pablo scheme; i.e. in the Vim pane:
:colo pablo
To make it work with your own custom Vim colourscheme, make sure that the setting for Normal highlighting does not have ctermbg or guibg specified. As an example, the "inactive colouring" does not work with the murphy colourscheme, because in murphy.vim there is the line:
hi Normal ctermbg=Black ctermfg=lightgreen guibg=Black guifg=lightgreen
that sets ctermbg or guibg to Black. However, changing this line to:
hi Normal ctermfg=lightgreen guifg=lightgreen
will make the "inactive colouring" work.
EDIT July 2019 Augusto provided a good suggestion for also changing the background colour for the line numbers. What I use in my vim colourscheme is the following (you need to find and edit the colourscheme file):
hi Normal guifg=#e6e1de ctermfg=none gui=none
hi LineNr guifg=#e6e1de ctermfg=none gui=none
There is no option to change the background color of a pane, but there is option to set the pane-border color (style)
pane-active-border-style style
Set the pane border style for the currently active
pane. For how to specify style, see the message-command-style option.
Attributes are ignored.
pane-border-style style
Set the pane border style for paneas aside from the
active pane. For how to specify style, see the message-command-style option.
Attributes are
ignored.
I like this variation of https://stackoverflow.com/a/33553372:
# Make sure your 16-color terminal theme uses slightly
# different colors for `background` vs `black` (AKA `color0`).
# "Nord" or "Tango dark" themes do this out of the box.
# Use `white` instead of `black` for light themes.
set -g window-active-style 'fg=terminal,bg=terminal'
set -g window-style 'fg=terminal,bg=black'
set focus-events on
set-hook -g client-focus-in "set window-active-style 'fg=terminal,bg=terminal'"
set-hook -g client-focus-out "set window-active-style 'fg=terminal,bg=black'"
The last three lines may require a recent version of tmux (I use tmux 3.3),
and mark all panes inactive when the terminal window is not focused. I am not sure if set focus-events on is necessary. The lack of -g inside the hook is important (the subtle bug that prevents is left as an exercise to a reader interested in tmux arcana).
You can, of course, use a different window-style (e.g. brightblack, or fg=white,bg=black).
Older answer (a different approach)
Since tmux 3.3 (released Jun 1, 2022, so it may not have propagated to all distributions yet), there are new options to help disambiguate which pane is active (though these don't change the background color specifically):
# I find this together with default coloring of the active pane border sufficient
set -g pane-border-lines heavy
# More explicit options that I find a bit excessive
set -g pane-border-lines number
set -g pane-border-indicators both # Displays arrows pointing to the current pane.
On version 3.1, you can set hooks on pane focus in or out. You must set focus-events to 'on' first.
In a combination of dean.'s answer and user21952-is-a-great-name's answer, the pane-focus-out hook fires on the pane that you are moving out of, and you set the background and foreground appropriately - I used a slightly dimmer color scheme. The pane-focus-in hook then fires on the pane that is getting focus, and I set the colors both to default.
I didn't bother setting a target on select-pane as it seems to work without it, but there is an option for {last} (or {!}) according to the wiki.
set -g focus-events on
set-hook -g pane-focus-out 'select-pane -P bg=colour0,fg=colour10'
set-hook -g pane-focus-in 'select-pane -P bg=default,fg=default'
This appears to work in my terminal but does not affect colors of an open Vim session. It also fires when I scroll up, it seems the copy mode also unsets focus.
# highlight focused pane (tmux >= 2.1), possible values are:
# - true
# - false (default)
tmux_conf_theme_highlight_focused_pane=true
# focused pane colours:
#tmux_conf_theme_focused_pane_fg='default'
tmux_conf_theme_focused_pane_bg='#191919'
I'm not sure it this is possible but I use a graphical terminal emulator that has a translucent background so I can see the GUI windows behind it (in this case tinted a shade of blue). I want my status Line to have this as its background color.
I was able to find this useful example: http://jasonwryan.com/blog/2010/01/07/tmux-terminal-multiplexer/
And it used the color default.
so what I wanted was:
set status-bg default
EDIT: this might not work in newer versions of tmux, see other answers below
The accepted answer from olleicua (to be more specific, the comment from sammy) stopped working for me as of tmux 3.2.
I changed the line to the following and now it's working again:
set-option -g status-style bg=default
The "3.2 questions and comments" thread on the official github page explains why this is the case:
status-fg and status-bg are now applied before status-style rather than instead of; this means that if either is set to default the status-style colour will be used. To fix, replace status-bg default with status-style bg=default.