Strip Whitespace On Save
TextMate 2 bundle: Strips trailing whitespace from current document when saving. Works nicely with my Save On Focus Lost bundle. If you need whitespace highlighting, check the superb Whitespace bundle by Mads Hartmann. If you happen to need new lines at EOF, then check Mike Szyndel's Ensure New Line at the EOF bundle, which is based on mine.
- Clone the git repo to
- Relaunch TextMate 2
Strip Whitespace on specific filetypes
If you want to customize how the bundle works, it's easy.
Say you want to avoid stripping white space on some specific files (like CSV and YAML), just add the following to your
[*.csv] 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 .tm_properties file:
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 Ctrl + Shift + P ('Show Scope' command) 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.
Strip without using .tm_properties files
In any case, if you can't (or don't want to) use
.tm_properties files, you can just open the bundle editor (Bundles menu › Edit Bundles... or pressing Ctrl + Alt + Command + B) and add
-text.tabular.csv in the Scope Selector field of the command (see attached screenshot : )
If you need to exclude multiple file types, just add
(space)-scope.namespace. For example, if you want to exclude CSV and YAML, you'd write:
If you want the bundle to work only on specific file types, use the namespace only, without the minus sign (i.e: if you want to strip CSV files only, you'd write
text.tabular.csv). If you need 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. Open Preferences » Software Update and ALT-click the "Check Now" button to get the most recent nightly build (this will grab a latest version than the one you get by just clicking the button).