ReSharper 2021.1 Help

Duplicate Line or Selection

ReSharper | Edit | Duplicate Text
Control+D
ReSharper_DuplicateText

One of the ways of creating a code element similar to an existing one (for example, a new method overload or a new auto-implemented property) is cloning the existing element with copy-paste and then editing the clone.

ReSharper helps you streamline the cloning part — with a single keystroke Control+D the cloned code is inserted right after the original.

Quickly duplicate the current line or selection

  1. If you want to clone a line, set the caret at this line line. To clone an arbitrary piece of code, select it in the editor.

    To select a logical code block, press Control+W one or more times; to select the current declaration, press Control+Shift+OemOpenBrackets.

  2. Press Control+D or choose ReSharper | Edit | Duplicate Text from the main menu. Alternatively, you can press Control+Shift+A, start typing the command name in the popup, and then choose it there.

  3. The duplicated line or multi-line selection is inserted below the original line or selection; the duplicated inline selection is inserted to the right of the original.

  4. If you have duplicated a selection, the selection stays at the clone. If necessary, you can press Ctrl+Shift+Alt and then use arrow keys to move the clone to the desired position.

This feature is supported in the following languages and technologies:

Language: C#Language: VB.NETLanguage: C++Language: HTMLLanguage: ASP.NETLanguage: RazorLanguage: JavaScriptLanguage: TypeScriptLanguage: CSSLanguage: XMLLanguage: XAMLLanguage: ResxLanguage: Build ScriptsLanguage: ProtobufLanguage: JSON
Feature is available in C#Feature is available in Visual Basic .NETFeature is available in C++Feature is available in HTMLFeature is available in ASP.NETFeature is available in RazorFeature is available in JavaScriptFeature is available in TypeScriptFeature is available in CSSFeature is available in XMLFeature is available in XAMLFeature is available in Resource filesFeature is available in build script filesFeature is available in ProtobufFeature is available in JSON

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.

Last modified: 08 March 2021