
我最近嘗試了atom。儘管速度太慢,但有一件事我很喜歡:自動縮排的工作方式,基本上無處不在。
我發現這裡如何Paste + Indent the default
在崇高文本中製作。
但我也希望:
{ "keys": ["ctrl+shift+up"], "command": "swap_line_up" },
{ "keys": ["ctrl+shift+down"], "command": "swap_line_down" },
變得swap_line_up_and_indent
這樣,如果我有:
console.log('hello');
function() {
}
而我ctrl+shift+down
,我得到:
function() {
console.log('hello'); // indented yai!!
}
任何機會?
答案1
因此,最簡單的方法(除了編寫一個相當廣泛的插件)是宏。這是swap_line_down_and_indent.sublime-macro
:
[
{
"command": "swap_line_down"
},
{
"command": "indent"
}
]
和swap_line_up_and_indent.sublime-macro
:
[
{
"command": "swap_line_up"
},
{
"command": "move",
"args":
{
"by": "lines",
"forward": true
}
},
{
"command": "indent"
}
]
將檔案儲存在選擇時開啟的資料夾的Packages/User
位置Packages
Preferences → Browse Packages…
。接下來,使用以下內容編輯自訂鍵盤映射:
{
"keys": ["ctrl+shift+up"],
"command": "run_macro_file",
"args":
{
"file": "res://Packages/User/swap_line_up_and_indent.sublime-macro"
}
},
{
"keys": ["ctrl+shift+down"],
"command": "run_macro_file",
"args":
{
"file": "res://Packages/User/swap_line_down_and_indent.sublime-macro"
}
}
你應該已經準備好了。不過,有一些注意事項。這些巨集只會縮排一級,因此您可能需要使用Ctrl]來進一步縮排該行。另外,假設要縮排的行是swap_line_[up|down]
命令運行後的下一行。
答案2
您也可以使用“命令鏈”套件來完成此操作。安裝該軟體包並將以下內容新增至使用者金鑰綁定檔案:
{
"keys": ["ctrl+super+up"],
"command": "chain",
"args": {
"commands": [
["swap_line_up"],
["reindent", {"single_line": false}]
],
},
},
{
"keys": ["ctrl+super+down"],
"command": "chain",
"args": {
"commands": [
["swap_line_down"],
["reindent", {"single_line": false}]
],
},
}