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

推荐订阅源

J
Java Code Geeks
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
博客园 - 三生石上(FineUI控件)
Hugging Face - Blog
Hugging Face - Blog
博客园 - Franky
云风的 BLOG
云风的 BLOG
I
InfoQ
小众软件
小众软件
Last Week in AI
Last Week in AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
大猫的无限游戏
大猫的无限游戏
A
About on SuperTechFans
Stack Overflow Blog
Stack Overflow Blog
The Cloudflare Blog
雷峰网
雷峰网
P
Proofpoint News Feed
腾讯CDC
H
Help Net Security
V
Visual Studio Blog
美团技术团队
F
Fortinet All Blogs
MongoDB | Blog
MongoDB | 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.