On Jul 13, 1:11 am, "Christian Brabandt" <[email protected]> wrote: > On Tue, July 12, 2011 11:33 pm, Ben Fritz wrote: > > Are you asking for every other line to be highlighted in a different > > color as shown in the screen shot? > > > You can't do it exactly like the screenshot, and it will slow down > > performance greatly, but you might be able to use a bunch of > > matchadd() calls, to set up matches for all text on each line. > > I tried once using several > :syn match Evenl /.*/ nextgroup=Oddl > :syn match Oddl /.*/ nextgroup=Evenl > :hi Evenl ctermbg=Red ctermfg=Black > :hi Oddl ctermbg=Yellow ctermfg=Black > > Unfortunately, this did not work. I am not sure why. My understanding > of the syntax highlighting was, that the nextgroup parameter should > force matching the next group. But somehow it ends always matching the > same group. Not sure if this is a bug or my understanding is wrong. >
I think it is because you aren't including the newline in the match. So, Oddl matches first, tries matching Evenl on the line ending (which fails because line endings aren't matched with '.'), and therefore Oddl matches again on the next line. Possibly just using ^.*\n as the pattern would fix it, but this will probably not work well together with existing syntax highlights. That's why I suggested matchadd() > > There is no way to highlight entire lines, including empty space and > > line numbers, alternating between two different backgrounds. At least, > > not without modifying Vim's C code and recompiling. > > There is no way to highlight entire lines, including empty space and > > line numbers, alternating between two different backgrounds. At least, > > not without modifying Vim's C code and recompiling. > > That is not entirely true. If you set up signs, you can highlight > entire lines. I have made a simply plugin that makes that > possible:http://www.vim.org/scripts/script.php?script_id=2998 > WOW! I didn't even know about that. I stand corrected. However, you still don't get the alternating highlight of the line number column, the sign column will then always be displayed, and the sign column is only 2 characters wide always so you cannot just use it as a replacement for the line number column. Also, 'wrap' and 'showbreak' interact in unexpected (but not incorrect) ways. So, something like this can alternate line colors, coloring all even lines in blue and falling back to Normal highlight for odd lines (very gaudy, probably not recommended with colors as-is) in an existing buffer: :sign define EvenL linehl=EvenLbg :hi EvenLbg guibg=blue :g#^#if line('.')%2==0 | exec 'sign place '.line('.').' line='.line('.').' name=EvenL buffer='.bufnr("%") | endif :nohls To keep the highlight up-to-date, you'd need to re-apply them after every change. So far I've come up with this: sign define EvenL linehl=EvenLbg hi EvenLbg guibg=blue augroup ALT_LINES au! autocmd BufWinEnter,CursorMoved,CursorMovedI,CursorHold,CursorHoldI * \ if !exists('b:my_changedtick') || b:my_changedtick != b:changedtick | \ let b:my_changedtick = b:changedtick | \ let pos_sav = getpos('.') | \ for id in range(2,line('$'),2) | exec 'sign unplace '.id.' buffer='.bufnr('%') | endfor | \ keepjumps exec 'g#^#if line(".")%2==0 | exec "sign place ".line(".")." line=".line(".")." name=EvenL buffer=".bufnr("%") | endif' | \ nohls | \ call setpos('.',pos_sav) | \ endif augroup END The for loop in there is an attempt to allow multiple buffers simultaneously. It's faster to do :sign unplace * but that will not work for multiple buffers. It's also really slow for big files--unbearably slow for really big ones, since it updates on every change--and the screen flashes on every change for small files. This could be improved by removing the CursorMoved autocmds at the sacrifice of not having completely correct highlight sometimes, but could still be very annoying. If I ever start using something like this, I'd probably tweak it to only fire on buffers with empty buftype, remove the CursorMoved and CursorMovedI events, and repalce them with InsertLeave. -- 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
