Why tmux window in iterm2 has different appearance? - tmux

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:

Related

Move/Resize Variables Explorer in VSCode Jupyter Notebook

How can I customize the location and size of the Variables Tab in VSCode so I can move it to a split screen?
If that is not possible, how can I run 2 instances of VSCode with the same kernel so the variable explorer only eats up space in the second screen? Is there a better workaround than this?

How to map a tmux command (prev,next window) to a mouse button (left,right)

I have a mouse with two additional left/right buttons, and on Ubuntu they work fine in Firefox for next/prev page in history, and in Sublime Text 3 for left/right tab (with this .sublime-mousemap config file).
I would like the same kind of behavior in tmux...
Unfortunately, I didn't find any way of mapping a tmux command (tmux next-window, tmux previous-window) to a mouse button (not left/right click or the wheel, but an other button). The manual does not evoke it, nor this answer for example.
Does any one has a trick for this? Thanks.
So tmux (currently) does not support these extra mouse buttons, and it seems hard to implement their support in tmux's current architecture.
Sadly, I think the only answer that can be given right now is a negative one : it is not possible to bind a tmux command to an extra mouse button.

Vifm background of highlighting changes inside tmux

I am using vifm inside tmux on Ubuntu 14.10. It looks great outside of tmux but inside tmux I have a problem with a highlighting line. I had almost the same problem with vim (vim in tmux background color changes when paging) but after applying :set t_ut= it works now.
Here is how vifm looks inside tmux (the highlighting line is supposed to take a whole line)
The value of $TERM inside tmux session was xterm-256color. I changed it to screen-256color. Now it works. Thanks #xaizek for the hint.

Change background color of active or inactive pane in Tmux

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'

set tmux/R window background color when using Vim-R

I'm using MacVim and Vim-R to interactively edit and run R code. Everything seems to be working fine, but I can't seem to figure out how to set the background color in the tmux window that R runs in.
To be precise: I open up a .r file with MacVim. Then I type _rf, which causes XQuartz to start up, and a window with the title 'tmux' to open up with R running inside of it. When I highlight lines of code and send them to R from MacVim, everything seems to work fine. But the default background color of the tmux window is white, which makes the nicely colored output text hard to read.
How can I change the background color of the tmux window to something darker?
See this part of the doc to force your plugin to use the right terminal emulator.
If you don't want to do that (I think that you should), you can configure the appearance of xterm in the ~/.Xresources file. This guide gives you useful examples.

Resources