Changing Ctrl + Tab behavior for moving between documents in Visual Studio

前端 未结 13 505
半阙折子戏
半阙折子戏 2020-11-28 17:39

Is it possible to change how Ctrl + Tab and Shift + Ctrl + Tab work in Visual Studio? I have disabled the popup naviga

相关标签:
13条回答
  • 2020-11-28 18:10

    After a couple of hours of searching I found a solution how to switch between open documents using CTRL+TAB which move from left to right and SHIFT+ CTRL+ TAB to go right to left.

    In short you need to copy and paste this macro:

    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    Imports EnvDTE90
    Imports System.Diagnostics
    
    Public Module TabCtrl
    
    Public Sub TabForward()
        Dim i As Integer
        Dim activateNext As Boolean = False
    
        For i = 1 To DTE.Windows.Count
            If DTE.Windows().Item(i).Kind = "Document" Then
    
                If activateNext Then
                    DTE.Windows().Item(i).Activate()
                    GoTo done
                End If
    
                If DTE.Windows().Item(i) Is DTE.ActiveWindow Then
                    activateNext = True
                End If
            End If
        Next
    
        ' Was the last window... go back to the first
        If activateNext Then
            For i = 1 To DTE.Windows.Count
                If DTE.Windows().Item(i).Kind = "Document" Then
                    DTE.Windows().Item(i).Activate()
                    GoTo done
                End If
            Next
        End If
    done:
    
    End Sub
    
    Public Sub TabBackward()
        Dim i As Integer
        Dim activateNext As Boolean = False
    
        For i = DTE.Windows.Count To 1 Step -1
            If DTE.Windows().Item(i).Kind = "Document" Then
    
                If activateNext Then
                    DTE.Windows().Item(i).Activate()
                    GoTo done
                End If
    
                If DTE.Windows().Item(i) Is DTE.ActiveWindow Then
                    activateNext = True
                End If
            End If
        Next
    
        ' Was the first window... go back to the last
        If activateNext Then
            For i = DTE.Windows.Count To 1 Step -1
                If DTE.Windows().Item(i).Kind = "Document" Then
                    DTE.Windows().Item(i).Activate()
                    GoTo done
                End If
            Next
        End If
    done:
    
    End Sub
    
    End Module
    

    The macro comes from: www.mrspeaker.net/2006/10/12/tab-un-stupidifier/

    If you never add a macro to Visual Studio there is a very useful link how to do it.

    0 讨论(0)
  • 2020-11-28 18:11

    Visual Studio 2010 has, built in, a way to solve this.

    By default, Ctrl+Tab and Ctrl+Shift+Tab are assigned to Window.[Previous/Next]..Document, but you can, through

    Tools -> Options -> Environment -> Keyboard,
    

    remove those key assignments and reassign them to Window.[Next/Previous]Tab to add the desired behavior.

    0 讨论(0)
  • 2020-11-28 18:13

    I'm 100% in agreement with Jeff.

    I had worked on Borland C++ Builder for several years and one of the features I miss most is the 'correct' document tabbing order with Ctrl-Tab. As Jeff said, "The current tab behavior keeps pulling me out of the task and makes me have to pay attention to the tool " is exactly how I feels about this, and I'm very much surprised by the fact that there aren't many people complaining about this.

    I think Ctrl-F6 - NextDocumentWindowNav - navigates documents based on the document's last-activated time. This behavior is a lot like how MDI applications used to behave in old days.

    With this taken this into account, I usually use Ctrl+F6 to switch between 2 documents (which is pretty handy in switching between .cpp and .h files when working on c++ project) even when there are more than 2 currently opened documents. For example, if you have 10 documents open (Tab1, Tab2, Tab3, ...., Tab10), I click on Tab1 and then Tab2. When I do Ctrl+F6 and release keys, I'll jump to Tab1. Pressing Ctrl+F6 again will take me back to Tab2.

    0 讨论(0)
  • 2020-11-28 18:17

    I guess you want what VSS calls Next(Previous)DocumentWindow. By default, it's on Ctrl(-Shift)-F6 on my VSS 8. On Ctrl(-Shift)-Tab they have Next(Previous)DocumentWindowNav. You can change key assignments via Tools/Options/Keyboard.

    0 讨论(0)
  • 2020-11-28 18:20

    Navigate to the blog post Visual Studio Tab Un-stupidifier Macro and make use of the macro. After you apply the macro to your installation of Visual Studio you can bind your favorite keyboard shortcuts to them. Also notice the registry fix in the comments for not displaying the macro balloon since they might get annoying after a while.

    0 讨论(0)
  • 2020-11-28 18:24

    In Visual Studio 2015 (as well as previous versions of VS, but you must install Productivity Power Tools if you're using VS2013 or below), there are two new commands in Visual Studio:

    Window.NextTab and Window.PreviousTab

    Just go remap them from Ctrl+Alt+PageUp/Ctrl+Alt+PageDown to Ctrl+Tab/Ctrl+Shift+Tab in:

    Menu Tools -> Options -> Environment -> Keyboard

    Note: In earlier versions such as Visual Studio 2010, Window.NextTab and Window.PreviousTab were named Window.NextDocumentWellTab and Window.PreviousDocumentWellTab.

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