Sunday, May 6, 2012

Re: Highlighting block of text

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>

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

No comments: