Skip to content

Instantly share code, notes, and snippets.

@bgreenlee
Created July 19, 2011 00:27
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgreenlee/1091026 to your computer and use it in GitHub Desktop.
Save bgreenlee/1091026 to your computer and use it in GitHub Desktop.
Sublime Text 2 plugin to strip trailing whitespace #python #sublimetext
import sublime_plugin
class StripTrailingWhitespaceCommand(sublime_plugin.TextCommand):
"""
Strip whitespace from the end of each line in the file.
"""
def run(self, edit):
trailing_white_space = self.view.find_all("[\t ]+$")
trailing_white_space.reverse()
for r in trailing_white_space:
self.view.erase(edit, r)
@bgreenlee
Copy link
Author

To bind to a key sequence, select Preferences -> User Key Bindings and add:

{ "keys": ["ctrl+super+s"], "command": "strip_trailing_whitespace" }

@cmdecker95
Copy link

Cool simple Sublime plugin! Why did you reverse the pattern matches in line 9?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment