100

I'm not asking for the option to automatically follow the current file in the solution explorer. This has been answered in this question and I have this option turned off because I hate the behavior.

I would like to have a shortcut (or macro, or ....) to jump to the file I'm currently editing in the solution explorer.

Community
  • 1
  • 1
Laoujin
  • 9,962
  • 7
  • 42
  • 69

11 Answers11

119

In VS 2013 there is a built-in keyboard shortcut (CTRL+\, S)

  1. Press CTRL+backslash
  2. Release both keys
  3. Press the S key

Or click the button highlighted in the image bellow.

Sync with active document

One also has the option to customize the keyboard shortcut if you don't like the default combination :)

Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265
moander
  • 2,080
  • 2
  • 19
  • 13
  • 31
    This keyboard shortcut is called `SolutionExplorer.SyncWithActiveDocument` (Tools -> Options -> Environment -> Keyboard) – Laoujin Jan 05 '15 at 11:55
  • 31
    The default shortcut is Ctrl+[,S in my VS. – Roman O Apr 09 '15 at 01:23
  • CTRL+backslash did not work for me actually, see: http://stackoverflow.com/a/37158527/2874896 – Jim Aho May 11 '16 at 09:34
  • 1
    You may want to deactivate the `Track Active Item in Solution Explorer` first, so syncing solution explorer will only happen on pressing this shortcut instead of "jumping" around when switiching code files. – phifi Feb 20 '17 at 08:52
  • Awesome. great help :) – sebastian Jul 23 '18 at 08:44
90

In Visual Studio 2015, 2017, 2019 and 2022 you can press Ctrl + [ and then s.

This will highlight the file currently being edited in Solution Explorer.

This can be configured via the following keyboard command: SolutionExplorer.SyncWithActiveDocument

To reconfigure, navigate to Tools -> Options -> Environment -> Keyboard

Adrian Thompson Phillips
  • 6,893
  • 6
  • 38
  • 69
29

As far as I know there is no such option before VS 2012.

In VS 2012 the "Sync with Active Document" option was introduced. You can find description and screen on this blog (scroll to "Sync with Active Document" in the middle of page).

psur
  • 4,400
  • 26
  • 36
6

To locate the file you're currently editing in Solution Explorer:

Ctrl + W + S

I previously used Shift + Alt + L, but for some reason this is no longer working.

The other suggestions (Ctrl+\,S and Ctrl+[,S and Ctrl + ` + S) do not work for me in VS2015. I don't use resharper and dont like using macros when simple shortcuts are available.

Spyder
  • 3,784
  • 3
  • 26
  • 15
6

In Visual Studio 2015, with ReSharper, I am able to press Shift + Alt + L to highlight the current file being edited in Solution Explorer.

Philip Pittle
  • 11,821
  • 8
  • 59
  • 123
Jeremy Paskali
  • 140
  • 2
  • 8
3

For VS2010 I found this macro and works for me :

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90

Public Module Utilities
    Public Sub TrackProjectItem()
        Dim solution As Solution2 = DTE.Solution
        If Not solution.IsOpen OrElse DTE.ActiveDocument Is Nothing Then Return

        solution.FindProjectItem(DTE.ActiveDocument.FullName).ExpandView()

        Dim FileName As String = DTE.ActiveDocument.FullName

        Dim SolutionExplorerPath As String
        Dim items As EnvDTE.UIHierarchyItems = DTE.ToolWindows.SolutionExplorer.UIHierarchyItems
        Dim item As Object = FindItem(items, FileName, SolutionExplorerPath)

        If item Is Nothing Then
            MsgBox("Couldn't find the item in Solution Explorer.")
            Return
        End If

        DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
        DTE.ActiveWindow.Object.GetItem(SolutionExplorerPath).Select(vsUISelectionType.vsUISelectionTypeSelect)
    End Sub

    Public Function FindItem(ByVal Children As UIHierarchyItems, ByVal FileName As String, ByRef SolutionExplorerPath As String) As Object
        For Each CurrentItem As UIHierarchyItem In Children
            Dim TypeName As String = Microsoft.VisualBasic.Information.TypeName(CurrentItem.Object)
            If TypeName = "ProjectItem" Then
                Dim projectitem As EnvDTE.ProjectItem = CType(CurrentItem.Object, EnvDTE.ProjectItem)
                Dim i As Integer = 1
                While i <= projectitem.FileCount
                    If projectitem.FileNames(i) = FileName Then
                        SolutionExplorerPath = CurrentItem.Name
                        Return CurrentItem
                    End If
                    i = i + 1
                End While
            End If

            Dim ChildItem As UIHierarchyItem = FindItem(CurrentItem.UIHierarchyItems, FileName, SolutionExplorerPath)
            If Not ChildItem Is Nothing Then
                SolutionExplorerPath = CurrentItem.Name + "\" + SolutionExplorerPath
                Return ChildItem
            End If
        Next
    End Function
End Module

Original Source here

Mate
  • 4,976
  • 2
  • 32
  • 38
3

In Visual Studio 2010/2012 you can use this extension (link). It adds option to sync on Solution Explorer toolbar and code context menu.

user503386
  • 1,108
  • 8
  • 5
  • the "link" open this same page XD – Mate Feb 19 '13 at 18:17
  • It shows a new menu item "Find In Solution Explorer" to the context menu when you right click on our document tab. this menu is positioned between the "Copy Full Path" and "Open Containing Folder" menu items. – S.Serpooshan Apr 09 '14 at 05:26
3

For VS 2017 the default configuration is:

CTRL + [,S

And the complete list of shortcuts you can find here:

http://visualstudioshortcuts.com/2017/

cpoDesign
  • 8,953
  • 13
  • 62
  • 106
2

If I got your question right, you can go to Tools -> Options -> Projects and Solutions -> General and check the "Track Active Item in Solution Explorer" option.

amirdaraee
  • 79
  • 1
  • 8
0

On my keyboard I had to press:

Ctrl + ` + S

Do note that the sign in the middle is the key just left of the backspace.

Using Visual Studio 2015.

Jim Aho
  • 9,932
  • 15
  • 56
  • 87
  • 1
    It might help if you said which layout you‘re using. The info where the key is located is helpful though. – bugybunny Oct 23 '18 at 06:56
0

On Visual Studio the Sync With Active Document icon Sync with Active Document icon VS2019 is not displayed when the "Track Active Item in Solution Explorer" option is already ticked under Tools > Options > Projects and Solutions > General.

To display the icon and perform the sync manually untick the "Track Active Item in Solution Explorer" option

Track Active Item in Solution Explorer unticked

or use the keyboard shortcut: "Ctrl" and "[" and "s" together on the active page

In Visual Studio 2013 the icon appears differently. It appears as a right and left pointer icon Sync With Active Document VS2013.

On Visual Studio 2019 the refresh icon with circular double arrows is now the Sync button Sync with Active Document icon VS2019

nimblebit
  • 473
  • 3
  • 11
  • 22