On 06/06/10 15:09, Tim Chase wrote:
On 06/06/2010 07:23 AM, Yue Wu wrote:
 > I want to set different colors for odd and even lines in
 > normal text region, i.e., those lines that are not with
 > any syntax defined.


I tried to dig up a link to this message, but it seems to
have fallen off the internet.

Maybe on the gmane or yahoo archive for the "old" Vim lists?

Below is a thread on the
topic from ~4 years ago where Benji and Tony come up with a
solution that was elegant enough that I archived it in my
"good vim stuff I want to keep around" folder.

-tim

""""""""""""""""""""""""""""""""""""

Benji Fisher wrote:
[...]
 >> I have not used syntax much either, but I decided to
 >> test this. I think what you want is (two :hi lines
 >> and) something like this:
 >>
 >> :syn match Oddlines "^.*$" contains=ALL nextgroup=Evenlines skipnl
 >> :syn match Evenlines "^.*$" contains=ALL nextgroup=Oddlines skipnl
 >>
 >> In other words, drop "transparent" and add "skipnl". I
 >> tested it with
 >>
 >> :syn clear
 >>
 >> first; I am not sure how well it will work without that.
 >>
 >> HTH --Benji Fisher

I agree about "skipnl".

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.

2. 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.)

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

4. 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.

Now that I'm on Linux, I'm still using these (but under ~/.vim/ instead of ~/vimfiles/ of course). I still haven't tried to apply this "pajama highlighting" to anything other than text files. And if you don't like the colours (the ctermbg ones are decidedly ;-) not the prettiest), well, change them. In the meantime I've downloaded the CSApprox plugin so even in konsole (but not of course on the Linux pure-text console which is a "true" 8/16 colour terminal) I get "GUI" colours -- and as a sidenote: when each of the red, green and blue components is a multiple of 0x33, the colour exists "natively" on 256-colour terminals.

Best regards,
Tony.
--
Those who make peaceful revolution impossible will make violent
revolution inevitable.
                -- John F. Kennedy

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to