Where does Sublime Text 2 store editing information? - sublimetext2

When I perform these steps:
Open an existing file in Sublime Text 2.
Type in arbitrary text at an arbitrary place in the file.
Close Sublime Text 2.
Note, I have not saved the changes.
Open Sublime Text 2.
Open the file from step 1.
I see changes in the file. But if I view the file in, let's say, Notepad, I see no changes.
Where does Sublime Text 2 keep the changes made to files?

As far as I'm concerned the question isn't answered completely...
As nnnn explained, the unsaved changes of a project are saved in its sublime-workspace file.
But if you haven't created a project and you are just working on some files, sublime also does remember the unsaved changes. These were saved in 'Session.sublime_session'.
Where the session can be found, depends on your operating system:
OS X: ~/Library/Application Support/Sublime Text 2/Settings/
Windows: %APPDATA%\Sublime Text 2\Settings\
Linux: ~/.config/sublime-text-2/Settings/
(I just found this info some kind of accidentally in the official sublime forum)

If you have made a project, the magical file-restore fairy will be in the folder where you told Sublime to store your project, in a file called [yourprojectname].sublime-workspace.
If you delete that workspace file before opening, Sublime will nuke your changes and complain about opening any previously open files. This move will probably cause you some grief, so don't try it unless you've already saved all necessary changes.
The workspace saves, among other things, your window layout, all the contents of any files that are open, and your last find/replace/autocomplete entries. (That is why your autocomplete gets "smarter" over time).
Note the little symbol where there is normally an x to close the tab. If it is a dot instead of an x, the file is considered unsaved and will be brought back also unsaved when you re-open Sublime.

I have the issue after updating Sublime Text 2 (old version) to Sublime Text (new version) on macOS. I don't know why the old version has the suffix "2".
Anyway, a solution to restore the whole my previous session is to copy a file Session.sublime_session, before the manipulation close the Sublime Text app, then execute a command:
cp ~/Library/Application\ Support/Sublime\ Text\ 2/Settings/Session.sublime_session ~/Library/Application\ Support/Sublime\ Text/Local/Session.sublime_session
And finally, start the Sublime Text app.

Related

How to recover a sublime 3 session?

Well, I'm using sublime text 3 and i did something really stupid. I just rewrote a file in which I've recently made some changes and lost it all. I did that pasting an older version, saving it and closing the file.
I need to know if there's any way to recover that old file. In my ~/Library/Application Support/Sublime Text 3/Local/ I can see two sublime_session files:
'Session.sublime_session' from yesterday and
'Auto Save Session.sublime_session' saved today
I have opened them with sublime, but how could I restore a file? Is it possible?
You can't recover changes in file closed with Sublime Text 3. When you close file, your undo buffer is lost forever.
Sublime Text 4 behave same way.

How to make a buffer have a read-only in Sublime Text 2

This is not about those files that have their read-only flag set at the OS level, but about every file that users don't intend to modify.
I want Sublime Text to ignore any changes and prevent saving anything to such files. One example for this scenario is when the user is reading source code that shouldn't be altered in anyway.
"Just be really careful, and don't press any buttons" is undoubtedly a good advice, but if I were to "accidentally" delete that octothorpe in front of a comment, or add new lines to a file that is sensitive to such things (some config files in Linux) and then accidently hit save....
I found "toggle-readonly" at GitHub, but it is actually toggling the file permissions ("Read Only", "Write"), which is not quite what I wanted.
Yes, this is possible, but you'll have to write a plugin (which actually isn't that hard, especially if you know Python). The API call is view.set_read_only(flag) in the sublime module, where Flag is a boolean. Here's a quick example which checks if a newly-opened file has a certain suffix, and if so sets it to read-only.
import sublime
import sublime_plugin
class MakeViewReadOnlyCommand(sublime_plugin.TextCommand):
def run(self, edit):
if self.view.file_name().endswith(".cfg"):
self.view.set_read_only(True)
class ConfigFileListener(sublime_plugin.EventListener):
def on_load(self, view):
view.run_command("make_view_read_only")
Open a new file with Python syntax, copy the code into it, alter it as needed, then save it in your Packages/User directory as make_view_read_only.py. Restart Sublime to load it, and you should be all set. To test if a certain view is read-only, open the console and enter
view.is_read_only()
The plugin "Toggle the View Read-Only" will do it. It basically does what MattDMo said: when you set the view as read-only, the file can still be changed by another program (or another user), and Sublime Text will pick up those changes. It also has the context menu item you asked for. I like the "Readonly" indicator in status bar.
I didn't test it on Sublime Text 2, but in Sublime Text 3 it works great, and it claims to work on Sublime Text 2 as well.

How to edit Sublime Text 3 Soda Theme

I installed the Soda Theme on Sublime Text 3 on OSX and I was wondering where are the actual files and folder to the theme that way I could look at the theme file and make my own edits to it, along with I would like to adjust a few of the images used in the theme.
On the Git documents it says if you are to manually install Soda on Sublime you place the soda folder in the package directory, although when I install Soda via Control Package I don't see the Soda theme in package directory.
Unless explicitly designated to not use it, most packages for Sublime Text 3 use the .sublime-package format (essentially a zip file). These packages are stored one directory up from the Packages folder, in Installed Packages. If you want to work with them, I highly recommend getting the PackageResourceViewer plugin by #skuroda. Install it via Package Control.
Once installed, open the command palette with ⌘⇧P and type prv to get the PackageResourceViewer options. Choose Extract Package, navigate down to Theme - Soda, hit Enter, and you're all set - the directory Packages/Theme - Soda should now exist with all the files from the Github repo in it. The .sublime-theme files will probably be the ones you're most interested in for now.
Have fun!
This answer is similar to the accepted solution, but with little more steps if it is not working out of the box. This might help someone if they are stuck with an issue which I have described in one of the below steps.
install PackageResourceViewer using Package Control
Go to Preferences->Package Settings->PackageResourceViewer->Setting-User. copy paste the following 3 lines,save and close it.
{
"single_command": false
}
press Ctrl+shift+p to open Package Control and select PackageResourceViewer: Edit Package Resource from the list. Find the package you want to edit and click on it. In my case, I want to edit a theme which is installed via ColorSublime Package, So I selected that theme.
Now you will see that the selected package file opened in the sublime editor itself. Edit it as you want and save it and close it. The changes should reflect in sublime editor. In my case, since I changed the theme I need reload it. So I continued with the following steps too.
go to view menu select 'Show Console' and run following command to reset the theme.
view.settings().erase("color_scheme")
open Preferences->Settings and delete the "color_scheme" attribute and its value from the settings file and close it. Again select the color theme from Preferences->Color scheme. Now you should able to see the changes reflected which you made in the theme package.
Hope this helps!
You can do it as follows.
Extract Soda theme from the Sublime Text 2 ~/Library/Application Support/Sublime Text 2/Packages/Color Scheme - Default folder
In Sublime Text 3, Select Sublime Text / Preferences / Browse Packages ...
Create a folder adjacent to the Users folder called THEMES.
Drop all themes you want from Sublime Text 2 (including Soda theme or any other themes) from the folder ~/Library/Application Support/Sublime Text 2/Packages/Color Scheme - Default into your ~/Library/Application Support/Sublime Text 3/Packages/THEMES folder from Sublime Text 3.
Edit the XML in the theme you want to use.
Back in Sublime Text 3, select Sublime Text / Color Schemes / THEMES / YourTheme.tmTheme to use it.

How do I edit HTML.tmLanguage in sublime on mac osx

I'm to change it to support non-quote id, as in:
<div id=someId></div>
I found this
http://www.sublimetext.com/forum/viewtopic.php?f=3&t=8129
But am having issues finding where to edit the tmLanguage file
Don't listen to Jamie's answer. You should never be editing the Pristine packages. Instead, you can find all of Sublime Text's packages and grammar files in ~/Library/Application Support/Sublime Text/Packages or, from within Sublime Text, go to Sublime Text > Preferences > Browse Packages. However, if you edit HTML.tmLanguage from within the HTML folder, your changes will be overridden when Sublime Text is updated. To prevent this, duplicate the HTML folder and renaming it to Better HTML. Then in your User Settings (Preferences > Settings - User) add the following:
"ignored_packages":
[
"HTML",
"Vintage"
],
By ignoring the default HTML package, Sublime Text will be forced to use your version of the HTML.tmLanguage file and your changes will be preserved.
You can find the HTML.tmLanguage file by going to /Applications and then control/right click on Sublime Text 2.app and select 'Show Package Contents'. Then navigate to /Contents/Mac OS/Pristine Packages/.
Inside that folder, you should see a collection of sublime-package files. Find HTML.sublime-package and rename it to HTML.zip. You should then be able to extract the archive, just like any other zip folder, and inside you should find all assests related to Sublime's HTML package - including the HTML.tmlanguage.
Make sure to recompress and then rename the folder back to .sublime-package after making your edits!
EDIT: I have since recognised that this is incorrect, the Pristine Packages should never be edited. Follow BoundinCode's answer instead!

How to prevent Sublime Text 2 from opening that last open file / project when starting up

I am on Lion - and in the command line, when I open up my project using "subl ." in my project folder - it opens up the last project I had open before I quit Sublime.
I have the Max Preference "Restore windows when quitting" unchecked.
How to I prevent this behaviour? Is there a preference setting for this?
I think the behavior you want can be enabled by changing the hot_exit and remember_open_files settings. If you check out the "Global Settings - Default" preferences, there are some comments there describing these settings.
If you want to change them, you should override them in the "Global Settings - User" file to preserve your changes across updates.
If anyone is wondering how to do this in sublime text 3, copy and paste the following into settings - user:
"hot_exit": false,
"remember_open_files": false,
I could only get it to work by also setting "hot_exit": false in my preferences.
On Linux, I had an issue where I couldn't even start Sublime Text 3 because there were too many files open and it would hang before I got a chance to change the settings.
I did what Mike Wizowski suggested and edited my $HOME/.config/sublime-text-3/Packages/User/Preferences.sublime-settings to include those settings.
However, restarting Sublime Text after this did not seem to fix my problem because Sublime still opened all the files and folders.
I found that deleting the 2 ".sublime_session" files in $HOME/.config/sublime-text-3/Local/ made Sublime Text forget what the recently opened files/folders were, thus fixing my hanging text editor.