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.
Labels: Vim
Comments
Previous posts
- Extreme programming too extreme?
- Applied computer science
- Sony PRS 505 ebook reader review
- Unlock Huawei E220 - soap on a rope
- Twitter outage
- Quad Head
- HLint
- Snowing in London
- Beautiful Code: Resolver One
- Mailless mailing list
Popular
- Beautiful Code: Resolver One
- Debugging memory leaks in IronPython apps
- Why Vim's modes frustrate newbies
- Four-monitor desktop
- xmonad
- Antipattern: static subject to observer map