by bomberstudios

TextMate 2 bundle: Strips trailing whitespace from current document when saving

127 Stars 24 Forks Last release: Not found 29 Commits 0 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Strip Whitespace On Save

TextMate 2 bundle: Strips trailing whitespace from current document when saving. Works nicely with my Save On Focus Lost bundle.


  • Clone the git repo to
    ~/Library/Application\ Support/TextMate/Bundles/Strip-Whitespace-On-Save.tmbundle
  • Relaunch TextMate 2


Customizing the bundle is easy.


Suppose you want to avoid stripping white space on some specific files (like CSV and YAML). Just add the following to your

scopeAttributes = attr.keep-whitespace

[*.yml] scopeAttributes = attr.keep-whitespace

If you wanted to preserve whitespace for that messed-up whitespace project of yours, just drop this in its

scopeAttributes = attr.keep-whitespace

Of course, you can combine those two approaches for complete control over whitespace-stripping!

If you want to know which scope corresponds to each language, just hit ^⇧P (Show Scope) on a document of that type, and you'll get a nice tooltip with the scope namespaces that apply at the current cursor's position.

Without Using

If you can't (or don't want to) use

files, just open the Bundle Editor (Bundles menu ▶︎ Edit Bundles... or pressing ^⌥⌘B) and add
in the command's Scope Selector field:

screenshot 2013-12-05 20 35 46

  • To exclude multiple file types, just add
    . For example, to exclude CSV and YAML, write:
    -text.tabular.csv -source.yaml
  • To work only on specific file types, use the namespace only, without the minus sign (e.g., to strip only CSV files, write
  • To include multiple file types, just add them separated by comma (i.e:
    text.tabular.csv, source.yaml, text.html.markdown


You need to be using at least TextMate version 2.0.0-alpha.9317.

To get the most recent nightly build, open Preferences ▶︎ Software Update and -click the "Check Now" button . This will grab the latest version, rather than the one you get by just clicking the button.


We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.