2

Hi I am using a vim setting to highlight columns past the column 80. This hardcoded setting is good enough for programming where I like to keep it in 79 columns. However for LaTeX, plain txt, RST, where I use different tw values it is not working for obvious reasons. Is it possible to somehow use the value of textwidth setting inside this regexp ? Or if not, how can I approach this problem ?

hi OverLength ctermbg=darkred ctermfg=white guibg=#592929
match OverLength /\%81v.\+/
Darek
  • 2,861
  • 4
  • 29
  • 52

1 Answers1

1

Instead of just setting the limit, why not have a function with a bind that'll highlight characters past n columns?

nnoremap <leader>h :call ToggleOverLengthHighlight()<CR>
let g:overlength_enabled = 0
highlight OverLength ctermbg=black guibg=#212121

function! ToggleOverLengthHighlight()
    if g:overlength_enabled == 0
        match OverLength /\%79v.*/
        let g:overlength_enabled = 1
        echo 'OverLength highlighting turned on'
    else
        match
        let g:overlength_enabled = 0
        echo 'OverLength highlighting turned off'
    endif
endfunction

enter image description here

timss
  • 9,982
  • 4
  • 34
  • 56
  • in our example, you also have 79 columns hardcoded – Darek Apr 22 '13 at 09:01
  • @Dārayavahuštdi Eh, "hardcoded" isn't really the right term. Updated my answer. I still think this is a decent solution to this issue, as you won't have to tackle specific filetypes all the time. – timss Apr 22 '13 at 09:48