Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在vim和tmux中开启真彩色 #8

Open
huaizhixu opened this issue Dec 9, 2022 · 0 comments
Open

在vim和tmux中开启真彩色 #8

huaizhixu opened this issue Dec 9, 2022 · 0 comments

Comments

@huaizhixu
Copy link
Owner

在 vim 和 tmux 中开启真彩色,可以获得更好的视觉体验。

在 vimrc 中加入下面的设置:

if exists('+termguicolors')
  let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
  let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
  set termguicolors
endif

Tmux 需要在 .tmux.conf 配置文件里添加下面的内容:

set -g default-terminal tmux-256color  # 这里也可设置成 screen-256color
set-option -ga terminal-overrides ",*256col*:Tc"

退出所有的 tmux,再重新打开,就可以了。

如何验证 true color 是否开启成功?验证 vim 的话,在 vim 里用 :terminal 命令打开自带的终端,执行下面的命令1

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";
}'

验证 tmux,则打开 tmux 后直接在命令行执行上面的命令。

如果显示的是连续的颜色,则已经开启成功;

如果是间断的颜色,则设置失败。

参考链接

  1. https://gist.github.com/XVilka/8346728 ↩︎
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant