ReSharper Help

Duplicate Line or Selection

ReSharper | Edit | Duplicate Text
Ctrl+D
ReSharper_DuplicateText

One of the ways of creating a code element similar to an existing one (e.g. a nwe method overload, 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 (Ctrl+D) the cloned code is inserted right after the original.

To 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 Ctrl+W one or more times; to select the current declaration, press Ctrl+Shift+[.

  2. Press Ctrl+D or choose ReSharper | Edit | Duplicate Text in the main menu .
  3. The duplicated line is inserted below the original line; 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/technologies:

C# VB.NET C++ HTML ASPX Razor JavaScript TypeScript CSS XML XAML RESX Build Scripts
feature_available feature_available feature_available feature_available feature_available feature_available feature_available feature_available feature_available feature_available feature_available feature_available feature_available

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.

See Also

Last modified: 3 September 2015