【发布时间】:2018-06-05 20:15:56
【问题描述】:
我正在尝试使用 Sublime Text 3 中的 RegReplace 插件运行一系列命令,但我无法加载命令,也无法让键绑定工作。我不知道出了什么问题。
采取的步骤:
- 已安装 RegReplace
- 打开命令面板
- 搜索“RegReplace:创建新的正则表达式”
-
修改规则如下
""" If you don't need a setting, just leave it as None. When the rule is parsed, the default will be used. Each variable is evaluated separately, so you cannot substitute variables in other variables. """ # name (str): Rule name. Required. name = "extract_variables" # find (str): Regular expression pattern or literal string. # Use (?i) for case insensitive. Use (?s) for dotall. # See https://docs.python.org/3.4/library/re.html for more info on regex flags. # Required unless "scope" is defined. find = r".*\[(.*[^(<|>)]*?)\].*" # replace (str - default=r'\g<0>'): Replace pattern. replace = r"\1" # literal (bool - default=False): Preform a non-regex, literal search and replace. literal = None # literal_ignorecase (bool - default=False): Ignore case when "literal" is true. literal_ignorecase = None # scope (str): Scope to search for and to apply optional regex to. # Required unless "find" is defined. scope = None # scope_filter ([str] - default=[]): An array of scope qualifiers for the match. # Only used when "scope" is not defined. # # - Any instance of scope qualifies match: scope.name # - Entire match of scope qualifies match: !scope.name # - Any instance of scope disqualifies match: -scope.name # - Entire match of scope disqualifies match: -!scope.name scope_filter = None # greedy (bool - default=True): Apply action to all instances (find all). # Used when "find" is defined. greedy = None # greedy_scope (bool - default=True): Find all the scopes specified by "scope." greedy_scope = None # format_replace (bool - default=False): Use format string style replace templates. # Works only for Regex (with and without Backrefs) and Re (with Backrefs). # See http://facelessuser.github.io/backrefs/#format-replacements for more info. format_replace = None # selection_inputs (bool -default=False): Use selection for inputs into find pattern. # Global setting "selection_only" must be disabled for this to work. selection_inputs = None # multi_pass (bool - default=False): Perform multiple sweeps on the scope region to find # and replace all instances of the regex when regex cannot be formatted to find # all instances. Since a replace can change a scope, this can be useful. multi_pass = None # plugin (str): Define replace plugin for more advanced replace logic. plugin = None # args (dict): Arguments for 'plugin'. args = None # ---------------------------------------------------------------------------------------- # test: Here you can setup a test command. This is not saved and is just used for this session. # - replacements ([str]): A list of regex rules to sequence together. # - find_only (bool): Highlight current find results and prompt for action. # - action (str): Apply the given action (fold|unfold|mark|unmark|select). # This overrides the default replace action. # - options (dict): optional parameters for actions (see documentation for more info). # - key (str): Unique name for highlighted region. # - scope (str - default="invalid"): Scope name to use as the color. # - style (str - default="outline"): Highlight style (solid|underline|outline). # - multi_pass (bool): Repeatedly sweep with sequence to find all instances. # - no_selection (bool): Overrides the "selection_only" setting and forces no selections. # - regex_full_file_with_selections (bool): Apply regex search to full file then apply # action to results under selections. test = { "replacements": ["extract_variables"], "find_only": True, "action": None, "options": {}, "multi_pass": False, "no_selection": False, "regex_full_file_with_selections": False }
此代码在 AppData\Roaming\Sublime Text 3\Packages\User\reg_replace_rules.sublime-settings 中生成以下内容
{
"replacements":
{
"extract_variables":
{
"find": ".*\\[(.*[^(<|>)]*?)\\].*",
"name": "extract_variables",
"replace": "\\1"
}
}
}
然后我在文件名 Default.sublime-commands 的同一目录下创建了以下命令
[
{
"caption": "Reg Replace: Extract ERS Variables",
"command": "extract_ers_variables",
"args": {
"replacements": [
"extract_variables"
]
}
}
]
保存所有这些后,我仍然没有在命令面板中看到该命令,并且当我尝试将其保存为键盘映射时它也没有显示。
非常感谢任何帮助
【问题讨论】:
标签: regex sublimetext3 sublimetext