【发布时间】:2018-08-15 15:10:00
【问题描述】:
我发现自己在我的代码上做了很多修补程序,我必须在远程机器上进行测试。在 Visual Studio 代码中,有没有办法设置一个宏,将
- 保存所有打开的文件
- 提交更改(使用空白或随机提交消息)
- 上传所有提交
谢谢!
【问题讨论】:
标签: visual-studio-code vscode-settings vscode-tasks
我发现自己在我的代码上做了很多修补程序,我必须在远程机器上进行测试。在 Visual Studio 代码中,有没有办法设置一个宏,将
谢谢!
【问题讨论】:
标签: visual-studio-code vscode-settings vscode-tasks
不保存文件:
keybindings.json:
{
"key": "ctrl+alt+s",
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "git add . && git commit -a -m 'Update' && git push\u000D"
}
}
关于sendSequence:https://code.visualstudio.com/docs/editor/integrated-terminal#_send-text-from-a-keybinding
保存文件:
MoreThanTom 的answer 调整:
(使用https://marketplace.visualstudio.com/items?itemName=ryuta46.multi-command)
settings.json:
"multiCommand.commands": [
{
"command": "multiCommand.syncAllFiles",
"sequence": [
"workbench.action.files.saveAll",
{
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "git add . && git commit -a -m 'Update' && git push\u000D"
}
}
]
}
]
keybindings.json:
{
"key": "ctrl+alt+s",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.syncAllFiles" },
}
不需要tasks。
【讨论】:
为此,您需要一次运行多个命令,因此您需要一个扩展。使用ryuta46.multi-command 和此配置,Ctrl+Alt+S 将保存并推送您的所有文件
settings.json (Ctrl+,):
{
"multiCommand.commands": [{
"command":"multiCommand.syncAllFiles",
"sequence": [
"workbench.action.files.saveAll",
{
"command": "workbench.action.tasks.runTask",
"args": "syncAll"
},
"workbench.action.terminal.toggleTerminal"
]
}]
}
我添加了一个命令来在命令运行后切换终端,这样每次运行命令时它就不会保持打开状态。不幸的是,即使终端已经打开,它也会发生,所以如果你不希望它这样做,只需删除该行
keybindings.json (Ctrl+KCtrl+S):
{
"key": "ctrl+alt+s",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.syncAllFiles" },
},
tasks.json:
{
"tasks": [
{
"label": "syncAll",
"type": "shell",
"command": "git add .;git commit -m 'Automatic Commit';git pull;git push",
}
]
}
【讨论】:
git pull; git push,而是做了git pull origin master,这正是我所需要的。
我认为您可以设置一个任务来为您完成工作https://code.visualstudio.com/docs/editor/tasks
如果这还不够,请告诉我,我可以给你写一个例子。 任务中最好的事情是,您可以将它们绑定到热键
【讨论】: