tmux 如何自定义背景颜色 | How does the tmux color palette work?

tmux 如何自定义背景颜色 | How does the tmux color palette work?坑1:256colorsupportforvimbackgroundintmuxhttps://superuser.com/questions/399296/256-color-support-for-vim-background-in-tmux原因Fromthelookofyour.bashrcand.profile,theshellsinsidetmuxareoverridingthe‘default-terminal’settinginyour

大家好,又见面了,我是你们的朋友全栈君。

坑1:256 color support for vim background in tmux

解决终端颜色配置与 tmux 颜色配置不匹配问题。

https://superuser.com/questions/399296/256-color-support-for-vim-background-in-tmux

原因

From the look of your .bashrc and .profile, the shells inside tmux are overriding the ‘default-terminal’ setting in your tmux conf. Something like this:

  • tmux creates new shell with TERM=screen-256color
  • .bashrc/.profile run, set TERM=xterm-256color
  • vim runs, tries to use incorrect TERM for tmux

you can check this by running

echo $TERM

in a fresh tmux shell.

Tmux is relatively picky about having a terminal set correctly. If you can, set the term value in gnome-terminal’s configuration, not in your .bashrc. Failing that, surround those settings with a check for “screen” or “screen-256color” TERM, and don’t reset them in that case.

Tmux REALLY wants the terminal set to screen or screen-256color

解决方法

This is what worked for me in #Ubuntu and #Mac:

# File: ~/.bashrc (Ubuntu), ~/.bash_profile (Mac)
# for VIM and TMUC
if [ "$TERM" = "xterm" ]; then
  export TERM=xterm-256color
fi
alias tmux='tmux -2'  # for 256color
alias tmux='tmux -u'  # to get rid of unicode rendering problem

Reload settings:

$ source ~/.bashrc # Ubuntu

$ source ~/.bash_profile # Mac

Set up .bashrc for Mac (as it is used by tmux)

# File: ~/.bashrc (Mac)
source ~/.bash_profile

Set up “default-terminal” option in ~/.tmux.conf.

# File: ~/.tmux.conf
set -g default-terminal "screen-256color"  # Mac and Ubuntu

坑 2:Change background color of active or inactive pane in Tmux

详解 .tmux.conf 配置文件设置背景颜色的方法。其中,fg 是字体颜色,bg 是背景颜色。

https://newbedev.com/change-background-color-of-active-or-inactive-pane-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'

坑 3:Reloading tmux config

写完配置文件后,需要手动 source 使其生效。

https://blog.sanctum.geek.nz/reloading-tmux-config/,Posted on 2012-03-19

If you have made changes to your tmux configuration file in the ~/.tmux.conf file, it shouldn’t be necessary to start the server up again from scratch with kill-server. Instead, you can prompt the current tmux session to reload the configuration with the source-file command.

This can be done either from within tmux, by pressing Ctrl+B and then : to bring up a command prompt, and typing:

:source-file ~/.tmux.conf

Or simply from a shell:

$ tmux source-file ~/.tmux.conf

This should apply your changes to the running tmux server without affecting the sessions or windows within them.

This entry was posted in Tmux and tagged configuration, reload, source, source-file, tmux.conf by Tom Ryder. Bookmark the permalink.


附:tmux 配置中的 colour0~255 颜色表

You can create it with for i in {0..255}; do printf "\x1b[38;5;${i}mcolor%-5i\x1b[0m" $i ; if ! (( ($i + 1 ) % 8 )); then echo ; fi ; done
在这里插入图片描述

配置文件:
在这里插入图片描述

效果:

在这里插入图片描述

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/151786.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • vue.js开发环境搭建

    vue.js开发环境搭建

  • Groupid(artifact id)

    什么是groupid和artifactId?groupid和artifactId被统称为“坐标”是为了保证项目唯一性而提出的,如果你要把你项目弄到maven本地仓库去,你想要找到你的项目就必须根据这两个id去查找。groupId和artifactId是maven管理项目包时用作区分的字段,就像是地图上的坐标。artifactId:artifactId一般是项目名或者模块名。group…

  • jqueryajax实例代码_什么叫实例

    jqueryajax实例代码_什么叫实例Jquery在异步提交方面封装的很好,直接用AJAX非常麻烦,Jquery大大简化了我们的操作,不用考虑浏览器的诧异了。推荐一篇不错的jQueryAjax实例文章,忘记了可以去看看,地址为:http://www.cnblogs.com/yeer/archive/2009/07/23/1529460.html和http://www.w3school.com.cn/jquery

  • MyBatis模糊查询的4种实现方式

    MyBatis模糊查询的4种实现方式1、根据姓名模糊查询员工信息1.1、方式一步骤一:编写配置文件步骤二:测试步骤三:分析此种方式需要在调用处手动的去添加“%”通配符。1.2、方式二说明:使用方式一可以实现模糊查询,但是有一点不方便的地方就是:在测试类中,调用selectList()方法传参时需要调用者手动的添加%号通配符,显然是麻烦的,能否在映射配置文件中直接将%号写好呢?有的朋友可能会这么想,好办,直接在配置文件中这么写:形如1:测试后发现,程序会报错,原因是:缺少单引号。这…

    2022年10月28日
  • vim中保存退出_文档没保存就关了怎么恢复

    vim中保存退出_文档没保存就关了怎么恢复保存命令按ESC键跳到命令模式,然后::w保存文件但不退出vi:wfile将修改另外保存到file中,不退出vi:w!强制保存,不推出vi:wq保存文件并退出vi:wq!强制保存文件,并退出viq:不保存文件,退出vi:q!不保存文件,强制退出vi:e!放弃所有修改,从上次保存文件开始再编辑

  • _beginthread, _beginthreadex

    _beginthread, _beginthreadex语法uintptr_t_beginthread(//NATIVECODEvoid(__cdecl*start_address)(void*),unsignedstack_size,void*arglist);uintptr_t_beginthread(//MANAGEDCODEvoid(__clrcall*start_add…

    2022年10月31日

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号