forvaidya
forvaidya

Reputation: 3315

Paste content of another file in current file

What is a keyboard shortcut / command name to paste the content of another file into the current file?

I want functionality similar to vim

:r inputfile.txt 

and inputfile.txt gets pasted into the current file at the insertion point.

Upvotes: 0

Views: 799

Answers (1)

Mark
Mark

Reputation: 181349

This might work for you: Replace File Name With .... One of the options is to replace with the file's content.

You can either trigger it via the context menu or set a keybinding to the command:

extension.replaceFileNameWithContent

You would have to select the fileName first though.


Here is a way to simplify the process if you do this alot.

With another extension to select the previous fileName - using Select By with this in your settings.json:

"selectby.regexes": {

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

and some keybinding to run the selection and replace file command (in 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"
},

Replace editorLangId == javascript with your file langID if you want to limit the keybinding to a particular language or group of languages.

I deliberately chose the same keybinding to make it simple. The first one runs if you have no selection in the editor and the second runs when you do have a selection - so they essentially run "in sequence" when you type alt+s twice. Demo (you do have to press your keybinding twice - the gif didn't capture both for some reason):

replace with file contents demo

Upvotes: 1

Related Questions