Visual Studio: hotkeys to move line up/down and move through recent changes

前端 未结 9 2227
清酒与你
清酒与你 2020-12-07 11:53

I\'m moving from Eclipse to Visual Studio .NET and have found all my beloved hotkeys except two:

  • in Eclipse you can press ALT- and
9条回答
  •  情话喂你
    2020-12-07 12:19

    If you haven't already found it, the place where these keyboard shortcuts are setup is under Tools | Options | Environment | Keyboard. A lot of handy commands can be found just by browsing through the list, although unfortunately I've never found any good reference for describing what each command is intended to do.

    As for specific commands:

    • I believe the forward/backward navigation commands you're referring to are View.NavigateBackward and View.NavigateForward. If your keyboard isn't cooperating with the VS key bindings, you can remap them to your preferred Eclipse keys. Unfortunately, I don't know of a way to change the algorithm it uses to actually decide where to go.

    • I don't think there's a built-in command for duplicating a line, but hitting Ctrl+C with no text selected will copy the current line onto the clipboard. Given that, here's a simple macro that duplicates the current line on the next lower line:

    
        Sub CopyLineBelow()
            DTE.ActiveDocument.Selection.Collapse()
            DTE.ActiveDocument.Selection.Copy()
            DTE.ActiveDocument.Selection.Paste()
        End Sub
    
        Sub CopyLineAbove()
            DTE.ActiveDocument.Selection.Collapse()
            DTE.ActiveDocument.Selection.Copy()
            DTE.ActiveDocument.Selection.LineUp()
            DTE.ActiveDocument.Selection.Paste()
        End Sub
    
    • For moving a line of text around, Edit.LineTranspose will move the selected line down. I don't think there's a command for moving a line up, but here's a quick macro that does it:
    
        Sub MoveLineUp()
            DTE.ActiveDocument.Selection.Collapse()
            DTE.ActiveDocument.Selection.Cut()
            DTE.ActiveDocument.Selection.LineUp()
            DTE.ActiveDocument.Selection.Paste()
            DTE.ActiveDocument.Selection.LineUp()
        End Sub
    

    If you haven't yet started playing with macros, they are really useful. Tools | Macros | Macros IDE will take you the editor, and once they're defined, you can setup keyboard shortcuts through the same UI I mentioned above. I generated these macros using the incredibly handy Record Temporary Macro command, also under Tools | Macros. This command lets you record a set of keyboard inputs and replay them any number of times, which is good for building advanced edit commands as well as automating repetitive tasks (e.g. code reformatting).

提交回复
热议问题