Visual Studio : short cut Key : Duplicate Line

后端 未结 30 1307
[愿得一人]
[愿得一人] 2020-12-12 10:01

Is there a shortcut for Duplicate Line command in Visual Studio 2008?

Some similar examples:

  • in
相关标签:
30条回答
  • 2020-12-12 10:26

    For visual studio 2010, try using these commands for quick line duplication (uses clipboard):

    • Click on the line you want to copy. Ctrl + C will copy that line.

    • Then press Ctrl + Shift + Enter to insert a blank below insertion point

      (Alternatively use Ctrl + Enter to insert a blank line above the insertion point.)

    • Then simply use Ctrl + V to paste the line.

    0 讨论(0)
  • 2020-12-12 10:27

    In Visual Studio 2019

    Ctrl + D

    In Visual Studio 2017 (v15.6 and after)

    Ctrl + D

    In Visual Studio 2017 (pre v15.6)

    (edit) This feature is now built-in in VS2017: Ctrl + E, V duplicates a line if nothing is selected, or duplicates selection. You can assign it to a different key combination, or find it in the menu:

    See this reference for more information.

    Pre VS2017, built-in method using clipboard

    As @cand mentioned, you can just do Ctrl + C ; Ctrl + V.

    Ctrl + C will copy the line if nothing is selected.

    Macro solution (pre VS2017)

    If you'd like to implement a more complete solution, perhaps to create a simpler keyboard shortcut or you don't want to effect the clipboard, see this guide:

    Duplicate line command for Visual Studio

    Visual Basic:

    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    Imports System.Diagnostics
    
    Public Module DuplicateLastLineModule
        Sub DuplicateLine()
            Dim line As String
            DTE.ActiveDocument.Selection.StartOfLine(0)
            DTE.ActiveDocument.Selection.EndOfLine(True)
            line = DTE.ActiveDocument.Selection.Text
            DTE.ActiveDocument.Selection.EndOfLine()
            DTE.ActiveDocument.Selection.NewLine()
            DTE.ActiveDocument.Selection.StartOfLine(0)
            DTE.ActiveDocument.Selection.Text = line
        End Sub
    End Module
    

    To create the macro, just go to the macro explorer ("Tools->Macros->Macro Explorer" or Alt+F8) and copy paste the code in a new module. Now just assign a keyboard shortcut to it:

    1. go to Tools->Options...
    2. under Environment, click Keyboard
    3. in the "Show Commands Containing" textbox, enter "duplicate" (this according to the name you gave the module.)
    4. you should now see the macro in the list below
    5. choose "Text Editor" from the "Use new shortcut in" list
    6. set focus in the "Press shortcut keys" textbox and hit the combination on the keyboard you whish to use for it (Ctrl+Shift+D in my case)
    7. hit the "Assign" button
    8. you should now see the shortcut in the "Shortcuts for selected command" textbox
    9. hit the OK button

    And that's it. Enjoy!

    0 讨论(0)
  • 2020-12-12 10:27

    http://www.jetbrains.com/resharper/

    My story: started working in a new company, never used Visual Studio before. One of the first things - how to duplicate line. After setting up macro ReSharper told me: would you like to substitute my shortcut which was: "duplicate text" :)

    0 讨论(0)
  • 2020-12-12 10:28

    Just put your mouse on the line to copy and do CTRL+C ,afterwards CTRL+V on the same line. Works like magic :-)

    0 讨论(0)
  • 2020-12-12 10:29

    In visual studio 2008 you can use CTRL + C + V

    0 讨论(0)
  • 2020-12-12 10:30

    The command you want is Edit.Duplicate. It is mapped to CtrlE, CtrlV. This will not overwrite your clipboard.

    0 讨论(0)
提交回复
热议问题