.vimrc: Support 256 colors, rework terminal settings
authorTony Duckles <tony@nynim.org>
Sun, 17 Dec 2017 18:51:18 +0000 (12:51 -0600)
committerTony Duckles <tony@nynim.org>
Sun, 17 Dec 2017 18:51:18 +0000 (12:51 -0600)
Based upon: http://www.memoryhole.net/~kyle/vimrc.html

Stop forcing t_Co=16 and forcing other terminal overrides. Let newer
terminal types (e.g. `screen-256colors`, `xterm-256colors`) do their
own thing.

.vimrc

diff --git a/.vimrc b/.vimrc
index cf9e98b64335c6e0187d324496fac6a2b939591d..89a60f5c1a0aa9c90f461efc2d7fab4f3378d0b1 100644 (file)
--- a/.vimrc
+++ b/.vimrc
@@ -41,27 +41,44 @@ if empty(glob('~/.vim/plugged'))
 endif
 
 " ---------------------------------------------------------------------------
-" Colors / Theme
+" Terminal Settings
 " ---------------------------------------------------------------------------
 
-if &t_Co > 2 || has("gui_running")
-  if has("terminfo")
+if !has("gui_running") && !(&term =~ '256color')
+  if has("terminfo") && ! (&term == 'linux' || &term == 'Eterm' || &term == 'vt220' || &term == 'nsterm-16color' || &term == 'xterm-16color')
+    " Force these terminals to accept my authority! (default)
     set t_Co=16
-    set t_AB=\e[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm
-    set t_AF=\e[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm
-  else
+    set t_AB=\e[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm  " ANSI background
+    set t_AF=\e[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm  " ANSI foreground
+  elseif &term == 'term' || &term == 'rxvt' || &term == 'vt100' || &term == 'screen'
+    " Less-Cool Terminals (no terminfo)
     set t_Co=16
-    set t_Sf=\e[3%dm
-    set t_Sb=\e[4%dm
+    set t_AB=\e[%?%p1%{8}%<%t4%p1%d%e%p1%{32}%+%d;1%;m
+    set t_AF=\e[%?%p1%{8}%<%t3%p1%d%e%p1%{22}%+%d;1%;m
+  else
+    " Terminals that have trustworthy terminfo entries
+    if &term == 'vt220'
+      set t_Co=8
+      set t_Sf=\e[3%dm  " foreground
+      set t_Sb=\e[4%dm  " background
+    elseif $TERM == 'xterm'
+      set term=xterm-color
+    endif
   endif
+endif
 
+" ---------------------------------------------------------------------------
+" Colors / Theme
+" ---------------------------------------------------------------------------
+
+if &t_Co > 2 || has("gui_running")
   set background=dark                 " dark background
   syntax enable                       " syntax highligting
 
   " Define to-do color(s)
   if !exists("autocmd_colorscheme_loaded")
     let autocmd_colorscheme_loaded = 1
-    autocmd ColorScheme * highlight TodoRed ctermbg=LightRed guibg=#E01B1B ctermfg=White guifg=#002b37
+    autocmd ColorScheme * highlight TodoRed ctermbg=Red guibg=#E01B1B ctermfg=White guifg=#002b37
   endif
 
   " Solarized color-scheme
@@ -84,14 +101,14 @@ endif
 highlight Comment                                    ctermfg=DarkGrey                    guifg=#425257
 " visual block
 highlight Visual          term=reverse cterm=reverse ctermfg=DarkGreen ctermbg=White     guifg=#4d830a guibg=#fdf6e3
-"" statusline (active vs inactive)
+" statusline (active vs inactive)
 if !exists(':AirlineTheme')
-  highlight StatusLine      term=reverse cterm=reverse ctermfg=Black     ctermbg=Grey      guifg=#073642 guibg=#93A1A1
-  highlight StatusLineNC    term=reverse cterm=reverse ctermfg=Black     ctermbg=DarkGrey  guifg=#073642 guibg=#37555c
-  highlight User1           term=reverse cterm=reverse ctermfg=Black     ctermbg=DarkGreen guifg=#4d830a guibg=#073642
+  highlight StatusLine    term=reverse cterm=reverse ctermfg=Black     ctermbg=Grey      guifg=#073642 guibg=#93A1A1
+  highlight StatusLineNC  term=reverse cterm=reverse ctermfg=Black     ctermbg=DarkGrey  guifg=#073642 guibg=#37555c
+  highlight User1         term=reverse cterm=reverse ctermfg=Black     ctermbg=DarkGreen guifg=#4d830a guibg=#073642
 endif
 " unprintable chars (listchars)
-highlight SpecialKey                                 ctermfg=DarkGray  ctermbg=Black     guifg=#374549 guibg=#06313c
+highlight SpecialKey                                 ctermfg=DarkGrey  ctermbg=Black     guifg=#374549 guibg=#06313c
 
 " ----------------------------------------------------------------------------
 "  Backups