Skip to main content
A newer version of this page is available. .

How to: Assign a Keyboard Shortcut to a Refactoring

  • 2 minutes to read

You can use the ExecuteRefactoring command to run a CodeRush 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 Ctrl+Shift+3 shortcut to the ExecuteRefactoring command:

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

access-shortcuts-menu

2) Click New Shortcut to create a shortcut.

add-new-shortcut

3) Specify the Ctrl+Shift+3 shortcut in the “First shortcut” text box, and another shortcut in the “Second shortcut” text box (optional).

specify-first-shortcut

4) Choose ExecuteRefactoring from the “Command” combo box.

choose-command

5) Type code action names, separated by semicolons, in the “Parameters” text box. The ExecuteRefactoring command can run one of the specified refactorings and code providers or invoke the Code Actions menu, if multiple code actions are available.

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 Extract String to Resource and Make Implicit refactorings.

specify-command-parameter

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

actions-catalog-page

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

7) Open the code editor and press the shortcuts key (Ctrl+Shift+3 in this example) to run the ExecuteRefactoring command.

run-command