Skip to content

Instantly share code, notes, and snippets.

@iturgeon
Created October 27, 2012 20:37
Show Gist options
  • Save iturgeon/3966100 to your computer and use it in GitHub Desktop.
Save iturgeon/3966100 to your computer and use it in GitHub Desktop.
SublimeText 2 CamelCase to SnakeCase Converter
[
{
"caption": "Snake Case: Convert CamelCase to snake_case",
"command": "snake_case"
}
]
import sublime, sublime_plugin, unicodedata, re, string
def add_underscores(s):
return re.sub('([A-Z]+)', '_\\1', s)
class SnakeCaseCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
content = self.view.substr(region)
self.view.replace(edit, region, add_underscores(content).lower())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment