Autocomplete 升华文本2-括号和HTML标记的自动缩进
(注意:在这些示例中,我将使用管道符号“|”来表示光标) 在Sublime Text 2中,当我键入大括号时,它会自动添加一个匹配的大括号,如下所示:Autocomplete 升华文本2-括号和HTML标记的自动缩进,autocomplete,format,sublimetext2,indentation,auto-indent,Autocomplete,Format,Sublimetext2,Indentation,Auto Indent,(注意:在这些示例中,我将使用管道符号“|”来表示光标) 在Sublime Text 2中,当我键入大括号时,它会自动添加一个匹配的大括号,如下所示: {|} 光标位于两个大括号之间。然后,当我按Enter键时,它会自动添加一个额外的新行和缩进,结果是: { | } 但是,括号和HTML元素不会出现相同的缩进行为。例如,如果我键入一个括号“[”,它会自动添加匹配的括号,如: [|] 但当我按Enter键时,结果是: [ |] 它不会添加额外的行或缩进。类似地,当我键入“div.s
{|}
光标位于两个大括号之间。然后,当我按Enter键时,它会自动添加一个额外的新行和缩进,结果是:
{
|
}
但是,括号和HTML元素不会出现相同的缩进行为。例如,如果我键入一个括号“[”,它会自动添加匹配的括号,如:
[|]
但当我按Enter键时,结果是:
[
|]
它不会添加额外的行或缩进。类似地,当我键入“div.some-class”,然后键入Tab时,我得到:
括号:
[
|
]
HTML元素:
<div class="some-class">
|
</div>
|
我怎样才能做到这一点呢?安装EMMET插件,它可以做到这一点,还可以提供大量额外的强大功能,特别是用于编写HTML和CSS的功能。:) 如果您尚未安装Package control(用于轻松安装新软件包/插件),请按照说明进行安装
然后你只需按CTRL+SHIFT+p并编写
软件包控件:Instal Package
并找到EMMET并安装它。完成后,重新启动Sublime Text,它应该可以工作:)安装EMMET插件,它将完成这项工作,另外还有大量额外的强大功能,特别是用于编写HTML和CSS的功能。:)
如果您尚未安装Package control(用于轻松安装新软件包/插件),请按照说明进行安装
然后您只需按CTRL+SHIFT+p并编写软件包控件:Instal Package
,然后找到EMMET并安装它。完成后,重新启动升华文本,它应该可以工作:)解释
我刚刚为自己想出了如何做你清单上的一件事
我已经修改了当您按下“enter”
键时运行的正则表达式
检查此操作数“\\{$”
和此操作数“^code\}”的旧正则表达式
我添加了或检查,使用管道
也检查[
和(
)以相同的方式:“操作数”:“\\{$\\\[$\\\\\\\[$\\\\\\($”
和“操作数”:“^\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\[$\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
方向
导航到首选项>键绑定-用户
个人,我将文件放在顶部,通过简短、简单的绑定和底部的块绑定/关注来组织。我认为下面是更大的块。
将此新代码粘贴到文件中:
// Auto-insert line and indent on square bracket and bracket (parenthesis)
{ "keys": ["enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
[
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$|\\[$|\\($", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\}|^\\]|^\\)", "match_all": true }
]
},
{ "keys": ["shift+enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
[
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$|\\[$|\\($", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\}|^\\]|^\\)", "match_all": true }
]
},
请注意:
- 正如我所说,我的代码是这样处理括号的。(升华将括号称为“方括号”,区别于“方括号”和“大括号”。)
- 如果不希望在括号中使用此选项,请将第一个“操作数”检查更改为:
“操作数”:“\\{$\\\[$”
,并将下一行的“操作数”检查更改为:“操作数”:“^\\\\\\\\\\\\\\]”
- 最后,我猜Sublime对它的解析是正确的,但是我在右大括号的末尾有一个逗号
,
,这将假定后面还有一些键绑定。如果它是文件末尾右大括号之前的最后一个绑定,那么应该删除逗号
另外,至少在Supreme Text 3中,您关于缩进的问题已经解决。解释
我刚刚为自己想出了如何做你清单上的一件事
我已经修改了当您按下“enter”
键时运行的正则表达式
检查此操作数“\\{$”
和此操作数“^code\}”的旧正则表达式
我添加了或检查,使用管道
也检查[
和(
)以相同的方式:“操作数”:“\\{$\\\[$\\\\\\\[$\\\\\\($”
和“操作数”:“^\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\[$\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
方向
导航到首选项>键绑定-用户
个人,我将文件放在顶部,通过简短、简单的绑定和底部的块绑定/关注来组织。我认为下面是更大的块。
将此新代码粘贴到文件中:
// Auto-insert line and indent on square bracket and bracket (parenthesis)
{ "keys": ["enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
[
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$|\\[$|\\($", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\}|^\\]|^\\)", "match_all": true }
]
},
{ "keys": ["shift+enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
[
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$|\\[$|\\($", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\}|^\\]|^\\)", "match_all": true }
]
},
请注意:
- 正如我所说,我的代码是这样处理括号的。(升华将括号称为“方括号”,区别于“方括号”和“大括号”。)
- 如果不希望在括号中使用此选项,请将第一个“操作数”检查更改为:
“操作数”:“\\{$\\\[$”
,并将下一行的“操作数”检查更改为:“操作数”:“^\\\\\\\\\\\\\\]”
- 最后,我猜Sublime对它的解析是正确的,但是我在右大括号的末尾有一个逗号
,
,这将假定后面还有一些键绑定。如果它是文件末尾右大括号之前的最后一个绑定,那么应该删除逗号
另外,至少在Supreme Text 3中,您关于缩进的问题已经解决。对于大括号()“。最后一个大括号也是缩进的。我也有这个问题,但实际上是在一个单独的文件中引起的。它不是键绑定,但对我来说它在JavaScript.tmPreferences
文件中。我几乎肯定。我花了很长时间才找到问题,而且我没有在任何地方记录它。我认为在我删除的文件底部的dent括号
。另外,请注意,括号被称为括号
,而不是括号
。我想我找到了。打开Default>Indentation Rules.tmPreferences
,你会看到底部的行indentParens
,在咨询了它之后,我认为你应该编辑你的用户>缩进_Rules.tmPreferences
文件。大括号“()”不起作用。最后一个大括号也缩进了。我也有这个问题,但实际上是在一个单独的文件中造成的。这不是键绑定,而是对我而言
<div class="some-class">
|
</div>
// Auto-insert line and indent on square bracket and bracket (parenthesis)
{ "keys": ["enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
[
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$|\\[$|\\($", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\}|^\\]|^\\)", "match_all": true }
]
},
{ "keys": ["shift+enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
[
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$|\\[$|\\($", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\}|^\\]|^\\)", "match_all": true }
]
},