Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GVim: Different colors of odd and even lines

Tags:

vim

colors

macvim

Can I create color scheme for GVim (MacVim) where odd lines and even lines will have different colors?

like image 927
golovanovski Avatar asked Mar 05 '11 16:03

golovanovski


1 Answers

A Google search turned this up (I didn't know how to do it, but your question made me curious). Post below.


Got it to work on text files, as follows (on W32)

---- ~/vimfiles/after/syntax/text.vim 
hi default Oddlines ctermbg=grey guibg=#808080 
hi default Evenlines cterm=NONE gui=NONE 

syn match Oddlines "^.*$" contains=ALL nextgroup=Evenlines skipnl 
syn match Evenlines "^.*$" contains=ALL nextgroup=Oddlines skipnl 

---- $VIM/vimfiles/after/filetype.vim 
augroup filetypedetect 
        au BufRead,BufNewFile *.txt setf text 
augroup END 

---- ~/vimfiles/colors/almost-default.vim 
[...] 
hi Oddlines ctermbg=yellow guibg=#FFFF99 
hi Evenlines ctermbg=magenta guibg=#FFCCFF 
[...] 

Notes: 1. filetype.vim in an "after-directory" and with ":setf" to avoid overriding already-detected "special" .txt files.

  1. With "default" before the highlight name in the syntax file (but not without it) the colors from the colorscheme (invoked from the vimrc) are used. (Without a colorscheme, the "default" colors from the syntax file are still used.)

  2. Haven't succeeded (but haven't much tried) to make it work for a more complex filetype with an already defined syntax like HTML

  3. After entering the above changes, Vim must be restarted for them to take effect.

OK, enough for now, I'm taking a nap. Best regards, Tony.

like image 84
JasCav Avatar answered Nov 15 '22 09:11

JasCav