Created
February 23, 2016 19:35
-
-
Save rotated8/c04cd77f3109777acaa5 to your computer and use it in GitHub Desktop.
Highlight mixed and trailing whitespace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Bad whitespace shows up in red. | |
highlight BadWhitespace ctermbg=1 guibg=Red | |
" This function will clear bad whitespace highlighting in help files. | |
" It is needed because Filetype events fire after BufEnter ones. See below. | |
function! IgnoreHelpFiles() | |
if &filetype ==? 'help' | |
call clearmatches() | |
endif | |
endfunction | |
" Match whenever we enter a buffer. (These happen in order) | |
augroup badwhitespace | |
autocmd! | |
" Tabs at the beginning of a line are bad. Especially if they are mixed in with spaces. | |
autocmd BufEnter * call matchadd('BadWhitespace', '^\( *\t\+\)\+') | |
" Trailing whitespace is bad, too. | |
autocmd BufEnter * call matchadd('BadWhitespace', '\s\+$') | |
" Remove matches in help files. | |
autocmd BufEnter * call IgnoreHelpFiles() | |
augroup END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this to your .vimrc to highlight spaces and tabs at the end of lines, and tabs at the beginning of lines.