ChatGPT解决这个技术问题 Extra ChatGPT

Auto select file in Solution Explorer from its open tab

Normally, many files in Visual Studio 2010 are opened in many tabs, while massively working on a project. Many times, I find myself right-clicking on a tab title and searching for Show/Select/Scroll-to this file in Solution Explorer, and I can't find it.

Is there a way to automatically select an opened file in Solution Explorer?

Yeah, I keep almost turning back on the "Track Active Item in Solution Explorer", then I remember how much I disliked that, because I'd lose track of the section of the project I was working on. However, I also often want to on-demand "focus-to" the document I'm editing, to see all the items in nearby namespaces. For example, maybe I've just gone 5 references deep in a project I don't know well, using F12 (Go to definition). I don't want 5 trees open so I can't get back to my focal project, but I now want to inspect the third-party library for a moment.

T
Tshilidzi Mudau

Another option is to bind 'View.TrackActivityInSolutionExplorer' to a keyboard short-cut, which is the same as 'Tools-->Options-->Projects and Solutions-->Track Active Item in Solution Explorer'

If you activate the short-cut twice the file is selected in the solution explorer, and the tracking is disabled again.

Visual Studio 2013+

There is now a feature built in to the VS2013 solution explorer called Sync with Active Document. The icon is two arrows in the solution explorer, and has the hotkey Ctrl + [, S to show the current document in the solution explorer. Does not enable the automatic setting mentioned above, and only happens once.


Keyboard binding is done in Tools/Options.../Environment/Keyboard -- I went with binding Ctrl+Alt+] (close square bracket).
'Tools-->Options-->Projects and Solutions-->Track Active Item in Solution Explorer' still works in Visual Studio 2017 Community Edition.
'Tools-->Options-->Projects and Solutions-->Track Active Item in Solution Explorer' still works in Visual Studio 2019
Why is this not enabled by default?
J
Jonathan Mee

I don't know if you can do it on-demand, but you can enable the option "Track Active Item in Solution Explorer" (Tools->Options->Projects and Solutions->General) which will always select the active tab item in the solution explorer.


More precisely: Tools -> Options -> Projects and Solutions -> General ->
P
Peter Mortensen

If you're using the ReSharper plugin, you can do that using the Shift + Alt + L shortcut or navigate via menu as shown.

https://i.stack.imgur.com/68LTL.png


A
AJ.

This isn't exactly what you're looking for, but it would automatically select the "active" file in the Solution Explorer:

Tools-->Options-->Projects and Solutions-->Track Active Item in Solution Explorer.


P
Peter Mortensen

The best option now is to install the Microsoft Visual Studio add on called Productivity Power Tools.

With this comes "Solution Navigator" (alternative to Solution Explorer, with a lot of benefits) - which then you can use to filter the files to only show "Open". You can even filter files to show "Edited" and "Unsaved".


B
Baraa Deek

simply Tools--> Options--> Projects and Solutions--> Track Active Item in Solution Explorer


hope it help any one need it
B
Basic

It's in VS2012 - Specifically the 2-Arrow icon at the top of the solution explorer (Left/Right arrows, one above the other). This automatically jumps to the current file.

This icon is only visible if you've got Track Active Item in Solution Explorer disabled.


T
Tarun

In Visual Studio 2012, the same can be done using the "Sync With Active Document" option in Solution Explorer


A
Anwar Ul-Haq

https://i.stack.imgur.com/av9LP.png


t
themissinglint

The Tab Studio plugin adds "select in solution explorer" to the right click menu on tabs.


i knew i saw it somewhere... thanks for pointing it out it was in tabstudio (which i had installed)
j
jpierson

I've put in a feature request for this very feature. Although I know this isn't an answer in itself it is a step in the direction of being able to get this feature implemented. Any votes it it may help to get Microsoft's attention.

As far as I'm aware of though there is no way to do this other than possibly writing a macro or creating your own add-in/extension to Visual Studio.


S
Sergey Pashkevich

There's a very nice extension to VS2010, which does exactly this: Solution Explorer Tools.

This extension adds a button which selects the current file in the solution explorer, as well as convenient buttons for collapsing and expanding projects.