问题描述
将另一个文件的内容粘贴到当前文件中的键盘快捷键/命令名称是什么?
我想要类似于vim的功能
:r inputfile.txt
和 inputfile.txt 会在插入点粘贴到当前文件中。
解决方法
这可能对您有用:Replace File Name With ...。选项之一是用文件的内容替换。
您可以通过上下文菜单触发它,也可以为命令设置按键绑定:
extension.replaceFileNameWithContent
尽管如此,您必须首先选择文件名。
如果您这样做,这是一种简化流程的方法。
具有另一个扩展名以选择先前的文件名-在您的settings.json中使用Select By,
"selectby.regexes": {
"selectFileName": {
"backward": "\\s+","backwardInclude": false,"showSelection": true
}
}
和一些用于运行选择和替换文件命令的键绑定(在keybindings.json中):
{
"key": "alt+s",// whatever keybinding you wish
"command": "selectby.regex","args": ["selectFileName"],"when": "editorTextFocus && !editorHasSelection && editorLangId == javascript"
},{
"key": "alt+s",// same keybinding as above
"command": "extension.replaceFileNameWithContent","when": "editorTextFocus && editorHasSelection && editorLangId == javascript"
},
如果要将键绑定限制为特定语言或一组语言,请用文件langID替换editorLangId == javascript
。
我特意选择了相同的键绑定以使其变得简单。如果您在编辑器中没有选择,则第一个运行;而当您选择时,第二个运行-因此,当您键入 alt + s 时,它们实际上按顺序运行>两次。演示(您必须按两次绑定键-gif由于某种原因未能同时捕获两者):