I am using Native Debug with GDB under VS Code. I can type any GDB command in the debug console. How can I run a fixed command in the debug console (not the terminal) using a shortcut?
I was only able to find editor.debug.action.selectionToRepl
(also known as "Evaluate in Debug Console") but this executes the currently selected text in the debug console. I want to execute a hardcoded command.
2
Answers
A hacky way that might work (not sure. put in keybindings.json):
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:
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.