Aug 10, 2010 vim

Notes on Vim colors for syntax highlighting.

Work in progress

I am currently working on a new vim colorscheme otter-dark with the following features:

Once finished, it will be uploaded to:

Website

Preview all themes and colorschemes

Built-in colors

$ ls /usr/share/vim/vim73/colors

default.vim    elflord.vim    morning.vim    peachpuff.vim  slate.vim
blue.vim       delek.vim      evening.vim    murphy.vim     ron.vim        torte.vim
darkblue.vim   desert.vim     koehler.vim    pablo.vim      shine.vim      zellner.vim

Usage

Load color scheme, see above.

:colorscheme desert
:colorscheme peachpuff

shortcut
:color twilight

see http://vim.wikia.com/wiki/Switch_color_schemes for function that switches color theme using F8. Also made into plugin.

Change color

displays all highlighting text

:highlight		    
:hi

Help

:help hi

Set color

:set hi <E> cterm= ctermbg= ctermfg= guibg= guifg= 
cterm__ : terminal based vim (most case)
gui__ : gui-based vim (gvim, macvim)

Reset colors

:hi clear
:hi clear {group}

Highlight cursor line

:hi Cursor guifg=NONE guibg=Green

cursorline

" show cursorline. *cursorline may cause slowdown in large file/ long text
set cursorline
hi CursorLine cterm=NONE ctermbg=233  "cursorline color: grey7"

colorschemes

vim colorscheme preview/editor

vim colorscheme preview

vim plugin: colorscheme pack

Includes solarized, tomorrow, and zenburn.

Vundler: add to .vimrc

Plugin 'flazz/vim-colorschemes'
:PluginInstall

[Ruby code that harvests the colorscheme from vim.org] (https://github.com/flazz/vim-colorschemes/tree/prep)

Good colorschemes

http://www.vimninjas.com/2012/08/26/10-vim-color-schemes-you-need-to-own/

solarized

Example setting

set background=dark
let g:solarized_termtrans=1
let g:solarized_termcolors=256
let g:solarized_contrast="high"
let g:solarized_visibility="high"
colorscheme solarized

Toggle between dark and light background (using F5)

call togglebg#map("<F5>")

Create colorscheme

create colorscheme based on existing colors

"these lines are suggested to be at the top of every colorscheme
hi clear
if exists("syntax_on")
syntax reset
endif

"Load the 'base' colorscheme - the one you want to alter
runtime colors/blue.vim

"Override the name of the base colorscheme with the name of this custom one
let g:colors_name = "my-blue"

"Clear the colors for any items that you don't like
hi clear StatusLine
hi clear StatusLineNC

"Set up your new & improved colors
hi StatusLine guifg=black guibg=white
hi StatusLineNC guifg=LightCyan guibg=blue gui=bold

Compatibility Issues

vim and tmux

Cause: shell uses $TERM=xterm-256color but tmux uses $TERM=screen-256color.

Solution 1:

set $TERM=screen-256color (http://sunaku.github.io/vim-256color-bce.html)

or

`alias tmux="TERM=screen-256color-bce tmux"`

Solution 2. Disable BCE (background color erase)

:set t_ut=
<C-L> to refresh

It works, but I need to do it for every time starting vim.

I need to make a script or macro to do this every time.

if &term =~ '256color'
    " disable Background Color Erase (BCE) so that color schemes
    " render properly when inside 256-color tmux and GNU screen.
    " see also http://snk.tuxfamily.org/log/vim-256color-bce.html
    set t_ut=
endif

Solution 3: http://superuser.com/questions/399296/256-color-support-for-vim-background-in-tmux

Make gvim colorschme work on terminal vim.

In case vim doesn’t recognize colored terminal:

if $TERM == "xterm-256color" || $TERM == "screen-256color" || $COLORTERM == "gnome-terminal"
  set t_Co=256
endif

Misc

Save as HTML (including color)

visual mode, highlight the text
:TOhtml

# this will open a new buffer with generated HTML, which can be saved

:TOHtml tutorial (generate HTML from Vim in color)

256 xterm color chart

Vim Plugin that shows color

Vimshell does not use escape sequence color. To use escape sequence, enable |+conceal| feature. It works with Vim 7.3+.