neovim / neovim

Vim-fork focused on extensibility and usability
https://neovim.io
Other
82.83k stars 5.67k forks source link

CheckHealth: ERROR: $TERM differs from the tmux `default-terminal` setting. Colors might look wrong. #7353

Closed yangmillstheory closed 7 years ago

yangmillstheory commented 7 years ago

Steps to reproduce using nvim -u NORC

nvim -u NORC
:CheckHealth

Actual behaviour


health#nvim#check
========================================================================
## Configuration
  - SUCCESS: no issues found

## Performance
  - SUCCESS: Build type: Release

## Remote Plugins
  - SUCCESS: Up to date

## terminal
  - INFO: key_backspace (kbs) terminfo entry: key_backspace=^H
  - INFO: key_dc (kdch1) terminfo entry: key_dc=\E[3~

## tmux
  - SUCCESS: escape-time: ^[]4;236;rgb:32/30/2f^[\^[]4;234;rgb:1d/20/21^[\^[]4;235;rgb:28/28/28^[\^[]4;237;rgb:3c/38/36^[\^[]4;239;rgb:50/49/45^[\^[]4;241;rgb:66/5c/54^[\^[]4;243;rgb:7c/6f/64^[\^[]4;244;rgb:92/83/74^[\^[]4;245;rgb:92/83/74^[\^[]4;228;rgb:f2/e5/bc^[\^[]4;230;rgb:f9/f5/d7^[\^[]4;229;rgb:fb/f1/c7^[\^[]4;223;rgb:eb/db/b2^[\^[]4;250;rgb:d5/c4/a1^[\^[]4;248;rgb:bd/ae/93^[\^[]4;246;rgb:a8/99/84^[\^[]4;167;rgb:fb/49/34^[\^[]4;142;rgb:b8/bb/26^[\^[]4;214;rgb:fa/bd/2f^[\^[]4;109;rgb:83/a5/98^[\^[]4;175;rgb:d3/86/9b^[\^[]4;108;rgb:8e/c0/7c^[\^[]4;208;rgb:fe/80/19^[\^[]4;88;rgb:9d/00/06^[\^[]4;100;rgb:79/74/0e^[\^[]4;136;rgb:b5/76/14^[\^[]4;24;rgb:07/66/78^[\^[]4;96;rgb:8f/3f/71^[\^[]4;66;rgb:42/7b/58^[\^[]4;130;rgb:af/3a/03^[\1ms
  - INFO: $TERM: xterm-256color
  - INFO: default-terminal: ^[]4;236;rgb:32/30/2f^[\^[]4;234;rgb:1d/20/21^[\^[]4;235;rgb:28/28/28^[\^[]4;237;rgb:3c/38/36^[\^[]4;239;rgb:50/49/45^[\^[]4;241;rgb:66/5c/54^[\^[]4;243;rgb:7c/6f/64^[\^[]4;244;rgb:92/83/74^[\^[]4;245;rgb:92/83/74^[\^[]4;228;rgb:f2/e5/bc^[\^[]4;230;rgb:f9/f5/d7^[\^[]4;229;rgb:fb/f1/c7^[\^[]4;223;rgb:eb/db/b2^[\^[]4;250;rgb:d5/c4/a1^[\^[]4;248;rgb:bd/ae/93^[\^[]4;246;rgb:a8/99/84^[\^[]4;167;rgb:fb/49/34^[\^[]4;142;rgb:b8/bb/26^[\^[]4;214;rgb:fa/bd/2f^[\^[]4;109;rgb:83/a5/98^[\^[]4;175;rgb:d3/86/9b^[\^[]4;108;rgb:8e/c0/7c^[\^[]4;208;rgb:fe/80/19^[\^[]4;88;rgb:9d/00/06^[\^[]4;100;rgb:79/74/0e^[\^[]4;136;rgb:b5/76/14^[\^[]4;24;rgb:07/66/78^[\^[]4;96;rgb:8f/3f/71^[\^[]4;66;rgb:42/7b/58^[\^[]4;130;rgb:af/3a/03^[\
  - ERROR: $TERM differs from the tmux `default-terminal` setting. Colors might look wrong.
    - SUGGESTIONS:
      - $TERM may have been set by some rc (.bashrc, .zshrc, ...).

health#provider#check
========================================================================
## Clipboard (optional)
  - SUCCESS: Clipboard tool found: pbcopy

## Python 2 provider (optional)
  - INFO: `g:python_host_prog` is not set.  Searching for python2 in the environment.
  - INFO: Executable: /usr/local/bin/python2
  - INFO: Python2 version: 2.7.13
  - INFO: python2-neovim version: 0.1.13
  - SUCCESS: Latest python2-neovim is installed: 0.1.13

## Python 3 provider (optional)
  - INFO: `g:python3_host_prog` is not set.  Searching for python3 in the environment.
  - INFO: Executable: /usr/local/bin/python3
  - INFO: Python3 version: 3.6.1
  - INFO: python3-neovim version: 0.1.13
  - SUCCESS: Latest python3-neovim is installed: 0.1.13

## Ruby provider (optional)
  - INFO: Ruby: ^[]4;236;rgb:32/30/2f^[\^[]4;234;rgb:1d/20/21^[\^[]4;235;rgb:28/28/28^[\^[]4;237;rgb:3c/38/36^[\^[]4;239;rgb:50/49/45^[\^[]4;241;rgb:66/5c/54^[\^[]4;243;rgb:7c/6f/64^[\^[]4;244;rgb:92/83/74^[\^[]4;245;rgb:92/83/74^[\^[]4;228;rgb:f2/e5/bc^[\^[]4;230;rgb:f9/f5/d7^[\^[]4;229;rgb:fb/f1/c7^[\^[]4;223;rgb:eb/db/b2^[\^[]4;250;rgb:d5/c4/a1^[\^[]4;248;rgb:bd/ae/93^[\^[]4;246;rgb:a8/99/84^[\^[]4;167;rgb:fb/49/34^[\^[]4;142;rgb:b8/bb/26^[\^[]4;214;rgb:fa/bd/2f^[\^[]4;109;rgb:83/a5/98^[\^[]4;175;rgb:d3/86/9b^[\^[]4;108;rgb:8e/c0/7c^[\^[]4;208;rgb:fe/80/19^[\^[]4;88;rgb:9d/00/06^[\^[]4;100;rgb:79/74/0e^[\^[]4;136;rgb:b5/76/14^[\^[]4;24;rgb:07/66/78^[\^[]4;96;rgb:8f/3f/71^[\^[]4;66;rgb:42/7b/58^[\^[]4;130;rgb:af/3a/03^[\ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
  - INFO: Host: /usr/local/bin/neovim-ruby-host
  - SUCCESS: Latest "neovim" gem is installed: ^[]4;236;rgb:32/30/2f^[\^[]4;234;rgb:1d/20/21^[\^[]4;235;rgb:28/28/28^[\^[]4;237;rgb:3c/38/36^[\^[]4;239;rgb:50/49/45^[\^[]4;241;rgb:66/5c/54^[\^[]4;243;rgb:7c/6f/64^[\^[]4;244;rgb:92/83/74^[\^[]4;245;rgb:92/83/74^[\^[]4;228;rgb:f2/e5/bc^[\^[]4;230;rgb:f9/f5/d7^[\^[]4;229;rgb:fb/f1/c7^[\^[]4;223;rgb:eb/db/b2^[\^[]4;250;rgb:d5/c4/a1^[\^[]4;248;rgb:bd/ae/93^[\^[]4;246;rgb:a8/99/84^[\^[]4;167;rgb:fb/49/34^[\^[]4;142;rgb:b8/bb/26^[\^[]4;214;rgb:fa/bd/2f^[\^[]4;109;rgb:83/a5/98^[\^[]4;175;rgb:d3/86/9b^[\^[]4;108;rgb:8e/c0/7c^[\^[]4;208;rgb:fe/80/19^[\^[]4;88;rgb:9d/00/06^[\^[]4;100;rgb:79/74/0e^[\^[]4;136;rgb:b5/76/14^[\^[]4;24;rgb:07/66/78^[\^[]4;96;rgb:8f/3f/71^[\^[]4;66;rgb:42/7b/58^[\^[]4;130;rgb:af/3a/03^[\0.5.1

Expected behaviour

Passing health check?


I've been trying for a couple of hours to fix this. TrueColor is working inside tmux

image

so I'm not sure why the health check is failing.

jamessan commented 7 years ago

The health check is complaining about your $TERM, not anything to do with colors.

The only valid $TERM values that should be used with tmux are variants of screen or tmux. If you have a new enough tmux and terminfo database, then you should probably use tmux-256color, otherwise screen-256color.

What the healthcheck is trying to tell you is that your $TERM doesn't match what tmux had been configured to advertise for $TERM, so you're most likely overriding it in your shell's init file. That's a bad idea.

yangmillstheory commented 7 years ago

Thanks for the explanation; I'm not solid on the many moving parts here. I use alacritty with xterm-256color and setting the $TERM variable in Alacritty (the default there is actually xterm-256color).

Would you recommend setting $TERM only if $TMUX is set? Or set it globally in my shell?

jamessan commented 7 years ago

You should never set $TERM from your shell config. A shell can be used from many terminals.

Your terminal should set $TERM.

Can you post the output of these commands?

tmux show-option -qvg default-terminal tmux show-option -qvgs default-terminal

yangmillstheory commented 7 years ago

(I actually meant "terminal" instead of "shell" above.)

🤔 /U/VictorAlvarez
[i]: tmux -V
tmux 2.5

🤔 /U/VictorAlvarez
[i]: tmux show-option -qvg default-terminal

🤔 /U/VictorAlvarez
[i]: tmux show-option -qvgs default-terminal
tmux-256color
jamessan commented 7 years ago

Ok. You have a recent tmux which changed the type of option that default-terminal is. :CheckHealth in 0.2.0 didn't know about this, so it sees an empty string as the configured terminal for tmux.

This was fixed in #6348.

yangmillstheory commented 7 years ago

I picked up the latest nightly build for that fix, but looks like it's actually in 0.2.0 (which I was running): https://github.com/neovim/neovim/blob/v0.2.0/runtime/autoload/health/nvim.vim#L133

So tmux_default_term !=# $TERM is true, but $TERM and tmux_default_term look the same:

In nvim :echo $TERM gives tmux-256color as does tmux show-option -qvgs default-terminal in tmux.

jamessan commented 7 years ago

What does :echo system('tmux show-option -qvgs default-terminal') show?

yangmillstheory commented 7 years ago
^[]4;236;rgb:32/30/2f^[\^[]4;234;rgb:1d/20/21^[\^[]4;235;rgb:28/28/28^[\^[]4;237;rgb:3c/38/36^[\^[]4;239;rgb:50/49/45^[\^[]4;241;rgb:66/5c/54^[\^[]4;243;rgb:7c/6f/64^[\^[]4;244;rgb:92/83/74^[\^[]4;245;rgb:92/83/74^[\^[]4;228;rgb:f2/e5/bc^[\^[]4;230;rgb:f9/f5/d7^[\^[]4;229;rgb:fb/f1/
c7^[\^[]4;223;rgb:eb/db/b2^[\^[]4;250;rgb:d5/c4/a1^[\^[]4;248;rgb:bd/ae/93^[\^[]4;246;rgb:a8/99/84^[\^[]4;167;rgb:fb/49/34^[\^[]4;142;rgb:b8/bb/26^[\^[]4;214;rgb:fa/bd/2f^[\^[]4;109;rgb:83/a5/98^[\^[]4;175;rgb:d3/86/9b^[\^[]4;108;rgb:8e/c0/7c^[\^[]4;208;rgb:fe/80/19^[\^[]4;88;rgb:9d
/00/06^[\^[]4;100;rgb:79/74/0e^[\^[]4;136;rgb:b5/76/14^[\^[]4;24;rgb:07/66/78^[\^[]4;96;rgb:8f/3f/71^[\^[]4;66;rgb:42/7b/58^[\^[]4;130;rgb:af/3a/03^[\tmux-256color

...

jamessan commented 7 years ago

Ok... so why are we getting the color escape codes back when running a command that's not attached to a tty? That sounds like a possible tmux bug to me.

jamessan commented 7 years ago

Did you recently upgrade tmux?

yangmillstheory commented 7 years ago

Last night I did a brew upgrade neovim to pick up the latest release (although I had it already). That's when I started seeing the errors.

yangmillstheory commented 7 years ago

When I run :echo system('tmux show-option -qvgs default-terminal') outside of tmux, I get the same output...

jamessan commented 7 years ago

When I run :echo system('tmux show-option -qvgs default-terminal') outside of tmux,

I'd expect that. Neovim is running the same command, the same way. The problem appears to be that the tmux command is including RGB escape sequences in the output, which it shouldn't be doing, especially when its output isn't to a terminal.

Maybe someone from @tmux can chime in here?

yangmillstheory commented 7 years ago

I think this is related: https://github.com/neovim/neovim/issues/6015

Might be able to close this as a duplicate as I'm experiencing basically the same issue. My default shell is zsh.

The workaround suggested there also works for me, but I'd upvote this proposed solution: https://github.com/neovim/neovim/issues/6015#issuecomment-275426019

mhinz commented 7 years ago

Could you please check if you get the same behaviour with iTerm2 v3.x?

iTerm because I think that Terminal.app still doesn't support true colors:

$ printf "\x1b[38;2;255;100;0mTRUECOLOR█\x1b[0m\n"

And maybe post your tmux configu somewhere. :)

yangmillstheory commented 7 years ago

Iterm2 Build 3.1.beta.3

image

I get the weird output with :echo system('tmux show-option -qvgs default-terminal') when set shell=/bin/bash is commented out in my .vimrc.

$ cat ~/.tmux.conf
# remap prefix key
set -g prefix C-a
unbind C-b
bind C-a send-prefix

# splitting panes with | and -
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"

bind a setw synchronize-panes

# windows
bind-key C-s last-window
bind C-p previous-window
bind C-n next-window

# quick pane resizing
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

# some global options
set -g mouse on
# enable true color
# set -g default-terminal "xterm-256color"
# set -ga terminal-overrides ",xterm-256color:Tc"
set -g default-terminal "tmux-256color"
set -ga terminal-overrides ",tmux-256color:Tc"
set -g display-time 4000
set -s escape-time 1
set -g base-index 1
set -g pane-base-index 1
set -g visual-activity on
set -g default-shell "/bin/zsh"
set -g default-command "reattach-to-user-namespace -l /bin/zsh"
setw -g automatic-rename off
setw -g monitor-activity off
setw -g clock-mode-style 12
setw -g mode-keys vi

# bind .tmux.conf reloading
bind r source-file ~/.tmux.conf; display "Reloaded!"

# make vim copy mode work on mac
bind-key -Tcopy-mode-vi 'v' send -X begin-selection
bind-key -Tcopy-mode-vi 'y' send -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy > /dev/null 2>&1"
unbind p
bind p paste-buffer

# fzf + tmux
#
# https://github.com/junegunn/fzf/wiki/Examples#tmux
unbind 0
unbind w
bind-key 0 run "tmux split-window -l 12 'bash -ci ftpane'"
bind-key w run -b ftwind

# https://github.com/tmux-plugins/tmux-yank#requirements
#
#   need this for tmux-fingers!
set-clipboard on
set-option -g default-command "reattach-to-user-namespace -l $SHELL"

# https://github.com/christoomey/vim-tmux-navigator#tmux
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n ˙ if-shell "$is_vim" "send-keys ˙"  "select-pane -L"
bind-key -n ∆ if-shell "$is_vim" "send-keys ∆"  "select-pane -D"
bind-key -n ˚ if-shell "$is_vim" "send-keys ˚"  "select-pane -U"
bind-key -n ¬ if-shell "$is_vim" "send-keys ¬"  "select-pane -R"
bind-key -n « if-shell "$is_vim" "send-keys «"  "select-pane -l"
bind-key -T copy-mode-vi ˙ select-pane -L
bind-key -T copy-mode-vi ∆ select-pane -D
bind-key -T copy-mode-vi ˚ select-pane -U
bind-key -T copy-mode-vi ¬ select-pane -R
bind-key -T copy-mode-vi « select-pane -l

# plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'Morantron/tmux-fingers'
set -g @fingers-key F
set -g @fingers-compact-hints 0
set -g @fingers-copy-command "reattach-to-user-namespace pbcopy > /dev/null 2>&1"
run '~/.tmux/plugins/tpm/tpm'

source-file ~/.tmux-gruvbox-dark.tmux

On regular vim I don't get the garbled output when running the same command (on Iterm and Alacritty).

🤔 /U/VictorAlvarez
[i]: echo $TERM
tmux-256color

🤔 /U/VictorAlvarez
[i]: /usr/local/bin/vim
Error detected while processing /Users/VictorAlvarez/.vimrc:
line  434:
E518: Unknown option: inccommand=split
Press ENTER or type command to continue

🤔 /U/VictorAlvarez
[i]: /usr/local/bin/vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled May 25 2017 08:55:37)
MacOS X (unix) version
Included patches: 1-604
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl             +file_in_path    +mouse_sgr       +tag_old_static
+arabic          +find_in_path    -mouse_sysmouse  -tag_any_white
+autocmd         +float           +mouse_urxvt     -tcl
-balloon_eval    +folding         +mouse_xterm     +termguicolors
-browse          -footer          +multi_byte      +terminfo
++builtin_terms  +fork()          +multi_lang      +termresponse
+byte_offset     -gettext         -mzscheme        +textobjects
+channel         -hangul_input    +netbeans_intg   +timers
+cindent         +iconv           +num64           +title
-clientserver    +insert_expand   +packages        -toolbar
+clipboard       +job             +path_extra      +user_commands
+cmdline_compl   +jumplist        +perl            +vertsplit
+cmdline_hist    +keymap          +persistent_undo +virtualedit
+cmdline_info    +lambda          +postscript      +visual
+comments        +langmap         +printer         +visualextra
+conceal         +libcall         +profile         +viminfo
+cryptv          +linebreak       +python          +vreplace
+cscope          +lispindent      -python3         +wildignore
+cursorbind      +listcmds        +quickfix        +wildmenu
+cursorshape     +localmap        +reltime         +windows
+dialog_con      -lua             +rightleft       +writebackup
+diff            +menu            +ruby            -X11
+digraphs        +mksession       +scrollbind      -xfontset
-dnd             +modify_fname    +signs           -xim
-ebcdic          +mouse           +smartindent     -xpm
+emacs_tags      -mouseshape      +startuptime     -xsmp
+eval            +mouse_dec       +statusline      -xterm_clipboard
+ex_extra        -mouse_gpm       -sun_workshop    -xterm_save
+extra_search    -mouse_jsbterm   +syntax
+farsi           +mouse_netterm   +tag_binary
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X_UNIX  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang   -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib  -L/usr/local/lib -o vim        -lncurses -liconv -framework Cocoa   -mmacosx-version-min=10.12 -fstack-protector-strong -L/usr/local/lib  -L/usr/local/Cellar/perl/5.24.1/lib/perl5/5.24.1/darwin-thread-multi-2level/CORE -lperl -lm -lutil -lc -F/usr/local/opt/python/Frameworks -framework Python   -lruby.2.4.1 -lobjc
jamessan commented 7 years ago

On regular vim I don't get the garbled output when running the same command

What if you :set noshelltemp first?

yangmillstheory commented 7 years ago

Same result in vim and nvim with :set noshelltemp.

jamessan commented 7 years ago

If this is "fixed" when you force nvim to use a different shell, then that sounds like your shell configuration is the culprit.

Is your shell changing the color palette? If so, it should only be doing that when run interactively.

justinmk commented 7 years ago

So this is a duplicate of https://github.com/neovim/neovim/issues/6015

yangmillstheory commented 7 years ago

There's this script that's sourced in my .zshenv. Here's where I initially got it from.

When I comment it out, the problem is gone. Do you have further insight?

Thanks @jamessan for taking time out to debug an issue barely related to neovim.

bfredl commented 7 years ago

You probably want to source that in .zshrc instead, so it should only be done for interactive shell.

mhinz commented 7 years ago

Just a small nitpick about your tmux config:

# set -g default-terminal "xterm-256color"
# set -ga terminal-overrides ",xterm-256color:Tc"
set -g default-terminal "tmux-256color"
set -ga terminal-overrides ",tmux-256color:Tc"

That should be:

set -g default-terminal "tmux-256color"
set -ga terminal-overrides ",xterm-256color:Tc"

Because you want tmux-256color to be used inside of tmux (instead of screen).

And terminal-overrides applies to the outside $TERM. It basically says: When starting tmux in a shell that has $TERM set to xterm-256color, add the Tc capability to tmux's internal image of tmux-256color to signalize it to use true colors. (Double check with tmux info | grep Tc.)

yangmillstheory commented 7 years ago

@mhinz thanks, this works. What's the real difference between using xterm-256color (Alacritty default) and tmux-256color and screen-256color? Are these all True Color? When would one choose one and not the other? (I realize this may be more appropriate for Stack Overflow, but can't hurt to ask here hopefully.)

mhinz commented 7 years ago

Those are terminfo entries; see man 5 terminfo. They describe what the pseudo terminal inside of your terminal emulator (alacritty, iTerm, ...) is capable of.

It's the terminal emulator itself that supports true colors and uses them whenever a program prints certain escape sequences. For Neovim you need to put set termguicolors in your vimrc to send these.

When you use a terminal multiplexer like tmux between your terminal emulator and Neovim, you need to enable true colors for it as well, so it properly "forwards" the escape sequences printed by Neovim to the terminal emulator. And that's what the terminal-overrides line is for.

yangmillstheory commented 7 years ago

Just a quick question, how do you learn enough to get into contributing to large projects like these? I've read a few books on bash and the unix CLI, but for folks that work on Alacritty, tmux, neovim, how did you get enough expertise in these low level components to start contributing to these projects? Most of the material I've gone through do no more than say "here's the CLI, here are some applications, here's what they do." The stuff you mention above is fairly lower level.

mhinz commented 7 years ago

The last point is not really needed to contribute to Neovim. In the end, you should find something that bugs you, navigate the sources until you find the location where the potential bug happens (which usually implies understanding how multiple functions are working together) and understand why it happens that way. Only then you can attempt to fix it properly.

And when you attempt to fix something, it's always a good idea to open an issue about it first. Then people with more insight can tell you whether it's a good or bad idea.

In case of doubt, join our Gitter channel and ask a lot of questions. :) It's an official resource and the core team hangs out there.