Created
September 14, 2012 13:46
-
-
Save pironim/3722006 to your computer and use it in GitHub Desktop.
vim trailing space highlight
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
Unobtrusive highlighting of trailing whitespace in Vim | |
Sunday, September 13, 2009 | |
Many programmers highlight trailing whitespace red to expose that unnecessary gunk that is otherwise hard to spot. I did not much care about trailing whitespace, it was never a problem for me, though now the distributed version control systems tend to complain about this. | |
Highlighting the trailing whitespace is effective but has this unwanted side-effect of a red thing appearing under the cursor when typing space at the end of line (most of the time I type space at the end of line it seems). | |
This set of commands will only highlight the trailing whitespace on opening the buffer and leaving the insert mode. Inspired by the Vim tip wiki. | |
highlight ExtraWhitespace ctermbg=red guibg=red | |
au ColorScheme * highlight ExtraWhitespace guibg=red | |
au BufEnter * match ExtraWhitespace /\s\+$/ | |
au InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/ | |
au InsertLeave * match ExtraWhiteSpace /\s\+$/ | |
Some notes: ctermbg=red is for vim, guibg is for gvim. The second line is to prevent any color scheme to override the highlight settings. | |
OK, that feels better. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment