[英]Why when saving(ctrl+s) a small python file in VSCode, the save takes a second and temporarily creates a copy of it?
[英]Is there a way to copy a file on save vscode
B
文件夹中的代码文件file
A
有没有办法在 vscode 中保存这个文件/多个文件?
我有两个文件夹A
和B
。 文件夹B
中有一些代码必须复制粘贴到文件夹A
才能执行。 但是版本控制在这个文件的文件夹B
上,所以我必须在那里编码。
我终于做到了,所以我分享它:使用 Visual Studio Code 扩展:多命令(来自@ryuta46)和命令运行器(来自@ed.net)我可以添加一个在“Ctrl+s”上触发的“多命令”将文件复制到另一个目录的快捷键(保存文件时):
添加到 settings.json创建一个名为 copyFile 的新“多命令”:根据需要调整目标。 此命令保存文件,等待 2 秒,然后复制到另一个位置。
"multiCommand.commands": [
{
"command": "multiCommand.copyFile",
"label": "Copy file to another location",
"description": "copy the current $file to another root hard-coded destination, require 'command-runner' plugin.",
"interval": 2,
"sequence": [
"workbench.action.files.save",
{
"command": "command-runner.run",
"args": { "command": "cp \"${file}\" \"x:/${relativeFile}\"" }
}
]
}
]
添加到 keybindings.json在 'Ctrl+s' 上触发先前定义的 copyFile 多命令
[
{
"key": "ctrl+s",
"command": "extension.multiCommand.execute",
"args": {
"command": "multiCommand.copyFile"
},
"when": "editorTextFocus"
}
]
这可以通过单个宏扩展来完成,例如Multi-Command 。 在您的keybindings.json
中进行此键绑定:
{
"key": "alt+s", // whatever keybinding you want
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.action.files.save",
{
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "cp '${file}' '${relativeFileDirname}\\copyTo'\u000D"
}
}
]
}
}
sendSequence
命令将参数文本发送到终端 - 示例脚本假定为类似 bash 的 shell。
如您所见,它将当前文件保存并复制到与当前文件位于同一父目录下的copyTo
文件夹中。
这是一个返回,因此该命令会立即运行,而无需手动点击返回。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.