Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim, split windows breaks length highlight

Tags:

linux

vim

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.

like image 719
anon Avatar asked Feb 11 '23 04:02

anon


1 Answers

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.

like image 125
Ingo Karkat Avatar answered Feb 13 '23 21:02

Ingo Karkat