Because of this issue: Send Text to replc command
not being worked on there is no good way to accomplish what you want. The only thing to do is get the code you want to run into the clipboard and then paste it.
But here is another way to do that, using an extension I wrote that can run the vscode api and javascript. Using Find and Transform make this keybinding:
{
"key": "alt+r", // whatever you want
"command": "findInCurrentFile",
"args": {
"runWhen": "onceOnNoMatches", // cursor should not be on a word
"run": [
"$${",
"await vscode.env.clipboard.writeText('2*3');", // your code
"await vscode.commands.executeCommand('workbench.panel.repl.view.focus');",
"await vscode.commands.executeCommand('debug.replPaste');",
"await vscode.commands.executeCommand('repl.action.acceptInput');",
"}$$",
]
}
}
Your code to run goes into the await vscode.env.clipboard.writeText('2*3') line. \\u000D would add a newline to the repl.
The only restriction is that the cursor should not be on any word (I will look into relaxing that requirement) because that will cause a match and the run argument will not run.
Later I will show how that keybinding can also be a setting, rather than a keybinding alone (and thus the resulting command will appear in the Command Palette).
The last command repl.action.acceptInput makes the repl input run immediately which you may or may not want.

As written the keybinding can be run from anywhere, but you can add a when clause to restrict that if you wish.