Want to take your software engineering career to the next level? Join the mailing list for career tips & advice Click here


Highlight trailing spaces and delete them in a flash.

Subscribe to updates I use TrailingSpaces

Statistics on TrailingSpaces

Number of watchers on Github 829
Number of open issues 68
Average time to close an issue 5 months
Main language Python
Average time to merge a PR 21 days
Open pull requests 13+
Closed pull requests 6+
Last commit about 4 years ago
Repo Created about 9 years ago
Repo Last Updated over 2 years ago
Size 111 KB
Organization / Authorsublimetext
Page Updated
Do you use TrailingSpaces? Leave a review!
View open issues (68)
View TrailingSpaces activity
View on github
Book a Mock Interview With Me (Silicon Valley Engineering Leader, 100s of interviews conducted)
Software engineers: It's time to get promoted. Starting NOW! Subscribe to my mailing list and I will equip you with tools, tips and actionable advice to grow in your career.
Evaluating TrailingSpaces for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

Trailing Spaces

A Sublime Text 2 and 3 plugin that allows you to

highlight trailing spaces and delete them in a flash!


Sublime Text provides a way to automate deletion of trailing spaces upon file saving (more on this at the end of this file). Depending on your settings, it may be more handy to just highlight them and/or delete them by hand, at any time. This plugin provides just that, and a lot of options to fine-tune the way you want to decimate trailing spaces.


It is available through Sublime Package Control and this is the recommended way of installation (brings configuration instructions, automatic updates with changelogs).

Alternative installation methods

From github

You can install from github if you want, although Package Control automates just that. Go to your Packages subdirectory under ST2's data directory:

  • Windows: %APPDATA%\Sublime Text 2
  • OS X: ~/Library/Application Support/Sublime Text 2
  • Linux: ~/.config/sublime-text-2
  • Portable Installation: Sublime Text 2/Data

Then clone this repository:

git clone git://github.com/SublimeText/TrailingSpaces.git


Download the plugin as a zip. Copy the Trailing Spaces directory to its location (see prior section).



The main feature you gain from using this plugin is that of deleting all trailing spaces in the currently edited document. In order to use this deletion feature, you may either:

  • click on Edit / Trailing Spaces / Delete;
  • bind the deletion command to a keyboard shortcut:

To add a key binding, open Preferences / Key Bindings - User and add:

{ "keys": ["ctrl+shift+t"], "command": "delete_trailing_spaces" }

With this setting, pressing Ctrl + Shift + t will delete all trailing spaces at once in the current file! For OSX users, quoting wbond: When porting a key binding across OSes, it is common for the ctrl key on Windows and Linux to be swapped out for super on OS X (eg. use super+ctrl+t instead).

Beware: the binding from this example overrides the default ST's mapping for reopening last closed file. You can look at the default bindings in Preferences / Key Bindings - Default.

Toggling highlighting

At any time, you can toggle highlighting on and off. You may either:

  • click on Edit / Trailing Spaces / Highlight Regions
  • bind the toggling command to a keyboard shortcut:
// I like "d", as in "detect" (overrides a default binding, though).
{ "keys": ["ctrl+shift+d"], "command": "toggle_trailing_spaces" }


Several options are available to customize the plugin's behavior. Those settings are stored in a configuration file, as JSON. You must use a specific file: Go to Preferences / Package Settings / Trailing Spaces / Settings \- User to add you custom settings. You can look at the default values in Settings - Default, in the same menu.

A few of them are also accessible through the Edit / Trailing Spaces menu. Sometimes, editing a setting will require a fresh Sublime Text to be applied properly, so try relaunching ST before reporting an issue ;)

All settings are global (ie. applied to all opened documents).

Changing the highlighting color

Default: invalid

You may change the highlighting color, providing a color scope name such as error, comment just like that:

{ "trailing_spaces_highlight_color": "comment" }

The scope should be defined in your current theme file. Here is a dummy, fully-fledged example (feel free to cut irrelevant pieces for your settings) of such a custom color scope:

  <string>Invalid - Illegal</string>

You would then use the value of invalid.illegal.

Keeping trailing spaces invisible

You can make trailing spaces invisible yet still rely on the deletion command. To do that, set the highlight scope to an empty string:

{ "trailing_spaces_highlight_color": "" }

Beware: this is not the same as disabling the highlighting (see On- Demand Matching below). With this setting, the plugin still runs when opening a file, and in the background afterwards; you just won't see the trailing spaces (they are being highlighted with a transparent color).

Include Current Line

Default: true

Highlighting of trailing spaces in the currently edited line can be annoying: each time you are about to start a new word, the space you type is matched as a trailing spaces. Currently edited line can thus be ignored:

{ "trailing_spaces_include_current_line": false }

Even though the trailing spaces are not highlighted on this line, they are still internally matched and will be delete when firing the deletion command.

Include Empty Lines

Default: true

When firing the deletion command, empty lines are matched as trailing regions, and end up being deleted. You can specifically ignore them:

{ "trailing_spaces_include_empty_lines": false }

They will not be highlighted either.

Modified Lines Only

Default: false (reopen ST to update)

When firing the deletion command, trailing regions in the entire document are deleted. There are some use-cases when deleting trailing spaces only on lines you edited is smarter; for instance when commiting changes to some third-party source code.

At any time, you can change which area is covered when deleting trailing regions. You may either:

  • click on Edit / Trailing Spaces / Modified Lines Only
  • specify as a setting:
{ "trailing_spaces_modified_lines_only": true }

There is also a command to toggle this feature on and off. You may thus define a key binding:

{ "keys": ["pick+a+shortcut"], "command": "toggle_trailing_spaces_modified_lines_only" }

Trim On Save

Default: false

Setting this to true will ensure trailing spaces are deleted when you save your document. It abides by the other settings, such as Modified Lines Only.

{ "trailing_spaces_trim_on_save": true }

Save After Trim

Default: false

You may not want to always trim trailing spaces on save, but the other way around could prove useful. Setting this to true will automatically save your document after you fire the deletion command:

{ "trailing_spaces_save_after_trim": true }

It is obviously ignored if Trim On Save is on.

Live Matching vs On-demand Matching

Default: true (reopen ST to update)

By default, trailing regions are matched every time you edit the document, and when you open it.

This feature is entirely optional and you may set it off: firing the deletion command will cause the trailing spaces to be deleted as expected even though they were not matched prior to your request. If you are afraid of the plugin to cause slowness (for instance, you already installed several heavy plugins), you can disable live matching:

{ "trailing_spaces_enabled": false }

In this case, for no trailing regions are matched until you request them to be deleted, no highlighting occursit is in fact disabled, regardless of your scope setting. If you want to check the trailing spaces regions, you can toggle highlighting on and off. In this case, it may come in handy to define a binding for the toggling command. When On-demand Matching is on and some trailing spaces are highlighted, added ones will obviously not be. Toggling highlight off and on will refresh them.

Ignore Syntax

Default: []

With this option you can ignore specific files/views based on the syntax used. An item has to match a case-sensitive substring of the syntax used in the view:

// Views with a syntax that contains "Diff" are ignored
{ "trailing_spaces_syntax_ignore": ["Diff"]}

For power-users only!

Disabled for large files

The plugin is disabled altogether for large files, for it may cause slowness. The default threshold is around 1 million of characters. This is configurable (in File Settings - User) and the unit is number of chars:

{ "trailing_spaces_file_max_size": 1000}

The matching pattern

Default: [ \t]+

Trailing spaces are line-ending regions containing at least one simple space, tabs, or both. This pattern should be all you ever need, but if you do want to abide by another definition to cover edge-cases, go ahead:

// *danger* will match newline chars and many other folks
"trailing_spaces_regexp": "[\\s]+"

About Sublime Text's built-in features

Trailing Spaces is designed to be a drop-in replacement of the limited Trim Whitespace On Save built-in feature. ST is indeed able to delete trailing spaces upon saving files, and maybe that's all you need!

In order to enable this behavior, edit Preferences / Settings - User to add the following:

{ "trim_trailing_white_space_on_save": true }

As Trailing Spaces bypasses this setting, you will have to uninstall it to benefit from this setting.

Made a little less obvious in the documentation are settings to showcase whitespaces (not only trailing ones!):

{ "draw_white_space": "all" }

and to ensure a newline is kept at end of file upon saving:

{ "ensure_newline_at_eof_on_save": true }

The former will display all whitespaces in your files. There is another value of selection which display whitespaces under (you got it) your current text selection.

TrailingSpaces open issues Ask a question     (View All Issues)
  • about 4 years Broken? trailing_spaces_include_current_line: false not being respected.
  • about 4 years Error trying to parse settings: Invalid Escape
  • over 4 years Plugin makes Sublime Text significantly slower
  • over 4 years on_activated: TrailingSpaces.trailing_spaces: 8.772s not slow?
  • over 4 years Isn't working on 3114
  • over 4 years don't highlight spaces for lines where cursor is at the end of line
  • over 4 years Deleting Empty Lines Question
  • over 4 years Option to only show trailing spaces on actual files
  • over 4 years Does not work on ST3
  • over 4 years Duplicate on_activated listener
  • almost 5 years trim_trailing_white_space_on_save:true invalidates undo action (ctrl+y)
  • almost 5 years Should not trim current line on save given these settings
  • almost 5 years "trailing_spaces_syntax_ignore" doesn't work
  • about 5 years Terminal pops up on Windows when saving
  • over 5 years "file_max_size" not taken into account?
  • over 5 years trailing_spaces_highlight_color not working
  • over 5 years Automatic trailing white spaces on line move
  • over 5 years Errors upon launch
  • over 5 years Highlights trailing spaces in input fields
  • about 6 years TrailingSpaces always trims on save although it's set to false
  • about 6 years Unable to prevent trim on Markdown files (pull #47 not working?)
  • over 6 years Doesn't seem to work with ST2
  • over 6 years Can't see any option in sublime text 3
  • over 6 years Trim spaces across all files in a folder
  • over 6 years Allow pattern at beginning of line when pattern matches entire line.
  • over 6 years Command to force to delete all trailing spaces
  • almost 7 years Border around highlighted whitespace
  • almost 7 years Wrong lines being highlighted
  • about 7 years Settings Being Overwritten?
  • about 7 years ST3: UnicodeDecodeError on non-UTF-8 files
TrailingSpaces open pull requests (View All Pulls)
  • Don't highlight spaces on build results view
  • Fix exception thrown on activating views with 'virtual' path #85
  • Only read file from disk when trim_modified_lines_only is enabled
  • Added support for non UTF-8 encoded files.
  • Quick fix in README.md
  • Allow "trailing_spaces_trim_on_save" to be set per syntax (thus also per-view).
  • Unhilight current line when in "edit mode"
  • Disable whitespace highlighting for views which are part of HexViewer
  • Improve character encoding compatibility
  • New config option: `trailing_spaces_scope_ignore`
  • Fix trimming of file that doesn't exist
  • Speedup matching
  • Proposed fix for exception while processing scratch buffers
TrailingSpaces questions on Stackoverflow (View All Questions)
  • Sublime plugin - trailingspaces - not working
TrailingSpaces list of languages used
Other projects in Python
Powered by Autocode - Instant Webhooks, Scripts and APIs
Autocode logo wordmark