This highlights the parts of the lines that are over 80 columns long:

augroup over_length
    autocmd BufEnter * highlight OverLength ctermbg=darkgrey
    autocmd BufEnter * match OverLength /\%80v.*/
augroup END

However, I would like to modify it to use &textwidth. Using /\%.&textwidth.v.*/ doesn't seem to work. Is there a way to substitute the value into the regular expression?

  • My want to consider using set colorcolumn=80. See :h 'cc' Feb 22 '17 at 18:03
  • @PeterRincker I find colorcolumn too distracting.
    – user8048
    Feb 23 '17 at 18:06

Yes, you have to use execute and put it in a string:

execute 'match OverLength /\%'. &textwidth .'v.*/'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy