我在Sublime Text 3中有以下两行:
Rectangle(Maxwell, "MagnetsWEstart" , "r_ta - h_pm", 42,"NdFe35", True, "WE")
Rectangle(Maxwell, "MagnetsWEend", "r_ta", 1984.42, "NdFe35",False, "WE")
我想对齐所有的逗号以及前面的文字在右边:
Rectangle(Maxwell, "MagnetsWEstart", "r_ta - h_pm", 42, "NdFe35", True, "WE")
Rectangle(Maxwell, "MagnetsWEend", "r_ta", 1984.42, "NdFe35", False, "WE")
我下载了Align Tab包并创建了键绑定
{ "keys": ["ctrl+shift+a"], "command": "align_tab", "args" : {"user_input" : ","} }
结果已经接近我想要的结果:
Rectangle(Maxwell , "MagnetsWEstart" , "r_ta - h_pm" , 42 , "NdFe35" , True , "WE")
Rectangle(Maxwell , "MagnetsWEend" , "r_ta" , 1984.42 , "NdFe35" , False , "WE")
但是如何在右边的逗号之间对齐表达式,并在逗号之前添加空格的红色?这甚至可能吗?
答案 0 :(得分:1)
与对齐标签对齐后,匹配
[(,] *\K(.+?)( +)(?=,)
替换为\2\1
答案 1 :(得分:1)
我找到了另一个解决方案。事实证明,Align选项卡有一个内置选项,您可以在正则表达式中添加。只需通过正则表达式对齐并输入,/r
。这意味着对齐。
答案 2 :(得分:0)
受ndn's answer启发的以下步骤最终导致了预期的结果:
1)安装reg_replace和Align tab包
2)包装:Reg_Replace - >设置 - >用户:
{
"replacements": {
"commaRightRegex": {
"find": "(\\s,)",
"replace": ",",
"greedy": true,
"case": false
}
},
"selection_only": true,
}
3)工具 - >新插件 - >包括run_multiple.py
4)密钥绑定 - >用户 - >添加:
{ "keys": ["ctrl+shift+a"],
"command": "run_multiple_commands",
"args": {
"commands": [
{"command": "align_tab", "args" : {"user_input" : ",/r"}},
{"command": "reg_replace", "args": {"replacements": ["commaRightRegex"]}}
]
}
}
最终将通过一个键盘快捷键启用所需的输出:
Rectangle(Maxwell, "MagnetsWEstart", "r_ta - h_pm", 42, "NdFe35", True, "WE")
Rectangle(Maxwell, "MagnetsWEend", "r_ta", 1984.42, "NdFe35", False, "WE")