There are two topics to be discussed here. (1) setting up your code colorizations, and (2) making vim recognize the code type that you are editing.
1. Setting up .gvimrc (or .vimrc) to colorize your code with your color choices:
- Within this topic, there are two alternatives:
(a) you are using X, so you have fine-grained control over the color set.
(b) you are using some kind of color tty terminal (puTTY for example), in which case you can only use the basic 8 or 16 colors.
- In the example that follows, these contents are typically found in the .gvimrc file which should be placed in the user's home directory. (_gvimrc for Windows). For tty terminals, you will need to define a .vimrc softlink to the .gvimrc file.
" Only do this for Vim version 5.0 and later.
if version >= 500
" Turn off Tool Bar:
set go=agimrt
" Highlighting strings inside C comments
let c_comment_strings=1
let c_comment_strings=0
" Switch on syntax highlighting.
syntax on
" Switch on search pattern highlighting.
set hlsearch
" For Win32 version, have "K" lookup the keyword in a help file
"if has("win32")
" let winhelpfile='windows.hlp'
" map K :execute "!start winhlp32 -k " . winhelpfile
"endif
" Hide the mouse pointer while typing
set nomousehide
" Set nice colors:
" There are two sets of defaults: a dark and a light background.
" You can set up as many different versions as you like.
set background=light
set background=dark
set guifont=fixed
"set guifont=helvR14
"set guifont=ncenR14
set guifont=hp8.8x16
"set guifont=hp8.10x20b
if has("gui_win32")
:set guifont=Lucida_Console:h8:cANSI
endif
if &background == "dark"
hi Normal ctermfg=White guifg=#a0ffff guibg=#402850
hi Comment ctermfg=Yellow guifg=#ffff80 guibg=#402850
hi Constant ctermfg=Green guifg=Green guibg=#402850
hi Special ctermfg=Magenta guifg=#80ffd0 guibg=#4028c8
hi Identifier ctermfg=Cyan guifg=#00c0ff guibg=#402850
hi Statement ctermfg=White guifg=white guibg=#402850 gui=bold
hi PreProc ctermfg=Magenta guifg=#ff00ff guibg=#402850
hi Type ctermfg=Blue guifg=#0000ff guibg=#402850 gui=bold
hi Ignore ctermfg=Grey guifg=Grey guibg=#402850
hi Error ctermfg=Red guifg=White guibg=Red
hi Todo ctermfg=Magenta guifg=#ffffa0 guibg=#402850 gui=bold
hi Search guibg=#d0d000
hi Visual ctermfg=Blue guifg=DarkBlue guibg=Cyan
hi Cursor ctermfg=NONE guifg=NONE guibg=Green
hi NonText guibg=#a0a0a0
else
hi Normal ctermfg=Black guifg=Black
hi Comment ctermfg=DarkYellow guifg=Brown
hi Constant ctermfg=DarkGreen guifg=DarkGreen
hi Special ctermfg=DarkMagenta guifg=DarkCyan guibg=#e0ffe0
hi Identifier ctermfg=DarkCyan guifg=DarkBlue
hi Statement ctermfg=Black guifg=Blue gui=bold
hi PreProc ctermfg=DarkMagenta guifg=Purple
hi Type ctermfg=Blue guifg=Black gui=bold
hi Ignore ctermfg=DarkGrey guifg=White
hi Error ctermfg=Red guifg=White guibg=Red
hi Todo ctermfg=Magenta guifg=Blue guibg=Yellow gui=bold
hi Visual ctermfg=DarkBlue guifg=DarkBlue guibg=Cyan
hi Cursor ctermfg=None guifg=NONE guibg=Green
hi NonText guibg=#808080
endif
endif
2. Getting vim to recognize the file type for correct code colorization:
- In following example the code colorization parser is set based on the file extension and only works in gvim.
" gretl provides a nice, simple colorizing to differentiate typical
" delimiters, text and numbers: Other reasonable choices: fstab, rexx
augroup filetypedetect
autocmd BufNewFile,BufRead *.cfg setfiletype gretl
autocmd BufNewFile,BufRead *.dbg setfiletype gretl
autocmd BufNewFile,BufRead *.log setfiletype gretl
autocmd BufNewFile,BufRead *.lst setfiletype gretl
autocmd BufNewFile,BufRead *.out setfiletype gretl
augroup END