I know the "File > Open folder..." dialog box in Sublime.
The problem is that:
- it first opens a "file picker" dialog box
- after choosing the right folder, it opens the folder in a new Sublime Text window, instead of the current window
How to open the current file's folder in the left "Folder view" of the current Sublime window, without any popup? (I would like to bind a keyboard shortcut for this). Note: I still use Sublime 2.
The menu item
Project > Add Folder to project...will prompt you for the name of a folder and then add it to the current window rather than create a new one. Contrary to the name, this will always work even if you're not explicitly usingsublime-projectfiles directly.For doing this without any sort of prompt, a plugin would be needed to adjust the list of folders that are open in the window currently.
In Sublime Text 3 and above, there is API support for directly modifying the list of folders that are open in the window, while Sublime Text 2 only has an API for querying the list of folders.
All versions of Sublime have a command line helper that can be used to interact with the running copy of Sublime (generally referred to as
subl), and one of the things it can do is augment the list of folders in the window by adding an additional one. In Sublime Text 2, thesublhelper is just the main Sublime Text executable itself.The following is a plugin that can be used in Sublime Text 2 and above that will perform the appropriate action to get the path of the current file to open in the side bar. If you're unsure of how to use plugins, see this video on how to install them.
This will define a command named
add_file_folder_to_side_barwhich will add the path of the current file to the side bar; the command disables itself if the current file doesn't have a name on disk, or if that path is already open in the side bar.If you're using Sublime Text 2, note that you need to adjust the variable at the top to point to where your copy of Sublime is installed (including the name of the program itself, as seen in the example code), since the plugin will need to be able to invoke it to adjust the side bar.
In order to trigger the command, you can use a key binding such as:
You can also create a file named
Context.sublime-menuin yourUserpackage (the same place where you put the plugin) with the following contents to have a context menu item for this as well: