Smart Duplicate Line
- 3 minutes to read
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 is available in C#, Visual Basic, HTML, XAML, and Blazor code.
The following screencast shows how the Smart Duplicate Line works in Blazor.
How to Use
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.
Note
Use the Esc key to dismiss unnecessary text fields.
Features
Underline Changed Code
CodeRush underlines changed code based on previous edits or after automatically incremented numbers.
Use Ctrl+Z to undo the automatic changes and restore the original line/selection.
To stop replacing a text string with another in a code file, right-click the text and select the “Stop replacing X with Y in this file” context menu item.
Increment/Decrement Decimal, Float, Double, Hex, and Octal Literals
The Smart Duplicate Line increments/decrements decimal, float, double, hex, and octal literals if it detects an increment pattern.
Note
When the Smart Duplicate Line duplicates items in collection initializers and in parameter lists, it adds commas automatically, if needed.
Increment/Decrement Single Letter Identifiers Parts
The Smart Duplicate Line can increment/decrement single letter identifiers and their parts based on a detected alphabetical pattern in the code.
Recognize Enum Element References and Cycle Through Elements
This feature recognizes enum element references and cycles through those elements if it detects an enum element cycling pattern in the surrounding code.
Recognize Camel Case Parts of Identifier Name and Link Identifiers Similar Parts
To enable this functionality, check the following options in the Editor | All Languages | Linked Text & Fields options page:
- Link matching text across different kinds of elements.
- Include partial matches (camel case parts).
Duplicate Parameters and Arguments in Method Declarations and Calls
You can declare new parameters based on the selection and existing parameters.
Options
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.
Change the Default Shortcut
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.