Skip to main content

How to: Assign a Keyboard Shortcut to a Refactoring

  • 2 minutes to read

You can use the ExecuteRefactoring command to run a CodeRush code action (refactoring or code provider) without invoking the Code Actions menu. If two or more code actions are available in the current code context, this command invokes the Code Actions menu where you can choose the desired code action.

Follow the steps below to bind the Caps+K shortcut to the ExecuteRefactoring command:

  1. Choose CodeRush | Shortcuts… from Visual Studio’s menu to open the Shortcuts configuration page.

    access-shortcuts-menu

    Note

    To use the Caps Lock key as a modifier, ensure this feature is enabled in the Setup Wizard, Quick Setup or IDE | Caps as a Modifier CodeRush options page. To engage/disengage the Caps Lock key, double-tap it in Visual Studio. See the following topic for details: Caps as a Modifier.

  2. Click Add a new folder to create a new folder for custom shortcuts.

    add-new-folder

  3. In the “New Folder” dialog, specify the folder name, check the “Make this a top level folder” checkbox to create a folder at the root hierarchy level, and click OK.

    specify-folder

  4. Select the newly created folder and click Add a new shortcut to create a shortcut.

    add-new-shortcut

  5. Specify the Caps+K shortcut in the “First shortcut” text box. Click the ellipsis button to add the Caps modifier to this shortcut.

    specify-first-shortcut

  6. Choose ExecuteRefactoring from the “Command” combo box.

    choose-command

  7. Type code action names, separated by semicolons, in the “Parameters” text box. If only one of the specified code actions is available in the code context, the ExecuteRefactoring command runs this action. Otherwise, the command invokes the Code Actions menu.

    Note

    You can also type the “*” character in the “Parameters” text box to include all available CodeRush code actions in this command.

    In this example, type the following code actions in the “Parameters” text box:

    specify-command-parameter

    You can find names of supported code actions (refactorings and code providers) on the Editor | Language | Code Actions | Code Actions Catalog CodeRush options page.

    actions-catalog-page

  8. Click OK to apply the changes and close the Shortcuts options page.

  9. Open the code editor and press the Caps+K shortcut key to run the specified code actions for the ExecuteRefactoring command.

    run-command