Created
December 18, 2018 09:20
-
-
Save wanyaoqi/3df0cc46c28e57ce0891b247856c37c3 to your computer and use it in GitHub Desktop.
sublime plugin convert words snake to camle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sublime, sublime_plugin | |
| # keymap example | |
| # [ | |
| # { "keys": ["alt+r"], "command": "s2c" } | |
| # ] | |
| # this_is_test_words | |
| # this_is_test_words_ | |
| # _this_is_test_words | |
| class S2cCommand(sublime_plugin.TextCommand): | |
| def run(self, edit): | |
| # settings = sublime.load_settings("s2c.sublime-settings") | |
| # self.view.insert(edit, 0, "hello!") | |
| for region in self.view.sel(): | |
| origin_text = self.view.substr(region) | |
| converted_text = self.snake2camle(origin_text) | |
| self.view.replace(edit, region, converted_text) | |
| def snake2camle(self, origin_text): | |
| words = origin_text.split("_") | |
| converted_words = "" | |
| for word in words: | |
| if len(word) > 0: | |
| converted_words += word[0].upper() + word[1:] | |
| return converted_words |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment