Sublime Forum

How to run C/CPP programs in new tab of Sublime Text editor?

#1

I am using SublimeREPL for programming in python where I can execute the program directly by pressing ctrl + b and it executes in a new tab of sublime text.

I made a similar setup for C and C++ where I can compile the program by pressing ctrl +b and then run the program by pressing ctrl + shift + b but the problem is it executes in the console which opens below, I want to execute it in a new tab of sublime text, so is there any way to display errors and output of C/C++ programs in new window of sublime text?

0 Likes

#2


How my current C program executes

0 Likes

#3

The default behaviour for a sublime-build file is to use an internal command named exec to execute a build, and that command is what opens the panel at the bottom of the window to display the results in. Something like SublimeREPL gets around that by using custom plugin code and modifying the sublime-build file so that it executes a different command.

One way to do that is to use the Terminus package, which allows you to open a terminal directly into a normal tab if desired. It’s possible to use Terminus in combination with a custom sublime-build file to have Terminus execute the build in a tab, which would do what you want. This is of particular importance if you want to be able to interact with your program in any way because standard build systems don’t allow that.

This video shows an example of how you would use Terminus in a build system to do this (this video talks about Terminus in general and also has a similar example).

The examples in both videos use TCC as the tool, which can compile and run simple C programs in one step. In your case you would need to create your own sublime-build file to execute the correct command to build and run your program based on the tools that you use. In order to do that you need to know what commands you would manually enter into a terminal in order to compile and run your program, so that you can include that in the sublime-build file.

If you’re unfamiliar with build systems and how they work, this playlist contains a series of videos that covers them, so you may find that useful.

0 Likes