New CodeRush Feature: Quick Pair (Parens, Brackets, Quotes, etc.) for Visual Studio

Today was the first CodeRush Feature Wednesday webinar presented by Rory Becker and myself. And for our first feature we decided to implement something I wanted – a better way to enter paired delimiters in code. When entering paired delimiters, there seem to be a number of common scenarios:

  • Enter the pair and move on (for example, parens in a C# method call that takes no arguments)
  • Enter the pair and place the caret between the pair (but then you have the challenge of moving outside the pair)
  • Surround a selection with the pair

To implement this feature, in the webinar we created a new Action called QuickPair which accepts leading and trailing delimiters, and an optional third parameter to determine whether the caret goes inside the delimiters or to the right outside the delimiters.

You can download and install the feature here:

This plug-in includes shortcut bindings based on the US keyboard. You may need to change these bindings to match your keyboard locale settings. For example, on a US keyboard, the parens are located above the 9 and 0 keys, respectively, like this:



The curly braces are above the brackets:



The angle brackets are above the comma and period keys:



And the double-quote is above the apostrophe (and the key to the left is the semi-colon):



With each of these key pairs, we’ve assigned two functionalities. The left key (e.g., Ctrl+[ ) places the caret between the two delimiters (adding a field, so you can just press Enter to get to the right of the delimiter pair), and the right key (e.g., Ctrl+] ) places the caret after the two delimiters (no fields needed). If there’s a selection, the left key will embed the selection within the delimiters (maintaining the original selection), and the right key will embed the selection within the delimiters, extending the selection to include the delimiters. Examples of all the bindings created in the webinar appear below.

Given these key positions, the table below shows available functionality (the “|” character indicates the caret position and the blue background indicates the selection, after code is inserted):

On a US Keyboard, press this: to get this:
(no selection)
or to modify a selection:
Ctrl+(   (|)   (My Selection)
Ctrl+)   ()|   (My Selection)
Ctrl+[   [|]   [My Selection]
Ctrl+]   []|   [My Selection]
Ctrl+Shift+{   {|}   {My Selection}
Ctrl+Shift+}   {}|   {My Selection}
Ctrl+Shift+<   <|>   <My Selection>
Ctrl+Shift+>   <>|   <My Selection>
Ctrl+;   "|"   "My Selection"
Ctrl+"   ""|   “My Selection”
Ctrl+=   (|) =>   (My Selection) =>

You may notice a lack of symmetry with the Ctrl+= binding (there is no corresponding binding to place the caret to the right of the lambda operator). I omitted this binding due to a lack of a suitable neighboring key to the equals sign. If you want to correct this asymmetry and add your own binding, feel free to. After installing this plug-in, you may view or change the shortcuts bindings in the IDE\Shortcuts options page. The QuickPair bindings are in the Code\QuickPair folder:


Have a request for a new feature? Email and let us know what you’d like to see us build for you on CodeRush Feature Wednesdays.

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.