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
在这里插入图片描述

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

效果:

在这里插入图片描述

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

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

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • datagrip在线激活码[免费获取]

    (datagrip在线激活码)2021最新分享一个能用的的激活码出来,希望能帮到需要激活的朋友。目前这个是能用的,但是用的人多了之后也会失效,会不定时更新的,大家持续关注此网站~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月21日
    279
  • Django(23)Django限制请求装饰器

    Django(23)Django限制请求装饰器前言有时候,我们想要限制访问的请求方法,比如我们希望用户只能通过get方式请求,post不允许,那么我们可以采用装饰器的方式,django已经为我们提供了内置的装饰器限制请求装饰器Django内

    2022年7月30日
    9
  • 正则表达式(.*?)惰性匹配()

    正则表达式(.*?)惰性匹配()没什么可说的看这儿就行了,,特别是最后一条。1、.匹配任意除换行符“\n”外的字符;2、*表示匹配前一个字符0次或无限次;3、+或*后跟?表示非贪婪匹配,即尽可能少的匹配,如*?重复任意次,但尽可能少重复;4、.*?表示匹配任意数量的重复,但是在能使整个匹配成功的前提下使用最少的重复。如:a.*?b匹配最短的,以a开始,以b结束的字符串。如果把它应用于aabab的话,它会匹配aab……

    2022年7月15日
    20
  • 净推荐值NPS(Net Promoter Score)[通俗易懂]

    净推荐值NPS(Net Promoter Score)[通俗易懂]净推荐值净推荐值(NetPromoterScore,NPS)目录[隐藏]1什么是净推荐值2净推荐值的理论基础[3]3净推荐值的计算4净推荐值的意义5净推荐值的评析6净推荐值在企业中的应用分析[3]7企业通过净推荐值提高客户忠诚度的主要步骤[5]8净推荐值提高客户忠诚度的实证分析[5]9净推荐值应用实例10参考文献[编辑]什么是净推荐值  净推荐值(N…

    2022年6月12日
    33
  • pymssql 中文乱码_pycharm输出中文乱码

    pymssql 中文乱码_pycharm输出中文乱码开门见山,先放解决问题的代码SELECTCONVERT(NVARCHAR,test_field)AStest_fieldFROMtest_tableWHEREtest_condition=’测试中文’–直接将中文字段test_field(VARCHAR)转化为NVARCHAR,其他类型同理,转换成N开头的类型接下来才是其他可能可行的解决方案:使用其他库,如pyodbc(详细信息请阅读相关文档),可参考:https://blog.csdn.net/zhaogeno1/art

    2025年6月30日
    4
  • kalilinuxarp攻击_linux开启转发

    kalilinuxarp攻击_linux开启转发arpspoof-iwlan0-t10.50.129.4410.50.128.1arpspoof-iwlan0-t10.50.128.110.50.128.197mkdirtmp_picsdriftnet-iwlan0-dtmp_pics转载于:https://www.cnblogs.com/albertofwb/articles/4901195.ht…

    2022年9月26日
    1

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

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