terminal - Vim: Difference between t_Co=256 and term=xterm-256color in conjunction with TMUX -


i testing various different terminals tend use ssh linux boxes have tmux set on.

basically noticed behavior, , hoping offer explanation of what's going on. may case specific behavior affects prompt app.

i using vim within tmux, , on panic's prompt app on iphone5 having behavior 256 colors not enabling when .vimrc set colors using set t_co=256 directive. here, vim correctly displaying colors when not run through tmux. also, os x's terminal.app correctly rendered colors (i did not test putty on windows unfortunately) vim in tmux.

then swapped out set t_co=256 set term=xterm-256color , colors work when using vim through tmux.

note tested both set -g default-terminal "xterm-256color" , set -g default-terminal "screen-256color" settings tmux , change had no effect on behavior.

when don't use tmux or screen, need configure terminal emulators advertise "capable of displaying 256 colors" setting term xterm-256color or comparable value works terminals , platforms. how depend on terminal emulator , outside of scope of question , answer.

you don't need in vim it's capable right thing itself.

when use tmux or screen, programs set own default value $term, screen, , vim has info given.

if want more uniform (and colorful) behavior, must configure them use "better" value $term:

  • tmux

    add line ~/.tmux.conf:

    set -g default-terminal "screen-256color" 
  • screen

    add line ~/.screenrc:

    term "screen-256color" 

now, both multiplexers tell vim support 256 colors , vim expect do.

edit

my answer assumes able edit configuration files but, since able edit ~/.vimrc, don't think i'm far off mark.

edit 2

the value of term option (retrieved &term) name of terminal picked vim upon startup. name supposed setup in terminal emulator itself.

the value of t_co option (&t_co) vim considers maximum number of colors can displayed host terminal. defined according entry corresponding $term in terminfo:

 term            | t_co -----------------+------   xterm           | 8  xterm-256color  | 256  screen          | 8  screen-256color | 256 

when vim starts up, gets value of term environment variable, queries terminfo database value , stores number of informations on environment in several t_… variables among which… number of colors available in t_co. given "legal" terminal type (one vim can lookup), vim always assumes correct number of colors.

setting t_co 256 while leaving term vim-defined value — or, more generally, setting t_co and/or term values don't match host terminal — makes no sense , create troubles when vim sends signal not understood terminal or vice-versa.

while entirely possible so, messing t_co , term in vim both totally useless , possibly harmful.

again, setup terminal emulators , terminal multiplexers correctly. that's really need.

if end in terminal multiplexer or terminal emulator can't define correct term, , can force vim assume 256 colors. end, changing value of t_co thing makes sense:

if &term == "screen"   set t_co=256 endif 

so… if can configure each individual part:

  • terminal emulator: xterm-256color
  • tmux/screen: screen-256color
  • vim: nothing

and done.

if can't control every part, use simple conditional in ~/.vimrc set t_co according &term don't change value of term.

but if can edit ~/.vimrc there's no reason can't edit ~/.screenrc or ~/.tmux.conf or ~/.bashrc or whatever.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -