簡體   English   中英

Visual Studio:將解決方案資源管理器滾動到當前文件的快捷方式

[英]Visual Studio: Shortcut to scroll solution explorer to current file

不是要求在解決方案資源管理器中自動跟蹤當前文件的選項。 這已經在這個問題中得到了回答,我關閉了這個選項,因為我討厭這種行為。

我想要一個快捷方式(或宏,或 ....)來跳轉到我當前在解決方案資源管理器中編輯的文件。

在 VS 2013 中有一個內置的鍵盤快捷鍵CTRL + \\S

  1. CTRL + 反斜杠
  2. 松開兩個鍵
  3. S

或單擊下圖中突出顯示的按鈕。

與活動文檔同步

如果您不喜歡默認組合,還可以選擇自定義鍵盤快捷鍵:)

在 Visual Studio 2015、2017 和 2019 中,您可以按Ctrl + [然后按s

這將突出顯示當前在解決方案資源管理器中編輯的文件。

這可以通過以下鍵盤命令進行配置: SolutionExplorer.SyncWithActiveDocument

要重新配置,請導航到工具 -> 選項 -> 環境 -> 鍵盤

據我所知,在 VS 2012 之前沒有這樣的選擇。

在 VS 2012 中引入了“與活動文檔同步”選項。 您可以在此博客上找到說明和屏幕(滾動到頁面中間的“與活動文檔同步”)。

要在解決方案資源管理器中找到您當前正在編輯的文件:

Ctrl + W + S

我以前使用過Shift + Alt + L ,但由於某種原因,這不再有效。

其他建議( Ctrl+\\,SCtrl+[,S和 Ctrl + ` + S)在 VS2015 中對我不起作用。 當簡單的快捷方式可用時,我不使用 resharper 並且不喜歡使用宏。

在 Visual Studio 2015 中,使用 ReSharper,我可以按Shift + Alt + L突出顯示在解決方案資源管理器中正在編輯的當前文件。

對於 VS2010,我找到了這個宏並且對我有用:

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

原始來源在這里

在 Visual Studio 2010/2012 中,您可以使用此擴展( 鏈接)。 它添加了在解決方案資源管理器工具欄和代碼上下文菜單上同步的選項。

對於 VS 2017,默認配置是:

CTRL + [,S

您可以在此處找到完整的快捷方式列表:

http://visualstudioshortcuts.com/2017/

如果我的問題是正確的,您可以轉到工具 -> 選項 -> 項目和解決方案 -> 常規並選中“在解決方案資源管理器中跟蹤活動項目”選項。

在我的鍵盤上,我不得不按:

Ctrl + ` + S

請注意,中間的符號是退格鍵左側的鍵。

使用 Visual Studio 2015。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM