views:

1377

answers:

10

Is it possible to change how ctrl+tab and shift+ctrl+tab work in Visual Studio? I have disabled the popup navigator window because I only want to switch between items in the tab control. My problem is the inconsistency of what switching to the next and previous document do.

Every other program that uses a tab control for open document I have seen uses ctrl+tab to move from left to right and shift+ctrl+tab to go right to left. Visual Studio breaks this with it's jump to the last tab selected. You can never know what document you will end up on and it is never the same way twice.

It is very counter intuitive. Is this a subtle way to encourage everyone to only ever have two document open at once?

A: 

Sorry to disagree out of hand, however, I find that the visual studio way of handling tabs very useful! Usually when Im editing multiple files I concentrate on a couple and the tab system allows me to move quickly and easily between all the pages. When it comes to editing different files then Ill just open them up and they'll be the ones being opened by the tab

OK I'll conceeded that it might be different in other versions of VS (I use 2008) to which I cant comment on. The window of open documents that ctrl+tab brigs up is usually more than enough to manage my solution.

TK
+1  A: 

I don't use Visual Studio ( yes, really, I don't use it ), but AutoHotKey can remap any hotkey globally or in a particular application:

#IfWinActive Microsoft Excel (application specific remapping)

; Printing area in Excel (@ Ctrl+Alt+A)
^!a::
Send !ade
return

#IfWinActive


$f4::
; Closes the active window (make double tapping F4 works like ALT+F4)
if f4_cnt > 0 
{
    f4_cnt += 1
    return
}

f4_cnt = 1
SetTimer, f4_Handler, 250
return

f4_Handler:
SetTimer, f4_Handler, off

if (f4_cnt >= 2)  ; Pressed more than two times
{  
 SendInput !{f4}
} else {
 ; Resend f4 to the application
 Send {f4}
}

f4_cnt = 0
return

These are two remappings of my main AutoHotKey script, I think it's an excellent tool for this type of tasks.

PabloG
+3  A: 

Let's say I have a few files open. I am working in one and I need to see what is in the next tab to the right. In every other single application on the face of the Earth (hyperbole), ctrl+tab will get me there. In Visual Studio, I have no idea which of the other tabs it will take me to. If I only ever have two documents open, this works great. As soon as you go to three or more, all bets are off as to what tab Visual Studio has decided to send you to.

The problem with this is that I shouldn't have to think about the tool, it should fade into the background, I should be thinking about the task. The current tab behavior keeps pulling me out of the task and makes me have to pay attention to the tool.

Jeff Cuscutis
+2  A: 

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.

buti-oxa
Ctrl-(Shift-)F6 doesn't get you to the left or right tab. its the same order as Ctrl-Tab but without the annoying window.
shoosh
Correct... Visual Studio 2010 has Window.NextTab and Window.PreviousTab, which does non-MRU based document changing, but it does not work with all document types: http://connect.microsoft.com/VisualStudio/feedback/details/571750/window-nexttab-and-window-previoustab-keybindings-do-not-work-on-form-designer-tabs
Greg Bray
+6  A: 

The Next(Previous)DocumentWindow would be fine if next and previous actually was next and previous. It is actually a next and previous from a list you can't see that changes order without telling you. Using the next and previous functionality changes the order of the list so you can't reproduce the behavior.

It drives me crazy that I can't just look at the tabs and ctrl+tab to that tab.

I seem to be the only person annoyed by this random behavior.

Jeff Cuscutis
This "feature" of Visual Studio drives me insane. I have yet to ever find a proper workaround for this.
Matthew Ruston
the only person, no. I complain every day
thepaulpage
+1  A: 

The philosophy of VS tab order is very counter intuitive since the order of the displayed tabs differs from the tab-switching logic, rendering the ordering of the tabs completely useless

So until a better solution arises, change the window layout (in Environment->General) from tabbed-documents to multiple-documents; it will not change the behaviour but reduces the confusion caused by the tabs.

That way you will also find the DocumentWindowNav more useful!

+1  A: 

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.

Kei
+4  A: 

Hi! This is my first post in Stack Overflow so I'm hoping at least somebody finds it useful. I also got fed up with the most recently used ordering of tabs found in Visual Studio ever since version 2005. There is a way around this and this blogger going by the name of Mr Speaker has the necessary macro code. Navigate to his blog post and make use of his macro. After you apply his macro to your VS 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. Have fun!

It apparently still breaks under some conditions, but this is the clostest one to actually working as desired.
Jeff Cuscutis
In VS 2010 you can configure Ctrl+Tab and Ctrl+Shift+Tab to change between text documents, but it does not work with designer tabs or the BinaryEditor. The macro from the above blog post is the only method that works with the majority of document window types. I also filed a bug with Microsoft that has more details ( http://goo.gl/K9rz ), and they said that they will change `Window.NextTab` and `Window.PreviousTab` to provide non-MRU switching for documents in the "next Visual Studio version".
Greg Bray
+3  A: 

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.

Does it still take 10 seconds to do this the first time, and flash a system tray icon every subsequent time you use it? That's what VS2005 did, and I couldn't take it...
romkyns
Romkyns: Yes, I'm afraid. Still not a viable solution.
David Foster
Romkyns: yes it's true, every time I execute the macro, a balloon pops up in the system tray to indicate the macro is running. to get rid of that ballon you may edit the Windows Registry and add the following DWORD value: "DontShowMacrosBalloon" = 1, in that key: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0(use 9.0 for Visual Studio 2008; 8.0 for 2005). The balloon disappears but system tray icon still will be appear. For me this solution is good enough I have not found a better and I hate orginalne ctrl+tab behavior.