I am using these lines in my .vimrc
file, to highlight leading whitespace (which includes spaces):
highlight ExtraWhitespace ctermbg=darkgreen guibg=darkcyan
autocmd BufWinEnter * match ExtraWhitespace /^\s* \s*\|\s\+$
So, this works fine in most cases. Except in help buffers, where it highlights a lot of indentation from the 开发者_如何学Pythonhelp files. I find this annoying, so I tried this as a workaround:
autocmd FileType help highlight clear ExtraWhitespace
But unfortunately, as soon as a help buffer is opened, it seems that the highlighting in all my buffers disappears. Any ideas on how to improve this?
This seems to be working:
highlight ExtraWhitespace ctermbg=darkgreen guibg=darkcyan
autocmd BufEnter * if &ft != 'help' | match ExtraWhitespace /\s\+$/ | endif
autocmd BufEnter * if &ft == 'help' | match none /\s\+$/ | endif
[edit] The above code works for trailing spaces since my Vim couldn't understand your pattern. So just :%s/ubstitute
the pattern to fit your needs.
If you only need the whitespace errors for C/C++ files you can always use:
let c_space_errors=1
There are other languages that have similar support.
Worst case, if you need it for other types of files, you could always switch your file type to C and fix your errors then.
Change the autocommand disabling custom highlighting in help buffers as follows:
:autocmd FileType help match none
精彩评论