How to create a shortcut to build and run Rust code from inside VS Code

Viewed 105

consider this simple rust program:

fn main() {
    println!("Hello, Man!");
}

I created a shortcut in Vs Code at:

{
  "key": "ctrl+shift+enter",
  "command": "rust-analyzer.run"
}

Now when i press ctrl+shift+enter, it should build and run the rust program and display the output in the built in terminal in VS Code.

When i press ctrl+shift+enter, it opens a window for me at the top offering several options, i choose run <program_name>:

enter image description here

Now i want VS Code to choose run <program_name> automatically, i do not want it to offer the 3 options, i want it to just build and run when i press ctrl+shift+enter.

Any ideas how can i do that ?

1 Answers

You could try setting the shortcut to cargo run instead?

{
  "key": "ctrl+shift+enter",
  "command": "cargo run"
}
Related