Skip to content

Instantly share code, notes, and snippets.

@aheadley
Created August 29, 2012 18:12
Show Gist options
  • Save aheadley/3516436 to your computer and use it in GitHub Desktop.
Save aheadley/3516436 to your computer and use it in GitHub Desktop.
ST2 plugin to wrap selected text to 80 chars
import sublime, sublime_plugin
import textwrap
import re
class WrapTextCommand(sublime_plugin.TextCommand):
def run(self, edit, *args):
for region in self.view.sel():
if not region.empty():
m = re.match(r'^(\s*)', self.view.substr(region))
if m:
prefix = '\n' + m.group(1)
else:
prefx = '\n'
self.view.replace(edit, region,
prefix.join(textwrap.wrap(self.view.substr(region), 80)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment