将另一个文件的内容粘贴到当前文件中

Paste content of another file in current file

将另一个文件的内容粘贴到当前文件的键盘快捷键/命令名称是什么?

我想要类似于 vim

的功能
:r inputfile.txt 

inputfile.txt被粘贴到当前文件的插入点。

这可能对您有用:Replace File Name With ...。选项之一是替换为文件的内容。

您可以通过上下文菜单触发它,也可以为命令设置键绑定:

extension.replaceFileNameWithContent

不过您必须先 select 文件名。


如果您经常这样做,这里有一种简化流程的方法。

对 select 以前的文件名的另一个扩展 - 在您的 settings.json 中使用 Select By:

"selectby.regexes": {

  "selectFileName": {
    "backward": "\s+",        
    "backwardInclude": false,
    "showSelection": true
  }
}

和 运行 的一些键绑定 selection 和替换文件命令(在 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"
},

如果您想将键绑定限制为特定语言或语言组,请将 editorLangId == javascript 替换为您的文件 langID。

为了简单起见,我特意选择了相同的键绑定。第一个 运行s 如果你在编辑器中没有 selection,第二个 运行s 当你有 selection - 所以它们本质上是 运行 “按顺序”,当您键入 alt+s 两次时。演示(您必须按两次键绑定 - 由于某种原因,gif 没有捕捉到两次):