如果您使用Chain of Command,那麼您可以將鍵綁定定義爲一系列命令。 如果您不知道執行哪些命令,請打開控制檯ctrl+`
並編寫sublime.log_commands(True)
以顯示所有執行的命令。
所以你怎麼能存檔你的行爲:
- 複製當前選擇的變量
- 轉到行
- 的末尾插入控制檯日誌片斷中的下一行
- 粘貼複製變量
{
"keys": ["super+shift+l"],
"command": "chain",
"args": {
"commands": [
["copy"],
["move_to", {"to": "eol"}],
["move_to", {"to": "eol"}],
["insert_snippet", {"contents": "\nconsole.log(\"$1 = \" + $1);$0"}],
["paste"]
]
},
"context":
[
{ "key": "selector", "operator": "equal", "operand": "source.js" },
{ "key": "selection_empty", "operator": "equal", "operand": false }
]
},
另一種方法是編寫一個插件,在當前行的下面創建一個日誌命令。插件具有多個遊標支持的優點,並且不會更改剪貼板。按Tools >>> New Plugin...
和寫:
import itertools
import sublime_plugin
class LogVariableCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
for sel in view.sel():
if sel.empty():
continue
content = view.substr(sel)
line = view.line(sel)
# retrieve the current indent
indent = "".join(itertools.takewhile(lambda c: c.isspace(),
view.substr(line)))
view.insert(edit, line.end(),
"\n{0}console.log(\"{1} = \" + {1})"
.format(indent, content))
要分配鍵綁定使用:
{
"keys": ["super+shift+l"],
"command": "log_variable"
}
值得注意的包:[LogMagic(https://packagecontrol.io/packages/LogMagic) – idleberg