SublimeText3 setting (configuration) manner - sublimetext3

I am new to SublimeText, use SublimeText3.
Along with the daily usage, I'm developing some plug-in, so I'd like to understand the manner deeply.
What I found strange is opening Preferences > Settings - Default,
a file Preferences.sublime-settings located at Library/Application Support/Sublime Text 3/Packages/Default.
However, there is actually no such a directory, so I assume this is a binary hardcoded Virtual directory/File.
Also, I noticed, there is a (non virtual) User directory and Preferences.sublime-settings where we can edit.
I think this is a very smart method to let the user preserve the default setting and override the configuration.
So far I just guessed like this, and I'd like to confirm my understandings here.
When a plugin is developed, the default setting is placed in the plugin folder, and a user-setting file is automatically created in the User folder. Am I correct?

Packages are run directly from the *.sublime-package files, located in the executable path I believe. These are simply renamed zips. You can override files by creating the proper folder and file name in the packages folder. Settings are loaded in the following order. First the Default package, then any plugins installed (in alphabetical order), finally the User directory. So anything specified in the Userdirectory will override/merge with anything preceding it.
With that out of the way, yes you should map the default settings to your plugins directory and the user ones to the user directory. The user setting file is not automatically created. For example, the following is an entry from Main.sublime-menu
{
"command": "open_file", "args":
{
"file": "${packages}/User/Preferences.sublime-settings",
"contents": "// Settings in here override those in \"Default/Preferences.sublime-settings\",\n// and are overridden in turn by file type specific settings.\n{\n\t$0\n}\n"
},
"caption": "Settings – User"
}
So when you first select the menu, it will try to create the file. If it doesn't exist, it should fill it with specified content.

Related

index.sublime-project and index.sublime-workspace files

I have a directory named project, and I navigated to Project > Add Folder to Project... in order to see the directory tree in my left sidebar. I noticed that doing this creates a file called index.sublime-project with the following content:
{
"folders":
[
{
"path": "."
}
]
}
I also noticed that there is another file in my directory called index.sublime-workspace, although this one does not appear in the tree view on the left sidebar of Sublime. It is only visible through windows explorer when I navigated to the Project directory.
What is the purpose of these files? Can I prevent them from being created every time I add folder to project?
Adding directories to the window using Project > Add Folder to Project is indeed one of the ways to open a folder (the others being to drag and drop a folder onto the window and File > Open Folder).
However, doing so do not create those files. To create them, you would need to use the Project > Save Project menu item. So you may have accidentally done that without realizing it. In theory a plugin could also create those files for you, though that seems unlikely (anything is possible though).
In any case, assuming you don't want them it's entirely safe to remove them.
A sublime-project file is a file that allows you to open folders in the side bar and then do things like apply settings that apply only to files in that window, alter what files and folders appear, and so on.
A sublime-workspace file is a localized session information for a particular window. Usually, they associated with a sublime-project file but they don't have to be. They store the state of the window, open files, etc so that you can close a window and then recall it later with the same state.

How to set default file extension of saving file for specific syntax in Sublime Text 3

The C++ standard doesn't rule the file extension, so the most of people use .cpp, but I prefer using .cc, how to tell Sublime Text save to .cc when using C++ syntax as default?
The way to change the default file extension shown by the save-as dialog when saving a file set to a specific syntax is to override that syntax's default .sublime-syntax file. In your case that would be the C++.sublime-syntax file.
Of course, as MattDMo points out, the easiest thing to do is to manually type the preferred file extension whenever you save a file. But for those that want to make the change, here's how to do it.
Open the Command Palette and select View Package File.
Type C++ and then select C++/C++.sublime-syntax. ST will open the file.
Near the top you should see file_extensions: and a list like this:
file_extensions:
- cpp
- cc
- cp
- cxx
- c++
...snip...
ST uses the 1st item in the file_extensions list as the default file extension for the save-as dialog.
To make .cc the default extension instead of .cpp, edit the list order so that - cc is the 1st item and - cpp is 2nd, i.e. swap the top 2 lines around.
Now save the file in your ST config Packages directory with this path: ../Packages/C++/C++.sublime-syntax. If you like you can create a C++ directory in Packages and then just use Ctrl+S to save because the path will have been automatically set by ST but the file won't save unless the ../Packages/C++/ directory already exists.
Note: The full path on a Linux machine would be like this: /home/user/.config/sublime-text-3/Packages/C++/C++.sublime-syntax
The Package Resource Viewer plugin's Open Resource Command Palette command could be used to extract .sublime-syntax files instead of ST's native View Package File command. That plugin will automatically create the appropriate Packages directory when necessary.
Your altered Packages/C++/C++.sublime-syntax file will now override the default version that is shipped with ST. You can reverse this easily simply by deleting the file. It is safe to delete the directory as well if you are not overriding any other files in the same directory.
The only problem with this is when you install a new version of ST. If the newly installed version has an updated C++.sublime-syntax file, the local one you've created will continue to override the new one. To get around this delete your altered Packages/C++/C++.sublime-syntax file when you install a new version of ST and repeat the steps above to restore your preferred default file extension once the installation has been done.
Unfortunately there is no way around this, you can not partially override the C++.sublime-syntax file with just the file_extensions: section. Of course new versions of ST don't come along very frequently and the C++.sublime-syntax file gets updated even less often. So this is not a major issue.

Sublime Text 3: import projects list from folder/files to OpenRecent list

I save several projects in a same folder by manual click Project -> Save Project As...
and I used to use cmd + ctrl + p to open Switch Projectlist to switch between projects
and everything's works fine.
but today, I accidentally remove my Switch Project list in by click Project -> Open Recent -> Clear Items, so my Switch Project list is empty now...
I know I could add them back through reopen ALL my projects. due to the number of projects is pretty a lot, that will be kind of annoying to add them back one by one.
I wanna know if there's a smarter way to do that for me.
maybe import all my *.sublime-project files from folder or something.
thanks
Short of manually opening every project, I don't think there is any way to do something like this directly. There isn't a command or plugin endpoint that I'm aware of that lets you open a project by name or filename, so it's not possible to create a plugin to do the work, and Sublime doesn't have the ability to pre-load the list of packages directly either.
That said, it is possible to manually update the list of recent projects, but whether or not that is more or less work than opening all of the projects is something to consider.
If you use Preferences > Browse Packages from the menu or the command palette, a file browser will open on your Packages folder. From there go up one directory level and go inside of the Local folder, where you will find a Session.sublime_session file.
Sublime saves it's state into this file when you quit it, and uses it to restore state when you start it again. Here you will find all of the saved information, such as the windows and files that were open and so on.
Changing this file will change the data that Sublime loads, so you can modify the session file to set up the data that you want. You need to make sure that you modify the file while Sublime is not running or your changes will be ignored and clobbered away. Also it's a good idea to make a backup of the file before you start in case things go pear shaped.
Down near the bottom of the file you will find a top level key named workspaces, and inside of it a recent_workspaces key:
"workspaces":
{
"recent_workspaces":
[
"/home/tmartin/local/src/OverrideAudit/OverrideAudit.sublime-workspace",
]
}
This is where the list of recent projects is stored for use in the menu and the quick switch project command. Particular things to notice are that the entries are naming sublime-workspace files, and that the paths are absolute.
NOTE: On windows, the filenames stored in the session file are in a format like /C/Users/tmartin and not c:\users\tmartin; on that platform you need to make sure that you adjust the paths accordingly. As long as there is already at least one entry in the list when you look at the session file, you can easily see how to construct the paths that you need.
Despite the name of the commands and menu items, what you're actually switching between is different workspaces. Every sublime-project is associated with a sublime-workspace file, which acts as a dedicated sublime_session file for that particular project. This mapping is one-to-many in that you can have multiple workspaces for the same project file, allowing you to reference the same paths in multiple windows but have different window layouts.
While Sublime is not running you can edit this file to add in the full paths to all of your workspace files; when you start Sublime up the list will be populated (every sublime-workspace file knows what sublime-project it is associated with).
What remains is whether or not it's quick to come up with the list of files in a way that you can easily paste them into the session file.

Sublime GDB for Sublime 3 doesn't work: You have not configured the plugin correctly

I've googled this issue and haven't seen any useful advice. My understanding is that the default settings should work; I can't see any information about mandatory modifications to the default settings.
You have not configured the plugin correctly, the default configuration file and your user configuration file will open in a new window
when I try to open the debugger, then it opens the user settings (an empty file) and the sublimeGDB settings file, which seems like it's the default. The setup tutorial on https://github.com/quarnster/SublimeGDB doesn't mention needing to modify any files, only that doing so is possible if you want to change your preferences.
Also, I do not understand the following instruction:
Open up the default settings via the command palette and begin typing GDB and select the default.
When I open the command palette, there is no "default" option when I type in GDB, only a list of SublimeGDB features (all of which lead to the titular error)
I installed SublimeGDB with package control.
If you look at your SublimeGDB.sublime-settings and you read some properties you can see that their values are set to "notset"
As the very minimum you have to set those:
"workingdir": "${folder:${file}}",
"commandline": "gdb --interpreter=mi --args ./${file_base_name}",
"env": {"DISPLAY": ":100"},
The working dir is the directory of the current open file.
This will launch the executable file that is named like the file you have currently open (without extension)
There are many others settings and options.
You need to read and learn how to configure them in order that they fit your needs.

Where are the default packages in Sublime Text 3 on Ubuntu?

I'm migrating from Sublime Text 2 to 3. In Sublime Text 2, I changed a lot of the default settings of the editor -- such as the tab bar height, sidebar color, etc. -- by modifying the Default.sublime-theme file in sublime-text-2/Packages/Theme - Default. I was also able to modify the colors of the default color schemes in a similar fashion. I've been trying to figure out how to do this for Sublime Text 3, but can't seem to find these files. ~/.config/sublime-text-3 only seems to contain overrides for user settings, not the default settings.
This link on the Sublime Text forums seems to give the location for Windows and Mac, but not for Ubuntu. I've searched a bit to no avail. Does anyone have suggestions?
Thank you!
To amplify on #skuroda's answer - ST3 contains all of its data that, in ST2, was stored in Packages/PackageName, in PackageName.sublime-package files that are basically just zip files, or "Resources" as they're now known. Using PackageResourceViewer, you can easily edit the individual files contained within the resource, then save it back again. When saved, the proper directory structure under Packages/PackageName will be created, allowing you to edit the file directly next time. The way file precedence works in Sublime, any file that exists in ~/.config/sublime-text-3/Packages/PackageName/ will override any file of the same name stored in PackageName.sublime-package.
However, since you don't want these files to be accidentally overwritten, I would suggest creating ~/config/sublime-text-3/Packages/User/Themes/ and User/Color Schemes directories and storing your customized files there instead. The User/ directory is protected from overwrites during upgrades, etc., and unless you're planning on creating a customized theme or color scheme for redistribution through Package Control, it's best practice to keep your files in there.
EDIT
I just realized you hadn't gotten an answer to your original question - where are the files stored? If you installed the .deb file from sublimetext.com, all the .sublime-package files are in /opt/sublime_text/Packages.
If you want the easiest way to save your customized settings first copy all the default settings and paste into a new file named Preferences.sublime-settings.
Then make your changes and save the file to:
/home/**username**/.config/sublime-text-3/Packages/User
In order to see the .config folder you will have to enable show hidden files.
The instructions are written at the top of the default settings list in case you are wondering where got this from.
In the ST console, try entering sublime.executable_path(). This should get you close to where you need to be. Also, you should copy the content of the file out and move them (under a new name to the packages folder). You probably don't want your modifications to be reverted on subsequent update. An alternative method is to try overriding the files you need to. I haven't done that for theme files, so I'm unsure if everything will work as it should. If you take the override route, I'd recommend using PackageResourceViewer. I wrote it to help with browsing/overriding package files in ST3.
You can use
dpkg -L <package name>
For example
dpkg -L subli<tab>
Just open up sublime text, hit ctrl+` to open sublime text console, then run these command accordingly
sublime.packages_path() to see user installed packages directory
sublime.installed_packages_path() to see zipped packages (with .sublime-package file type) directory
Mostly likely, you'll find the Default package inside zipped packages directory.
You can use PackageResourceViewer to see zipped packages's contents as #MattDMo suggested, but more over, you can actually extract zipped packages into user installed package directory directly using PackageResourceViewer's extract command.

Resources