Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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/
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.