The Smart Duplicate Line helps you create structurally similar code lines with minimal changes. This feature duplicates a code line and inserts text fields into the duplicate to simplify code modification. The Smart Duplicate Line can also change cloned values based on a detected pattern.
This feature works in C#, Visual Basic, XAML, and HTML code.
Place the caret in a code line you want to duplicate.
Press the Shift+Enter shortcut to copy the code.
The Smart Duplicate Line creates text fields for the code line parts you can change. It also links identifiers used several times in the code. You can edit one identifier and all other identifiers reflect the changes.
Use the Esc key to dismiss unnecessary text fields.
The Smart Duplicate Line increments/decrements decimal, float, double, hex, and octal literals if it detects an increment pattern.
When the Smart Duplicate Line duplicates items in collection initializers and in parameter lists, it adds commas automatically, if needed.
The Smart Duplicate Line can increment/decrement single letter identifiers and their parts based on a detected alphabetical pattern in the code.
This feature recognizes enum element references and cycles through those elements if it detects an enum element cycling pattern in the surrounding code.
To enable this functionality, check the following options in the Editor | All Languages | Linked Text & Fields options page:
You can declare new parameters based on the selection and existing parameters.
You can configure how CodeRush generates links and fields in the Editor | All Languages | Linked Text & Fields options page. The screenshot below shows the default options.
You can change the default Shift+Enter shortcut for the DuplicateLine command in the IDE | Shortcuts options page.
Find the DuplicateLine command's shortcut (Shift + Enter) and select it.
Change the First shortcut text field and press OK to apply this change.