How to highlight odd and even lines with different colors for normal text region.

89 views
Skip to first unread message

Yue Wu

unread,
Jun 6, 2010, 8:23:17 AM6/6/10
to vim_use
Hello list,

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.

How to do it?

--
Regards,
Yue Wu

Key Laboratory of Modern Chinese Medicines
Department of Traditional Chinese Medicine
China Pharmaceutical University
No.24, Tongjia Xiang Street, Nanjing 210009, China

Tim Chase

unread,
Jun 6, 2010, 9:09:12 AM6/6/10
to vim...@googlegroups.com, Yue Wu
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. 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.


Yue Wu

unread,
Jun 6, 2010, 11:46:29 AM6/6/10
to vim...@googlegroups.com
On Sun, 06 Jun 2010 21:09:12 +0800, Tim Chase <v...@tim.thechases.com>
wrote:

> 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

Thank you, Tim, it works very well.

Tony Mechelynck

unread,
Jun 6, 2010, 12:00:14 PM6/6/10
to vim...@googlegroups.com, Tim Chase, Yue Wu
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?

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

Tim Chase

unread,
Jun 6, 2010, 3:19:38 PM6/6/10
to Tony Mechelynck, vim...@googlegroups.com
On 06/06/2010 11:00 AM, Tony Mechelynck wrote:
> On 06/06/10 15:09, Tim Chase wrote:
>> 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?

Having the original email saved (including the subject line), my
attempts to Google various excerpts of the exact text failed to
bring back the original message. No harm as I've reintroduced it
to teh intarwebs, but I've had little luck resurrecting such
"ancient" (gasp, 4 years old...that's a geologic age in internet
terms! :) emails despite knowing exact terms/phrases from the
message body.

Perhaps another's google-fu is stronger.

-tim


Gary Johnson

unread,
Jun 6, 2010, 3:41:40 PM6/6/10
to vim...@googlegroups.com

I Googled for

vim oddlines evenlines

and came up with

http://www.mail-archive.com/v...@vim.org/msg07010.html

which is your message from 2006:

Re: Shading alternating patterns.
Tim Chase
Tue, 10 Oct 2006 08:23:56 -0700

But there is no sign of the posts from Benji and Tony from February
of that year, even after clicking the "show more results" link. It
does look like the history cut-off is four years plus or minus a
couple of months.

Regards,
Gary

AK

unread,
Jun 6, 2010, 4:09:20 PM6/6/10
to vim...@googlegroups.com

Hi, I made a collection of vim plugins with python:
http://lightbird.net/pysuite/ I need feedback! (they require vim
compiled with python).

At this stage the goal is not to have very polished or feature-complete
plugins but to have something that can serve as example and a starting
point for people who want to develop for vim in python.

Tim Chase

unread,
Jun 6, 2010, 4:19:23 PM6/6/10
to vim...@googlegroups.com
On 06/06/2010 02:41 PM, Gary Johnson wrote:
> I Googled for
>
> vim oddlines evenlines
>
> and came up with
>
> http://www.mail-archive.com/v...@vim.org/msg07010.html
>
> which is your message from 2006:
>
> Re: Shading alternating patterns.
> Tim Chase
> Tue, 10 Oct 2006 08:23:56 -0700
>
> But there is no sign of the posts from Benji and Tony from February
> of that year, even after clicking the "show more results" link. It
> does look like the history cut-off is four years plus or minus a
> couple of months.

Sigh...can't count on the internet for _anything_ these days.

That's okay -- it's not like anything worth preserving was
happening more than four yea...ooh, look, a shiny object! :-)

-tim


Tony Mechelynck

unread,
Jun 6, 2010, 5:52:31 PM6/6/10
to vim...@googlegroups.com

Apparently Yahoo! itself keeps its archives longer than dedicated
"history archives" keepers. Here are a few threads on that subject,
including the one Tim saved:
10-Feb-2006 01:26 http://tech.groups.yahoo.com/group/vim/message/65679
10-Oct-2006 17:11 http://tech.groups.yahoo.com/group/vim/message/74391
20-Feb-2009 10:03 http://tech.groups.yahoo.com/group/vim/message/101663

Best regards,
Tony.
--
Experience is something you don't get until just after you need it.
-- Olivier

Christian Brabandt

unread,
Jun 7, 2010, 2:11:18 AM6/7/10
to vim...@googlegroups.com
Hi Gary!

On So, 06 Jun 2010, Gary Johnson wrote:

> I Googled for
>
> vim oddlines evenlines
>
> and came up with
>
> http://www.mail-archive.com/v...@vim.org/msg07010.html
>
> which is your message from 2006:
>
> Re: Shading alternating patterns.
> Tim Chase
> Tue, 10 Oct 2006 08:23:56 -0700
>
> But there is no sign of the posts from Benji and Tony from February
> of that year, even after clicking the "show more results" link. It
> does look like the history cut-off is four years plus or minus a
> couple of months.

here it is at gmane:
http://thread.gmane.org/gmane.editors.vim/39403/focus=39403o

regards,
Christian
--
In der Jugend sind wir in der Regel sanguinisch, in sp�teren Jahren
cholerisch, nach der Ernte der Erfahrungen mehr oder weniger
melancholisch und im hohen Alter stumpf wie das Phlegma.
-- Karl Julius Weber

Reid Thompson

unread,
Jun 7, 2010, 8:41:44 AM6/7/10
to vim...@googlegroups.com, reid.t...@ateb.com, Tony Mechelynck
On Sun, 2010-06-06 at 14:19 -0500, Tim Chase wrote:
> On 06/06/2010 11:00 AM, Tony Mechelynck wrote:
> > On 06/06/10 15:09, Tim Chase wrote:
> >> 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?
>

>
>

has some information from 2006
http://markmail.org/search/?q=vim++match+Oddlines


Reid Thompson

unread,
Jun 7, 2010, 8:42:52 AM6/7/10
to vim...@googlegroups.com, reid.t...@ateb.com
On Sun, 2010-06-06 at 12:41 -0700, Gary Johnson wrote:
> which is your message from 2006:
>
> Re: Shading alternating patterns.
> Tim Chase
> Tue, 10 Oct 2006 08:23:56 -0700
>
> But there is no sign of the posts from Benji and Tony from February
> of that year, even after clicking the "show more results" link. It
> does look like the history cut-off is four years plus or minus a
> couple of months.


has February emails
http://markmail.org/search/?q=vim++match+Oddlines

clemens fischer

unread,
Jun 20, 2010, 2:20:13 PM6/20/10
to vim...@googlegroups.com
On Sun-2010/06/06-21:19 Tim Chase wrote:

> Having the original email saved (including the subject line), my
> attempts to Google various excerpts of the exact text failed to
> bring back the original message. No harm as I've reintroduced it
> to teh intarwebs, but I've had little luck resurrecting such
> "ancient" (gasp, 4 years old...that's a geologic age in internet
> terms! :) emails despite knowing exact terms/phrases from the
> message body.

I just googled for >>"despite knowing exact terms/phrases from"<< and
got yours. The quotes are _mandatory_ in these cases.


clemens

Tim Chase

unread,
Jun 20, 2010, 7:02:32 PM6/20/10
to vim...@googlegroups.com

Yes, I had tried exact-phrase searching on an excerpt of the
original text (which I had in my local archive), but Google
yielded nothing. It turns out that searching individual archives
(such as Mark Mail or perhaps Gmane) can yield a deeper search
that what Google's results returned. My email (the excerpt from
which you quoted) was fresh enough that Google found it. I'm
guessing that the original email I tried to disinter was
sufficiently old that Google thought it wasn't worth
indexing/returning. However recent referencing of the thread will
likely have triggered reindexing of the page, making it reappear
in Google results.

-tim


Reply all
Reply to author
Forward
0 new messages