惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
阮一峰的网络日志
阮一峰的网络日志
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
博客园 - 司徒正美
Last Week in AI
Last Week in AI
爱范儿
爱范儿
罗磊的独立博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
雷峰网
雷峰网
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
Jina AI
Jina AI
人人都是产品经理
人人都是产品经理
量子位
V
V2EX
博客园 - 叶小钗
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN
Set up true color for nvim and tmux in Zoc terminal and x...
2021-03-17 · via jdhao's digital space

In my daily work, I often ssh to a remote server using a terminal emulator. My local machine is a Windows 10 desktop. In this post, I want to share how to make true color work across terminal emulator, nvim and tmux.

Pick a suitable terminal emulator#

Not all terminal emulators support true colors. First, we need to use a terminal emulator that supports true colors. Both zoc terminal and xshell can support this.

To test whether true color works or not, run the following script on the command line:

awk 'BEGIN{
    s="/\\/\\/\\/\\/\\"; s=s s s s s s s s;
    for (colnum = 0; colnum<77; colnum++) {
        r = 255-(colnum*255/76);
        g = (colnum*510/76);
        b = (colnum*255/76);
        if (g>255) g = 510-g;
        printf "\033[48;2;%d;%d;%dm", r,g,b;
        printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b;
        printf "%s\033[0m", substr(s,colnum+1,1);
    }
    printf "\n";
}'

If you can see a smooth color band, then true color has been activated successfully.

Enable true color in terminal emulator#

In zoc terminal, true color support is enabled by default. Previously, true color support is missing in xshell. The latest version of xshell (xshell 7) has added support for true color, but this feature is disabled by default.

To enable true color support in xshell, go to Tools --> Options, click the Advanced Tab page, under Terminal section, check the box Use true color. We need to restart xshell to activate this feature. Open a source code file using nvim, you should see that true color is working properly.

Make true color work with tmux and nvim#

However, if we use nvim inside tmux, the colorscheme is still not right. In order to make true color work inside tmux, we need a few more configuration.

Set TERM environment variable#

The correct way to set the TERM variable is via the terminal emulators.

For zoc terminal, go to Options --> Edit Session Profile. Click Emulations, in the left, choose Xterm from the list of emulations. Check TERM box below, and set it to xterm-256color. On the right, also check the box 256 color support (TERM=xterm-256color).

For xshell, edit the properties of current session (File --> Current Session Properties). Click the Terminal category, and change Terminal Type to xterm-256color.

Restart the current connection. Run command echo $TERM to verify that TERM varialbe has been correctly set to xterm-256color.

Configure tmux#

Open tmux config (in $HOME/.tmux.conf) and add the following settings:

# True color settings, see https://jdhao.github.io/2018/10/19/tmux_nvim_true_color/ for the details.
set -g default-terminal "screen-256color"

# If terminal supports true color, use the following options.
set -ga terminal-overrides ",xterm-256color*:Tc"

After these two steps, kill tmux server and start a new tmux session:

tmux kill-server
tmux new -s "test"

Then start nvim, your colorscheme1 should work properly now.