Introduce and Setup Tmux

2020-01-21

This article is a bit old and the content may be outdated, so please refer to it with caution and remember to check the latest official materials (such as documentation, etc.)

Setup and introduce Tmux so that I can use it

Cheat Sheet #

Tmux cheatsheet

Image source is in the image

Enable 256 color vim #

From https://superuser.com/a/1459904

First, outside tmux, you need:

export TERM=xterm-256color
bash

in .tmux.conf:

set -g default-terminal "screen-256color"
bash

And don't forget to source config manually:

tmux source-file ~/.tmux.conf
bash

All above make sure tmux have full 256 colors support.

And in your vimrc, add:

if exists("$TMUX")
    set t_Co=256
    set notermguicolors
else
    set termguicolors
endif
vim

Enable True Color for vim #

From https://github.com/tmux/tmux/issues/1246 and https://github.com/lifepillar/vim-solarized8#troubleshooting

Basically,

let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
vim

will do the trick.

Resize Panes on Keyboard #

You may just use mouse though

This assumes that you've hit ctrl + b and : to get to the command prompt

:resize-pane -D (Resizes the current pane down)
:resize-pane -U (Resizes the current pane upward)
:resize-pane -L (Resizes the current pane left)
:resize-pane -R (Resizes the current pane right)
:resize-pane -D 10 (Resizes the current pane down by 10 cells)
:resize-pane -U 10 (Resizes the current pane upward by 10 cells)
:resize-pane -L 10 (Resizes the current pane left by 10 cells)
:resize-pane -R 10 (Resizes the current pane right by 10 cells)
text

Border Chaos #

If I split the panes vertically, the first column of the right pane is overwritten by the border.

chaos

It turns out to be the old problem with MinTTY. As you can see on the top-middle of the screenshot, the border is displayed in full width (2 chars), with introduced the chaos.

To solve it, inspired by https://github.com/mintty/mintty/issues/615, all you need to do is Options → Text → Locale: C (Or any language with sane character width). And the broken vim airline is solved too!

fixed

Leave your comments and reactions on GitHub