简体   繁体   中英

Sublime 3 - Difference Between File -> Open Folder and Project -> Open Project

I have been using Sublime 3 almost 2 years. When I want to work with what I did was File -> Open Folder .

But there is a option for Project -> Open Project .

So what is the difference between both of them? What are the advantages and disadvantages of both methods.

TL;DR: The main difference is persistence of your working environment, if that matters to you.

When you select File > Open Folder and pick a folder, that folder and it's contents are added to the side bar as open folders in the current window, subject to various settings that tell Sublime what files to ignore or exclude. Various functionality in Sublime Text is based on the files available in open folders.

Examples include Go To Anything allowing you to select from a list of all files found or the symbols from all of the found files being put into the global symbol list, which powers Goto Symbol and Goto Definition .

Sublime contains a setting named hot_exit , which is turned on by default. When this setting is turned on, the state of Sublime at the time you quit it is stored in a session file and then restored the next time you start Sublime.

The session stores things like the layout of the window or windows that were open when Sublime was terminated, the list of files that were open, their position, the cursor locations, selected text and unsaved changes along with a lot of other bits and pieces.

So, if you're using File > Open Folder and you work for a while, then you quit Sublime and come back later, everything is restored exactly as it was when you quit, and you can continue working.

The session information that's stored for files that you open this way is transient; it's only persisted while the window is open. If you close that window while Sublime is running, the next time you select File > Open Folder again, you can see the file structure in the side bar (if visible), but the list of files that you had open and all of that other information I mentioned above is reset, so it's like starting over.

If instead after opening folders you select Project > Save Project As... , you're creating a sublime-project file which directly contains the list of folders that you opened, and that file is persisted to disk somewhere in a file of your choosing. This can be inside of one of the folders you opened or some other location.

In the project file (use Project > Edit Project to open it) you can specify settings that apply only to files opened in the window where the file is open; for example you could change the tab_size to something different than what you normally use just for files in that project. The Project file can also contain build systems that apply only to that project.

When you save a project you're also saving a sublime-workspace file (and you can have several sublime-workspace files for a project if you want to, see Project > Save Workspace as... ). The work space file is basically a mini session file that applies to that project.

When you close a window that has a project loaded in it, the state of everything is persisted into the workspace file and restored the next time you use that project. This means that when you open a project, the window you see is the same window that you had the last time you used the project; the files you had open are still open, the cursor locations are saved, and so on.

Where this really shines is in combination with the Project > Quick Switch Project menu entry or it's associated key binding (note: there is no default key binding for this on Windows, requiring you to make your own).

This command opens a panel with all projects and work spaces that you've created so that you can quickly filter down and select a project that you've used before. The result is an immediate swap of content of the current window to the item selected.

This level of persistence is a time saver and productivity booster if you happen to be often working with the same sets of files in the same way.

When you open a Project, that project is added to the root folder of the Sublime 3. Which means you have a current root project Running and you add another project to that. When you open a file, you open a new file folder which is not added to the Current Root project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM