I was cleaning up my vimrc today, splitting it into separate files to make it easier to maintain. On completion of these changes, all my configuration, mappings and plugins appear to be working, except for highlighting trailing whitespace.
I have the following lines in .vim/rc/appearance.vim:
highlight RedundantSpaces term=standout ctermbg=red guibg=red
match RedundantSpaces /\s\+$\| \+\ze\t/ "\ze sets end of match so only spaces highlighted
As I understand it, the first line creates a highlight group 'RedundantSpaces', and instructs vim to make the background of any text matching the highlight group red, when on a colour terminal. The second line defines the pattern used to identify text matching the highlight group.
When I open a file in vim and start typing spaces on a blank line, they are not highlighted in red. If I run :source ~/.vimrc
, the highlighting appears.
If I remove the lines sourcing all my individual rc/*.vim
files from .vimrc
and put the above two RedundantSpaces
lines in .vimrc
directly, vim behaves as expected, and trailing whitespace is highlighted.
However, if I leave in the lines sourcing rc/*.vim
, and then have the RedundantSpaces
lines at the end of my .vimrc
(i.e. those commands are the last to be run when vim is invoked), the highlighting still does not work, and I need to source ~/.vimrc
.
It seems clear that something in my rc/*.vim
files is interacting poorly with the highlighting configuration, however I'm at a loss to explain what that is. Nothing in any of those files should be interacting with the highlight configuration.
Can anyone suggest what might be going wrong here?
Best Answer
The issue is caused by the sensible plugin:line 93.
:help t_Co
If you run vim in verbose log mode (
vim -V15load_log.vim
) – and search fort_Co=
andRedundantSpaces
you'll see thatsensible
is actually parsed after yourappearance.vim
file.Quick fix would be to either comment out that section of the code and add it to your
.vimrc
, but as you link to git repositories that is perhaps not what you want.A different approach would be to move it out of the
bundle
directory and add it as a separatesource
line in yourvimrc
, before your glob loop.I.e.:
Another way would be to load custom highlight on BufLoad.
Etc. …