On 8 May 2012, at 23:08, Richard wrote:

> Well, I spoke too soon. What I wanted was to highlight
> multiple block with different colors *at the same time*
> Seems that match only works on a single pattern at a time.
> 
> Richard

You could try generating a random name for each block? or base it off the 
line/column pairs?

Regards, Andy


> 
> On May 8, 3:01 pm, richard emberson <[email protected]>
> wrote:
>> Tim,
>> 
>> I finally got to the point in my project where I could tryout
>> your code. In one sense your code was similar to some of
>> my attempts at using the match/highlight capability but
>> I 1) did not order the column/line correctly and, more
>> importantly, 2) I did not have a trailing '.' in the
>> match patterns.
>> 
>> If one is willing to create highlight groups on the fly,
>> then one can programatically highlight arbitrary
>> blocks of code ... W5!
>> 
>> function! XXX(name, c1, c2, l1, l2)
>>    exec "highlight! " . a:name . " ctermbg=green guibg=green"
>>    exec "sil! match " . a:name. ' /\%>' .a:c1. 'c\%<' .a:c2. 'c\%>'
>> .a:l1. 'l\%<' .a:l2. 'l./'
>> endfunction
>> 
>> map <Leader>h :call XXX("Foo33",8,21,5,14)<CR>
>> 
>> Thanks.
>> 
>> Richard Emberson
>> 
>> ps:  5W == Which Was What We Wanted
>> 
>> On 05/06/2012 05:12 PM, Tim Chase wrote:
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> On 05/06/12 16:14, Richard wrote:
>>>> I'd like to highlight an arbitrary block of text even when
>>>> normal syntax-base highlighting is in effect.
>>>> Now, one can highlight a block of height 1 using matching:
>>>> :hi Green ctermbg=Green
>>>> :match Green /\%10l\%30c.*\%40c\%10l/
>>>> :match none
>>>> But what I'd like to do is for a block with height
>>>> greater than 1; something like what can be done
>>>> with Cntl-V visual block selection but without using
>>>> visual selection.
>>>> I've search the net without finding a solution.
>>>> Is it possible?
>> 
>>> I'm not sure if this does what you want, but I threw it together in
>>> the hopes that it was close.  Just visually highlight the range
>>> (linewise, characterwise, or blockwise) that you want to highlight
>>> and press<f4>.  Adjust the "Error" at the bottom for whatever
>>> highlighting group you want (in the case of your example, "Green")
>> 
>>> -tim
>> 
>>> function! Hi(scheme)
>>>    let l:mode=visualmode()
>>>    let [_, lnum1, col1, _]=getpos("'<")
>>>    let [_, lnum2, col2, _]=getpos("'>")
>>>    if l:mode == 'v'
>>>      if lnum1==lnum2
>>>        let range='\%'.lnum1.'l\%>'.(col1-1).'c.*\%<'.(col2+1).'c'
>>>      else
>>>        let range=join([
>>>        \'\%'.lnum1.'l\%>'.(col1-1).'c.*',
>>>        \'.*\%'.lnum2.'l\%<'.(col2+1).'c',
>>>        \'\%>'.lnum1.'l\%<'.lnum2.'l',
>>>        \], '\|')
>>>      endif
>>>    else
>>>      let left=min([col1, col2])
>>>      let right=max([col1, col2])
>>>      let top=min([lnum1, lnum2])
>>>      let bottom=max([lnum1, lnum2])
>>>      if l:mode == 'V'
>>>        let range=
>>>        \'\%>'.(top-1).'l'.
>>>        \'\%<'.(bottom+1).'l'.
>>>        \'.'
>>>      else " visual block
>>>        let range=
>>>        \'\%>'.(left-1).'c'.
>>>        \'\%<'.(right+1).'c'.
>>>        \'\%>'.(top-1).'l'.
>>>        \'\%<'.(bottom+1).'l'.
>>>        \'.'
>>>      endif
>>>    endif
>>>    exec printf('sil! match %s /%s/', a:scheme, range)
>>> endfunction
>>> vnoremap<f4>  :<c-u>call Hi("Error")<cr>
>>> nnoremap<f4>  :match NONE<cr>
>> 
>> --
>> Quis custodiet ipsos custodes
> 
> -- 
> 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

-- 
Andrew Long
andrew dot long at mac dot com





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