From 5ddf8bb370e7bf72a647a2dc7af0e2dadb568a41 Mon Sep 17 00:00:00 2001 From: Jongwook Choi Date: Sat, 30 Sep 2017 21:36:40 -0400 Subject: [PATCH 1/8] Zsh/Tmux: Set TERM to xterm-256color Recent versions of tmux works well with ncurses (for 256 or richer colors) with TERM="xterm-256color". We do not find any reason to use 'screen-256color'; the new TERM configuration is required to enable 24-bit true color feature. --- tmux/tmux.conf | 3 ++- zsh/zshrc | 8 ++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/tmux/tmux.conf b/tmux/tmux.conf index c8bbd0ac..25132a19 100644 --- a/tmux/tmux.conf +++ b/tmux/tmux.conf @@ -150,7 +150,8 @@ set-window-option -g display-panes-time 1500 set -g focus-events on # Color and Themes -set-option -g default-terminal "screen-256color" +set-option -g default-terminal "xterm-256color" +set-option -ga terminal-overrides ",xterm-256color:Tc" # True-color (24bit) # let pane/window numbers be 1-indexed set-option -g base-index 1 diff --git a/zsh/zshrc b/zsh/zshrc index 8a3ded6b..8c169992 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -86,12 +86,8 @@ zplug load #--verbose for config_file (${ZDOTDIR:-$HOME}/.zsh/zsh.d/*.zsh(N)) source $config_file # Terminal -# screen-256color if inside tmux, xterm-256color otherwise -if [[ -n "$TMUX" ]]; then - export TERM="screen-256color" -else - export TERM="xterm-256color" -fi +# Use xterm-256color (for tmux, too) +export TERM="xterm-256color" # iTerm integration (for OS X iTerm2) # @see https://iterm2.com/shell_integration.html From 23755638f96de5c5cb9886797d5820dd28b9978b Mon Sep 17 00:00:00 2001 From: Jongwook Choi Date: Sat, 30 Sep 2017 22:32:35 -0400 Subject: [PATCH 2/8] Vim: Use termguicolors if possible (24-bit true color) This enables 24-bit true color support in true-color compatible environments. Mainly, highlights will follow gui colors. --- vim/vimrc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vim/vimrc b/vim/vimrc index 8a8175e6..a25637ac 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -428,6 +428,11 @@ if &term =~ '256color' set t_ut= endif +" 24-bit true color: neovim 0.1.5+ / vim 7.4.1799+ +if (has("termguicolors")) && &term == 'xterm-256color' + set termguicolors +endif + " apply base theme silent! colorscheme xoria256 From caf69ee92050dc7cdd7022f443755f5f1a16a940 Mon Sep 17 00:00:00 2001 From: Jongwook Choi Date: Sat, 30 Sep 2017 22:36:01 -0400 Subject: [PATCH 3/8] Vim: Update highlight color of popup menu for GUI environments Popup menu was in a gray-ish color with GUI or 24-bit terminals, which should be yellow-ish as in normal terminals (256 color). --- vim/vimrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index a25637ac..48ca5667 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -494,8 +494,8 @@ autocmd BufWinLeave * call clearmatches() autocmd InsertLeave * silent! set nopaste " better popup menu colors (instead of dark black) -highlight Pmenu ctermfg=black ctermbg=yellow -highlight PmenuSel ctermfg=red ctermbg=white gui=bold +highlight Pmenu ctermfg=black ctermbg=yellow guifg=black guibg=#ffec99 +highlight PmenuSel ctermfg=red ctermbg=white guifg=red guibg=white gui=bold " http://vim.wikia.com/wiki/Identify_the_syntax_highlighting_group_used_at_the_cursor function! ShowSyntaxGroup() From 4bad77ae60b0ff4024e0664ae7079538e8f0045d Mon Sep 17 00:00:00 2001 From: Jongwook Choi Date: Wed, 4 Oct 2017 14:53:11 -0400 Subject: [PATCH 4/8] Zsh: Add submodule 'is_mosh' Detects the current shell (running inside tmux, or not) is through a mosh channel. This tool is necessary for auto-configuring true color mode in several applications including vim. --- .gitmodules | 3 +++ install.py | 1 + zsh/is_mosh | 1 + 3 files changed, 5 insertions(+) create mode 160000 zsh/is_mosh diff --git a/.gitmodules b/.gitmodules index c88c38b7..c501295c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -11,3 +11,6 @@ [submodule "zsh/zplug"] path = zsh/zplug url = https://github.com/zplug/zplug +[submodule "zsh/is_mosh"] + path = zsh/is_mosh + url = https://github.com/wookayin/is_mosh diff --git a/install.py b/install.py index 0dbe5865..8d0a77f7 100755 --- a/install.py +++ b/install.py @@ -47,6 +47,7 @@ # Bins '~/.local/bin/dotfiles' : 'bin/dotfiles', '~/.local/bin/fasd' : 'zsh/fasd/fasd', + '~/.local/bin/is_mosh' : 'zsh/is_mosh/is_mosh', '~/.local/bin/imgcat' : 'bin/imgcat', '~/.local/bin/imgls' : 'bin/imgls', '~/.local/bin/fzf' : '~/.fzf/bin/fzf', # fzf is at $HOME/.fzf diff --git a/zsh/is_mosh b/zsh/is_mosh new file mode 160000 index 00000000..6cde1cf5 --- /dev/null +++ b/zsh/is_mosh @@ -0,0 +1 @@ +Subproject commit 6cde1cf5d4af45b2f9bcc4267d0beca0b2b61c17 From 2669be446f9a61280953001487a9ee6a2185fa0a Mon Sep 17 00:00:00 2001 From: Jongwook Choi Date: Wed, 4 Oct 2017 15:01:34 -0400 Subject: [PATCH 5/8] Vim: Use 24-bit true color (termguicolors) whenever possible Whenever possible, use termguicolors features to enable 24-bit true color, even in the terminals like GUI. There is a subtle challenge as some shell or terminal emulators may not support 24-bit colors. We assume that modern terminal emulators we would use will support it, or even fall-back to 256 colors nicely, but otherwise it may look broken as in mosh. For mosh, to workaround this issue until mosh supports true color, we detect whether the vim is running in a mosh environment. This detection should be robust even when it is running under a tmux session; to this end, the 'is_mosh' script is introduced. Whenever the vim is initialized or asked to redraw the screen, we detect mosh under which the feature shall be disabled. --- vim/vimrc | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 48ca5667..8eb13b0c 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -341,7 +341,11 @@ xnoremap ag y:Ag " nmap cd :cd %:p:h " r : screen sucks, redraw everything -nnoremap r :redraw! +function! Redraw() + redraw! + call s:auto_termguicolors() " re-detect true colors +endfunction +nnoremap r :call Redraw() " src : source ~/.vimrc nnoremap src :source ~/.vimrc @@ -429,9 +433,28 @@ if &term =~ '256color' endif " 24-bit true color: neovim 0.1.5+ / vim 7.4.1799+ -if (has("termguicolors")) && &term == 'xterm-256color' - set termguicolors -endif +" enable ONLY if TERM is set valid and it is NOT under mosh +function! s:is_mosh() + let output = system("is_mosh -v") + if v:shell_error + return 0 + endif + return !empty(l:output) +endfunction + +function s:auto_termguicolors() + if !(has("termguicolors")) + return + endif + + if &term == 'xterm-256color' && !s:is_mosh() + set termguicolors + else + set notermguicolors + endif +endfunction +call s:auto_termguicolors() + " apply base theme silent! colorscheme xoria256 From f279ee0ac305da515ef3e0d2e9697f83ec861336 Mon Sep 17 00:00:00 2001 From: Jongwook Choi Date: Sat, 7 Oct 2017 16:59:11 -0400 Subject: [PATCH 6/8] Vim: Apply termguicolors for nvim terminals In some nvim environments, &term is set to be 'nvim' instead of the TERM value inherited from the shell. --- vim/vimrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index 8eb13b0c..c4aabc9e 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -447,7 +447,7 @@ function s:auto_termguicolors() return endif - if &term == 'xterm-256color' && !s:is_mosh() + if (&term == 'xterm-256color' || &term == 'nvim') && !s:is_mosh() set termguicolors else set notermguicolors From 77d7d0d1a5ff11925e3a751aab533996632fb982 Mon Sep 17 00:00:00 2001 From: Jongwook Choi Date: Sat, 7 Oct 2017 21:29:03 -0400 Subject: [PATCH 7/8] Vim: Apply different airline theme for true color mode When 24-bit colors are enabled (termguicolors), use a slightly different appearance and color themes. --- vim/vimrc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index c4aabc9e..aa013bb7 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -459,6 +459,14 @@ call s:auto_termguicolors() " apply base theme silent! colorscheme xoria256 +" airline theme: status line and tab line +if &termguicolors + let g:airline_theme='deus' +else + let g:airline_theme='bubblegum' +endif + + " override more customized colors highlight StatusLine ctermfg=LightGreen highlight ColorColumn ctermbg=52 guibg=#5f0000 @@ -654,9 +662,9 @@ let g:EditorConfig_core_mode = 'python_external' " ---------------------------------------------------------------- }}} " Airline {{{ +" Note: for airline theme, see the 'appearance' section " use airline, with powerline-ish theme -let g:airline_theme='bubblegum' let g:airline_powerline_fonts=1 " enable tabline feature From 1c7b48d43b9b8e93783f4fa6318ed652997958cf Mon Sep 17 00:00:00 2001 From: Jongwook Choi Date: Sat, 7 Oct 2017 21:51:50 -0400 Subject: [PATCH 8/8] Vim: Use better highlight color for diff Use better color, respecting syntax highlight, when viewing diff under GUI mode or true color. Previously, foreground color for diff texts had to set black in which syntax highlights are ignored, because 256-color doesn't have dark green/red color of similar brightness to the background. In 24-bit color mode, we adopt dark but chromatic colors for diff background. --- vim/vimrc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vim/vimrc b/vim/vimrc index aa013bb7..a4e58899 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -480,6 +480,18 @@ highlight Constant ctermfg=204 guifg=#ff5f87 highlight PreProc ctermfg=219 guifg=#ffafff highlight SpecialKey ctermfg=242 guifg=#666666 +" colors for gui/24bit mode {{ +" DiffAdd - inserted lines (dark green) +highlight DiffAdd guibg=#102a05 guifg=NONE +" DiffDelete - deleted/filler lines (gray 246) +highlight DiffDelete guibg=#949494 +" DiffChange - changed lines (dark red) +highlight DiffChange guibg=#471515 guifg=NONE +" DiffChange - changed 'text'(brighter red) +highlight DiffText guibg=#721b1b guifg=NONE +" }} + + " no underline, current cursor line highlight CursorLine cterm=none