快捷键如下

匈牙利
所有单词首字母大写, 快捷键 ctrl+k ctrl+r 文本 user_blog 转换为 UserBlog

匈牙利变量
第一个单词首字母小写, 其它单词首字母大写, 快捷键 ctrl+k ctrl+e 文本 user_blog 转换为 userBlog

下划线
所有单词小写, 用下划线分隔, 快捷键 ctrl+k ctrl+r 文本 UserBlog 转换为 user_blog

添加快捷键
选择 Preferences - Key Bindings 添加如下 json

[ {"keys": ["ctrl+k", "ctrl+r"], "command": "variables_camel_case", "args": { "action": "CamelCase", "author": "dotcoo" } }, {"keys": ["ctrl+k", "ctrl+e"], "command": "variables_camel_case", "args": { "action": "CamelCaseVariable", "author": "dotcoo" } }, {"keys": ["ctrl+k", "ctrl+w"], "command": "variables_camel_case", "args": { "action": "Underscore", "author": "dotcoo" } } ]

安装插件

选择 Preferences - Browse Packages… 新建文件 VariablesCamelCase.py 代码内容如下:

import sublime import sublime_plugin import re # 注意缩进问题 class VariablesCamelCaseCommand(sublime_plugin.TextCommand): def run(self, edit, action='CamelCase', **kwargs): # action = kwargs['action'] if 'action' in kwargs else 'CamelCase' # author dotcoo regions = self.view.sel() for region in regions: if region.empty() : region = self.view.word(region.begin()) sel_text = self.view.substr(region) if action == 'CamelCase': sel_text = sel_text[0:1].upper() + re.sub(r'(_[a-z])', lambda m: m.group(1)[1:].upper(), sel_text)[1:] elif action == 'CamelCaseVariable': sel_text = sel_text[0:1].lower() + re.sub(r'(_[a-z])', lambda m: m.group(1)[1:].upper(), sel_text)[1:] elif action == 'Underscore': sel_text = re.sub(r'([A-Z])', '_\\1', sel_text).lstrip('_').lower() self.view.replace(edit, region, sel_text)