1

In Eclipse IDE in Properties -> General -> Keys
user can assign key binding for most command.

I want to bind Ctrl+R to (for example) Run As -> Node application but I cannot find it in the list (there are Run Java Application, Run Maven Build both with Alt+Shift+X, some key binding)

If desired Launch Type is not in list, how to configure it in plugin project sources?

(Yes, I can relaunch with Ctrl+F11, but it is not convenient for left hand and is NOT launching current Editor)

UPDATE: how do I map a key in eclipse to run the project run configuration? suggested Alt+R, S, 1 that is too long.

UPDATE 2:

All related that suggest a bit different solutions:

What exactly plugin.xml should have that user could assign Key binding?

Community
  • 1
  • 1
Paul Verest
  • 60,022
  • 51
  • 208
  • 332

1 Answers1

3

Try using Practically Macro Options

Just install it from the eclipse update site

http://puremvcnotificationviewer.googlecode.com/svn/trunk/PracticallyMacroGoogleUpdateSite

After installing and restarting eclipse. Go to Windows-->Preferences-->Practically Macro options-->Editor Macro Defenitions

Click "New" and select "Editor Macro script (Beanshell)" in Available Commands and click "Add"

Use the following script

import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.ui.DebugUITools;
    try
    {
      // Terminate process if it already exists from a previous launch 
      org.eclipse.debug.core.ILaunch[] allLaunches=DebugPlugin.getDefault().getLaunchManager().getLaunches();
      for (ILaunch l : allLaunches)
      {              
        if (l.getLaunchConfiguration().getName().equals("YOUR CONFIG NAME"))
        {
          console.write("terminating launch: " );
          console.writeln(l.getLaunchConfiguration().getName());
          l.terminate();
          break; 
        }
      }

        org.eclipse.debug.core.ILaunchConfiguration[] allConfigurations=DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations();
        for (ILaunchConfiguration config : allConfigurations) {
            if (config.getName().equals("YOUR CONFIG NAME"))
            {
                DebugUITools.launch(config, "debug");
                break;
            }
        }
    } catch (CoreException e) {
        e.printStackTrace();
    }
    finally{}

Notes:

  1. Replace the YOUR CONFIG NAME with whatever you want
  2. DebugUITools.launch can be changed to run or debug
  3. Specify a macro name in the "Macro info" section
  4. Assign an id started with 1.. If you want to be able to see this macro in the standard Eclipse key binding dialog

Now Click "ok"

Go to Windows-->Preferences-->General-->Keys

Select your macro's name and assign it to any key you want.

Finally dont forget to restart your eclipse again!

For more help:

http://sourceforge.net/p/practicalmacro/discussion/878739/thread/891ddd13

Sandhu Santhakumar
  • 1,678
  • 1
  • 13
  • 24
  • PracticallyMacro is great discovery for me. And it was already on SO http://stackoverflow.com/questions/1437323/assigning-a-keyboard-shortcut-for-a-specific-eclipse-build-configuration – Paul Verest Nov 11 '13 at 06:21
  • I have not not succeeded so far and need to switch to other tasks. I used launchConfigurationType id https://github.com/Nodeclipse/nodeclipse-1/blob/master/org.nodeclipse.debug/plugin.xml#L21 As it is not only for me, I need changing plugin. Some launch related code here https://github.com/Nodeclipse/nodeclipse-1/tree/master/org.nodeclipse.debug/src/org/nodeclipse/debug/launch – Paul Verest Nov 11 '13 at 06:42
  • Ultimate utility.. I am surprised why it is not a part of Eclipse. Use Eclipse Market Place for easy installation. – Apurva Singh Apr 08 '16 at 18:35
  • 1
    I do not have "Editor Macro script (Beanshell)" why? – centenond Jul 02 '16 at 22:23