Sublime Forum

Highlight currently open file in the project tree

#1

Hi.
I often work with large projects with many nested folders. I constantly use Goto Anything to open files as opposed to the side bar. I also often need to know where currently open file is located in the project hierarchy, and the only way to do it is by looking at the title bar of the editor, which displays the full path, but it doesn’t guarantee to match the project structure. It would be absolutely great if Sublime Text could sync the project tree in the side bar with the currently active document, in other words expand the necessary folders in the side bar, highlight the currently active file and scroll it into view if necessary, regardless of how the file gets activated, either from Goto Anything, Goto Definition, selecting the tab, etc. Doesn’t matter.
Does anyone else think it would be a nice addition?
Thanks!

0 Likes

#2
  1. If the sidebar is expanded to show the file you’re editing already, Sublime will hilite the file in the tree when you activate the tab.
  2. Better still, if you right-click somewhere in the file content, “Reveal in side bar” will expand the relevant branch and hilite the file.

Think these two have you covered :smile:

0 Likes

#3

[quote=“qgates”]1. If the sidebar is expanded to show the file you’re editing already, Sublime will hilite the file in the tree when you activate the tab.
2. Better still, if you right-click somewhere in the file content, “Reveal in side bar” will expand the relevant branch and hilite the file.

Think these two have you covered :smile:[/quote]

Awesome! I never use right-click menu so I wasn’t aware of this feature. Thanks a lot for pointing it out!

0 Likes

#4

If you want to happen every time, by the way, you could write a plugin that calls reveal_in_side_bar in the on_activated callback.
The problem would then be closing all the old file’s folders when you switched to a new file.

0 Likes

#5

You can map this command to a shortcut, just add an entry to your key bindings:

{ "keys": "ctrl+alt+s"], "command": "reveal_in_side_bar" },
4 Likes

#6

thank you @ms4py! There’s a small typo, the keys need to be bracketed on both sides :smile:

{ "keys": ["ctrl+alt+s"], "command": "reveal_in_side_bar" },
1 Like

#7


Thank you. :slightly_smiling:

0 Likes

#8

I was just interested in doing this automatically when going from file to file.

I managed to do exactly that by creating a simple python script:

import sublime, sublime_plugin

class OnActivatedListener(sublime_plugin.EventListener):
    def on_activated (self, view):

        print ("opened" + view.file_name ())

        view.window ().run_command ("reveal_in_side_bar")
0 Likes