Back to Devexpress

How to: Assign a Keyboard Shortcut to a Refactoring

coderushforroslyn-401791-getting-started-examples-refactorings-how-to-assign-keyboard-shortcut-to-a-refactoring.md

latest1.7 KB
Original Source

How to: Assign a Keyboard Shortcut to a Refactoring

  • Apr 13, 2022
  • 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.

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

  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.

  4. Select the newly created folder and click Add a new shortcut to create a 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.

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

  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.

  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.