A.J.Mechelynck wrote:
Mohsin wrote:
I want to use a highlighter mode on my text file, example:
:color_region bold line1 col1 line2 col2
:color_region bold 5 5 6 6
:color_region underline 5 5 6 6
I couldn't do this in vim. Vim only has syntax coloring with regexps.
Emacs has functions to apply properties to text blocks, and I was hoping
vim has something comparable.
tia.
m
Vim regexps allow you to specify line and/or column numbers. Example, to
match a block defined by lines 55 to 77, virtual columns 15 to 37, and
highlight it in bold-underlined text:
(untested)
:highlight User1 term=bold,underline cterm=bold,underline
gui=bold,underline
:match User1 /^\%55l\_.*\%77l$\&\%>14v.*\%<39v/
(these are two commands, each on one line). The pattern means "(from the
beginning of line 55, anythyng including line breaks, up to the end of
line 77) *and* (from after virtual comumn 14, anything but line breaks,
as much as possible, followed by a zero-length match before column 39)".
I _think_ this is the correct phrasing but you should test it. The
"after column" and "before column" matchings are used to avoid problems
if the exact columns in question are, let's say, halfway a tab. IIUC,
the rightmost column that can be included in "a zero-length match before
column 39" is column 37.
Best regards,
Tony.
After testing, the above regexp won't work but this one will:
:match User1 /\%>54l.\%<78l\&\%>14v.\%<39v/
The reason is, the matches on both sides of \& must "match" (i.e.,
start) at the same place. By using > and < and matching one character at
a time we catch all characters in the rectangular area of interest. The
four numbers in the regex are, from left to right
y1-1 y2+1 x1-1 x2+2
where we want to highlight any character whose line l and column c
verify (y1 <= l <= y2) and (x1 <= c <= x2)
Best regards,
Tony.