views:

1322

answers:

2

I would like vim to color "long" lines for me. Using 80 columns as an example, I would like to highlight lines that exceed that length. Here is roughly what I think the .vimrc file should contain, although it (1) doesn't work, and (2) uses Perl's regex syntax to illustrate my point, because I don't know Vim's well enough:

...
highlight Excess ctermbg=0
au Syntax * syn match Excess /.{80,}$/
...

This (in my mind at least) should mark lines that exceed 80 columns. What I would ideally like is the ability to color only the part of the line that exceeds 80 columns, so if a line is 85 columns, then the 81st through the 85th columns would be highlighted.

I'm sure Vim can do this, just not with me at the helm.

+1  A: 

I use the following method:

hi gitError ctermbg=Red
match gitError /^.*\s$/
2match gitError /^.\{120\}.*$/

(These match some git pre-commit hooks)

The second line should be of interrest to you.

terminus
Thank you. This (/^.\{120\}.*$/) highlights the whole line - any idea about just highlighting from characters 121 onwards?
Paul Beckingham
Sorry, no idea. The problem is that it may not be doable with regexps. You know, it would propably require a stack machine.
terminus
You can highlight only the 80 first chars. I know, not exactly what you want, but you'll see the excess quite clearly anyway.
PEZ
+6  A: 

I have this in my vimrc.
I found it here: http://stackoverflow.com/questions/235439/vim-80-column-layout-concerns

highlight OverLength ctermbg=darkred ctermfg=white guibg=#FFD9D9
match OverLength /\%81v.*/

You might want to adjust the colors to your preferences.

HS
+1.Now, if someone could explain why that works that would help me a lot because I don't get it.
PEZ
This only works for the first file you open in any given buffer
Brandon Thomson