简体   繁体   English

Visual Studio:将解决方案资源管理器滚动到当前文件的快捷方式

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

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.我想要一个快捷方式(或宏,或 ....)来跳转到我当前在解决方案资源管理器中编辑的文件。

In VS 2013 there is a built-in keyboard shortcut ( CTRL + \\ , S )在 VS 2013 中有一个内置的键盘快捷键CTRL + \\S

  1. Press CTRL +backslashCTRL + 反斜杠
  2. Release both keys松开两个键
  3. Press the S keyS

Or click the button highlighted in the image bellow.或单击下图中突出显示的按钮。

与活动文档同步

One also has the option to customize the keyboard shortcut if you don't like the default combination :)如果您不喜欢默认组合,还可以选择自定义键盘快捷键:)

In Visual Studio 2015, 2017 and 2019 you can press Ctrl + [ and then s .在 Visual Studio 2015、2017 和 2019 中,您可以按Ctrl + [然后按s

This will highlight the file currently being edited in Solution Explorer.这将突出显示当前在解决方案资源管理器中编辑的文件。

This can be configured via the following keyboard command: SolutionExplorer.SyncWithActiveDocument这可以通过以下键盘命令进行配置: SolutionExplorer.SyncWithActiveDocument

To reconfigure, navigate to Tools -> Options -> Environment -> Keyboard要重新配置,请导航到工具 -> 选项 -> 环境 -> 键盘

As far as I know there is no such option before VS 2012.据我所知,在 VS 2012 之前没有这样的选择。

In VS 2012 the "Sync with Active Document" option was introduced.在 VS 2012 中引入了“与活动文档同步”选项。 You can find description and screen on this blog (scroll to "Sync with Active Document" in the middle of page).您可以在此博客上找到说明和屏幕(滚动到页面中间的“与活动文档同步”)。

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.我以前使用过Shift + Alt + L ,但由于某种原因,这不再有效。

The other suggestions ( Ctrl+\\,S and Ctrl+[,S and Ctrl + ` + S) do not work for me in VS2015.其他建议( Ctrl+\\,SCtrl+[,S和 Ctrl + ` + S)在 VS2015 中对我不起作用。 I don't use resharper and dont like using macros when simple shortcuts are available.当简单的快捷方式可用时,我不使用 resharper 并且不喜欢使用宏。

在 Visual Studio 2015 中,使用 ReSharper,我可以按Shift + Alt + L突出显示在解决方案资源管理器中正在编辑的当前文件。

For VS2010 I found this macro and works for me :对于 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

Original Source here原始来源在这里

In Visual Studio 2010/2012 you can use this extension ( link ).在 Visual Studio 2010/2012 中,您可以使用此扩展( 链接)。 It adds option to sync on Solution Explorer toolbar and code context menu.它添加了在解决方案资源管理器工具栏和代码上下文菜单上同步的选项。

For VS 2017 the default configuration is:对于 VS 2017,默认配置是:

CTRL + [,S CTRL + [,S

And the complete list of shortcuts you can find here:您可以在此处找到完整的快捷方式列表:

http://visualstudioshortcuts.com/2017/ http://visualstudioshortcuts.com/2017/

如果我的问题是正确的,您可以转到工具 -> 选项 -> 项目和解决方案 -> 常规并选中“在解决方案资源管理器中跟踪活动项目”选项。

On my keyboard I had to press:在我的键盘上,我不得不按:

Ctrl + ` + S Ctrl + ` + S

Do note that the sign in the middle is the key just left of the backspace.请注意,中间的符号是退格键左侧的键。

Using Visual Studio 2015.使用 Visual Studio 2015。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否有用于在解决方案资源管理器中重命名文件的 Visual Studio 键盘快捷键? - Is there a Visual Studio keyboard shortcut to rename a file in Solution Explorer? Visual Studio 中用于在 Windows 文件资源管理器中打开解决方案的快捷方式? - Shortcut in Visual Studio to open solution in Windows file explorer? Visual Studio - 关闭解决方案资源管理器的键盘快捷键 - Visual Studio - Keyboard Shortcut to close Solution Explorer Visual Studio解决方案资源管理器中的快捷方式(.lnk)文件 - Shortcut (.lnk) files in Visual Studio Solution Explorer Visual Studio - 解决方案资源管理器中的当前文件 - 使其更暗? - Visual Studio - Current file in Solution Explorer - Make it darker? 有没有办法设置键盘快捷键以在 Visual Studio 的解决方案资源管理器中打开包含选定文件的文件夹? - Is there a way to set a keyboard shortcut to open containing folder of a selected file in Solution Explorer in Visual Studio? 解决方案资源管理器中的 Visual Studio 2017 锁定文件 - Visual Studio 2017 lock file in solution explorer 配置文件未出现在 Visual Studio 的解决方案资源管理器中 - Config file not appearing in solution explorer in visual studio 删除visual studio中的当前文件的快捷方式 - Shortcut to delete current file in visual studio 当前文件中下一个错误的 Visual Studio 快捷方式? - Visual Studio shortcut to next error in current file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM