当我在 javascript 的字符串中间换行时,我真的很想有一些自动字符串连接。当我达到 80 个字符时,我通常必须中断,并且想要一种简单的方法来做到这一点。
例如:
var string = '<html>Here is some html in a string so it is going to be very long</html>';
我只想在中间换行,Sublime 文本会自动连接成
var string = '<html>Here is some html in a string so it is going' +
'to be very long</html>';
这可能吗?有插件吗?
最佳答案
你可以用一个宏来做到这一点,下面是我之前做的一个例子。
如果您想在 80 个字符以外的地方换行,可以将 width
参数更改为 wrap_lines
命令。您还可以替换不同的 characters
序列,例如如果您正在编辑 Python 并且想要插入三重引号。
将下面的脚本保存为 Sublime JSON 宏文件,例如split-literal.sublime-macro
。在 Sublime 中转到“Preferences->Browse Packages”,然后将宏文件复制到 Packages/User 中。该宏现在应该出现在“工具”->“宏”菜单中。
要为这个宏分配一个热键,转到“Preferences->Key Bindings - User”并将以下内容添加到键映射文件中:
[
{ "keys": ["ctrl+shift+w"], "command": "run_macro_file", "args": {"file":"Packages/User/split-literal.sublime-macro"} }
]
显然用您喜欢的任何热键代替 ctrl+shift+w
。
完整的 JSON 宏示例:
[
{
"args":
{
"width": 80
},
"command": "wrap_lines"
},
{
"args":
{
"by": "lines",
"forward": false
},
"command": "move"
},
{
"args":
{
"to": "eol"
},
"command": "move_to"
},
{
"args":
{
"characters": "' +"
},
"command": "insert"
},
{
"args":
{
"by": "lines",
"forward": true
},
"command": "move"
},
{
"args":
{
"to": "bol"
},
"command": "move_to"
},
{
"args":
{
"characters": " '"
},
"command": "insert"
},
{
"args":
{
"to": "eol"
},
"command": "move_to"
}
]
关于sublimetext2 - 如何在javascript中自动连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20405200/