I set this up in my .vimrc to highlight a line over 80 characters.
highlight OverLength ctermbg=darkred ctermfg=darkred guibg=darkred
match OverLength /\%>80v.\+/
Now then, if I open (one buffer) a file with lines that are too long, they'll highlight. Fine, but if I open a different file and then use NERDTree to open a vsplit of the original file, the long line will no longer highlight. What am I doing wrong?
Edit: I'm using gvim on GNU/Linux.
Edit: After you open the original file in a split long lines will not highlight FOR ANY FILE until you restart vim and open the file in a single buffer.
The :match
command only applies to the current window. So any :split
won't inherit the highlighting. This is documented under :help :match
:
Define a pattern to highlight in the current window.
You can automatically install the matching for any window via :autocmd
:
autocmd VimEnter,WinEnter * match OverLength /\%>80v.\+/
But I'd recommend to switch to the 'colorcolumn'
setting, which is available in Vim 7.3+; this only highlights a single column (and also in shorter lines), but you can simply :set colorcolumn=81
in your ~/.vimrc
and it applies to all windows, and you get to keep the :match
highlighting for other uses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With