Ben Ward

Catching Trailing Whitespace in TextMate


Trailing whitespace is nasty, and there are various ways to go about catching it. There's a neat way of running TextMate's ‘strip trailing whitespace’ macro every time you save, for example, but that introduces an irritating lag if you're twitchy with ⌘S like I am.

So instead, you can edit the language definitions for the languages you use:

  name = 'invalid.whitespace';
  match = '\s+$';

Then, open TextMate preferences, and under Fonts & Colours add a new colour named “Trailing Whitespace” and enter ‘invalid.whitespace’ as the scope selector. Make it red, or grey, or whatever you like, and stray whitespace will now be highlighted.

You can file issues or provide corrections: View Source on Github. Contributor credits.