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

前端 未结 9 2091
清酒与你
清酒与你 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:07

    I have recently done the same thing and moved from Eclipse to Visual Studio when I moved onto a new project. The Resharper add in is highly recommended - it adds some of the rich editing, navigational and refactoring functionality that eclipse has to VS.

    Resharper also allows you to use a keybaord mapping scheme that is very simillar to InteliJ. Very handy for the Java escapees...

    Regarding your second question, Resharper has the same move code up / down function as eclipse, but with some caveats. Firstly, using the InteliJ keyboard mappings, the key combination is rather tortuous.

    Move code up: ctrl + shift + alt + up cursor

    Move code down: ctrl + shift + alt + down cursor

    Secondly, it does not always move by just one line, but actually jumps code blocks. So it cannot move a line from outside an if statement to inside it - it jumps the selected line right over the if block. To do that you need to move "left" and "right" using

    Move code into outer code block: ctrl + shift + alt + left cursor

    Move code into next inner code block: ctrl + shift + alt + right cursor

    0 讨论(0)
  • 2020-12-07 12:07

    Paul Ostrowski I tried your tool. It works mostly okay.

    The other thing that eclipse does is move the line to the current indentation level.

    For example:

    function test()
    {
        // do stuff
    }
    Console.WriteLine("test"); 
    

    Doing a shift-up on console.writeline would change it to

    function test()
    {
        // do stuff
        Console.WriteLine("test"); 
    }
    

    but your tool seems to do this:

    function test()
    {
        // do stuff
    Console.WriteLine("test"); 
    }
    
    0 讨论(0)
  • 2020-12-07 12:10

    For anyone looking for a way to do this in Visual Studio 2010, the free Visual Studio 2010 Pro Power Tools extension adds the capability to move lines up and down.

    http://visualstudiogallery.msdn.microsoft.com/en-us/d0d33361-18e2-46c0-8ff2-4adea1e34fef

    0 讨论(0)
  • 2020-12-07 12:17

    Use the MoveLine extension to move a line (or group of lines) up or down in VS 2010/2012.

    0 讨论(0)
  • 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).

    0 讨论(0)
  • 2020-12-07 12:24

    Record a macro in visual studio to do the alt-arrow thing:

    ctrl-alt-r -- record mode
    ctrl-c -- copy a line
    up arrow -- go up a line
    home -- beginning of line (maybe there is a way to paste before the current line without this)
    ctrl-v -- paste
    ctrl-alt-r -- end record mode
    

    Now you can map this macro to any set of keystrokes you like using the macros ide and the keyboard preferences.

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