How to use shortcut keys to run the current individual cpp file in CLion?

188 views Asked by At

I want to clarify that answering is not as simple as pressing Ctrl + Shift + F10. When using CLion, if I am working on a cpp project, indeed I can directly run the entire project using the aforementioned shortcut. However, it is different when I am editing a single file.

  • When I create a new file and want to run it, I have to click on the green triangle on the left side of the main function, and then select the "Run..." option to execute the program. It's really frustrating (although I found that after clicking that triangle, I can use Ctrl + Shift + F10 to run the file).

    enter image description here

  • Another shortcut for running is Shift + F10. The peculiarity of this shortcut is that regardless of the currently active page, it will run the last executed file. To run the current file using this shortcut, I either have to repeat the previous method or open a window to select a run configuration, which is quite cumbersome.

I hope to find a solution that closely resembles the functionality of clicking the green triangle (preferably native), which means I don't want to use terminal commands for compilation and execution like the "Run Code" feature in VSCode.

  • The IDE action corresponding to Ctrl + Shift + F10 is "Run Class," while the action corresponding to Ctrl + Shift is simply "Run." This information can be found using the IdeaVim's "track action id" feature. I tried to achieve this by editing the keymap in Vim, but I was not successful. The main issue lies in switching the run configuration.

  • IdeaVim was not able to replicate all Vim commands perfectly. Its support for :let and :echo is not as flawless. The persistence of a purely keyboard-driven workflow makes one want to eliminate almost all unnecessary mouse work...

I have added some shortcut keys for editing the Run configuration (and since I don't know how to automate this process with variables, I had to add another shortcut key to retrieve the file path for filling in the "Source file" option). This way, I can manually create a Run configuration and then select it to run the current file.

Indeed, doing it this way is certainly very cumbersome.

enter image description here

0

There are 0 answers