rosstex
rosstex

Reputation: 823

Run the current file in IntelliJ?

I've recently tried to switch from Eclipse to IntelliJ as a debugger for my university course, and I'm really enjoying the auto-completion, Chronon backwards debugging and other nice features. But there's one thing that bugs the living hell out of me: I just want to run the current file!

In Eclipse, the "Run" button was intelligent enough to simply run the current file if it contained a main method, and use the last-ran file otherwise. But in IntelliJ, just running a file is much more complicated. You have to create a Run Configuration of the right file, and then select that Run Configuration, instead of just opening the file you want. This is a big hassle for me, especially since I have many different classes with main methods in most homeworks and projects.

I found that on Macs, Ctrl + FN + Shift + F10 will "Run Context Configuration", which is almost what I'm looking for. But for some reason, this key binding doesn't have an equivalent toolbar button that switches to the context configuration and just runs it, which would solve all my problems! Can anyone help me out?

Upvotes: 20

Views: 25172

Answers (11)

Josh
Josh

Reputation: 548

In the Settings, under Keymaps, this is called Run context configuration.

I think this is the entire file, not just the class..

Default seems to be ctrl+shift+r.

Keymap settings for run context configuration

In the IDE configuration (not project), under keymaps, there is a XML of keymaps, and you can also set this.

Ensure you close your IDE before changing this file.

You may need to create a keymap first for this file to be created.

  <action id="RunClass">
    <keyboard-shortcut first-keystroke="shift ctrl enter" />
  </action>

shift ctrl enter is the shortcut you want.

Upvotes: 0

serhii
serhii

Reputation: 71

just create new configuration with name for example Run current file, and configure running file as $FilePath$

for example my python config looks like this: enter image description here

select this config and that's all, now any selected file will be running by Run\Debug commands without any additional actions and manipulations

Upvotes: 0

Dmitry Ivanov
Dmitry Ivanov

Reputation: 585

After NetBeans, I was surprised that IntelliJ compiles all project files for the DEBUG only one Java file. So to run a single file I had to complete all the files.

Upvotes: 0

Matthias
Matthias

Reputation: 1

I think, @dimitrisli has still the correct answer: In IntelliJ on a Mac, If you want to run the current open file you can press control + shift + R

In addition: your focus should be in the file you want to run (you see the cursor blinking in the active file). But you can quickly jump into the editor by hitting Esc

Besides, IntelliJ provides you a list of shortcuts when you press command + shift + A and then begin to write what you want to do (e.g. "run").

Upvotes: 0

cazaimi
cazaimi

Reputation: 193

On Mac OS X: IntelliJ Idea:

control(^) + shift + r => Runs current file.

Bonus:

  1. Press Cmd + 1 to shift focus to the project structure
  2. Navigate to the file in question using arrow keys
  3. control + shift + r to run the file

Upvotes: 0

Jorge
Jorge

Reputation: 39

@dimitrisli answer was partially correct.

In fact, if you want to run the current script you need to use:

CONTROL + FN + SHIFT + F10

FN + SHIFT + F10 => runs the last execution

(but if you add CONTROL it will run the current script if the file has a main method or is a test class).

Upvotes: 1

BarthesSimpson
BarthesSimpson

Reputation: 954

Did this change since the original question? In 2018 on Mac I just do ctrl + r to re-run the last run file and ctrl + shift + r to run the current file.

Upvotes: 5

rosstex
rosstex

Reputation: 823

Years later, the simple answer: Right click inside the file and hit "Run"!

Upvotes: 8

Mark Jeronimus
Mark Jeronimus

Reputation: 9543

I can't find a "Run current file, otherwise selected context" action. I did find them separately.

Key binds for "Run current file":

  • Run context configuration
  • Debug context configuration

Upvotes: 12

Bastien Jansen
Bastien Jansen

Reputation: 8836

By default, the Run and Debug buttons run the last configuration. If you want to run the current file, right click in the editor and you'll see entries to run or debug the current file.

On Windows, I have Alt+ Shift + F6 to run a Java or JS file and Ctrl + Shift + F5 to debug (using the Netbeans keymap).

Upvotes: 0

dimitrisli
dimitrisli

Reputation: 21381

If you hover over the Run and Debug buttons you'll see the shortcuts. Given you're on a Mac OS and Fn is important to trigger F buttons here's the shortcuts:

Run: Shift + Fn + F10

Debug: Shift + Fn + F9

Upvotes: 8

Related Questions