2

I'm looking for a regex that will select all text on a line from the 51st character to the end for lines exceeding 50 characters in length.

I need the regex to not include the first 50 characters of the line.

The reason for it is to add something to the gitcommit.vim syntax file to make it more obvious when I'm exceeding the 50 characters for the summary. Setting ctermbg=red or something along those lines.

I'm aware I could probably do something like setting ctermbg=red for the whole first line, and then let gitcommitSummary syntax group set the background back for the first 50 characters, but this problem caught my interest and I'd like to find out if there is a way for a regex to skip looking at the first X characters of the line.

I was playing around with something like the following, but it's just a zero-width assertion so it obviously doesn't work. Any ideas?

# This just highlights all lines exceeding 50 characters
/^\(.\{50\}\)\@=.*$

EDIT: Just realized that the gitcommit.vim file actually had syntax highlighting for this using "nextgroup", and just had it commented out by default. So I reached my original goal but I'd still like to know if it's possible to do this with a regex.

1 Answer 1

7

The Vim regex atom for matching at a particular column is \%Nc where N is the column number. See

:help /\%c

To match at a virtual column number, the atom is \%Nv. See

:help /\%v

To search for anything after column 50, you could use

/\%>50v

where the > means to match at any column after column 50. You could also use that regex in a :match command like this:

:match ErrorMsg /\%>50v/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .