Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build and run Rust code with a single Sublime Text shortcut?

I have installed the "Rust Enhanced" plugin onto Sublime Text 3126 and I am able to build and run a *.rs program opened in Sublime Text.

In reality, the process is a nightmare:

  1. Press Cmd+Shift+B
  2. Select Rust to compile
  3. Make sure there is no errors
  4. Press Cmd+Shift+B
  5. Select Rust - Run to run the last executable built

Cmd+B just repeats the last command executed.

How can this be shortened into a single shortcut?

like image 796
Pavel Vlasov Avatar asked Oct 21 '16 13:10

Pavel Vlasov


People also ask

How do I run a shortcut code in Sublime Text?

The shortcut key for this purpose is Ctrl+Shift+P for Windows and Cmd+Shift+P for Mac.


1 Answers

I like this answer posted on Quora, except that you don't have to do point 1 listed there. Here are the steps:

  1. Go to your workspace folder or wherever you're going to create your project.
  2. From the command line(Shift + Right click when inside the folder in Windows), invoke

    cargo new PROJECT_NAME --bin

  3. This creates a main.rs file inside src folder. Open it and code away.

  4. Run Ctrl + Shift + B once and select Cargo - Run. You can build (and run) with this from now on with only Ctrl + B.
like image 191
Stan Avatar answered Nov 15 '22 08:11

Stan