How to negate 'remove all folders' mistake in Sublime Text project - sublimetext2

In Sublime Text (2 & 3) I find I accidentally remove all folders from the project when I don't want to (this option is poorly placed in the menu, with no obvious undo or warning and is arguably similar to a 'clear' button on a form).
I often have many folders open in a project each one a leaf in the folder tree structure, which is my workflow, so naturally this is a nasty break in my work if it's accidentally triggered!
I would like to know if I can either disable this option or undo it if I accidentally trigger it?

Aside from a backup, a version control system, or a versioning feature on your file system, there is unfortunately no way of undoing the "Remove all Folders from Project" command, because as soon as the command is fired the folders are removed from the .sublime-project file, and the file is saved. However, there is a way to disable the command. The methods vary between Sublime Text 2 and 3, so I'll go over 2 first.
In Sublime Text 2, click on Preferences -> Browse Packages... to open the Packages folder, whose location varies by operating system. Go into the Default folder, and open Main.sublime-menu in Sublime (it's a JSON file). Search for "close_folder_list" and find the line that looks like this (it's line 737 in version 2.0.2):
{ "command": "close_folder_list", "caption": "Remove all Folders from Project", "mnemonic": "m" },
Now, you can either simply delete the entire line, or comment it out by putting // as the first characters on the line. Save the file, then click on the Project menu to see that the option is gone.
If you're using Sublime Text 3, you'll need a workaround to access the Packages/Default folder and its contents, as in this version most of the packages that you would normally have seen in the Packages directory in ST2 are zipped into .sublime-package files and stored elsewhere. However, there's a plugin for that! Make sure you have Package Control installed, then open the Command Palette, type pci to bring up Package Control: Install Package, and search for PackageResourceViewer. Install it, open the Command Palette again, type prv, and select PackageResourceViewer: Edit Package Resource. Scroll down to Default, click on it or hit Enter, then scroll down to Main.sublime-menu and select it to open it for editing. You can now follow the instructions above to find the line containing "close_folder_list" (it should be line 795) and either delete it or comment it out.
If you'd like to keep the menu item, but move it to a different spot, you can do that as well. For example, if you'd like it at the very bottom of the menu, separated by a divider, delete the original line, put the cursor below the "refresh_folder_list" line, and paste in the following:
{ "caption": "-" },
{ "command": "close_folder_list", "caption": "Remove all Folders from Project", "mnemonic": "m" },
so it looks like this:

Related

Sublime Text 3 HTML files comments are not angle brackets but curly brackets

When toggle comments with ctrl+/ on HTML or VueComponent files syntax with Sublime Text 3 the comments that appear are {{-- Comment text --}} instead of the correct ones <!-- Comment text -->.
How to make ST to add correct comments?
Edit as #MattDMo advised in comments below: add the list of installed packages.
"A File Icon",
"All Autocomplete",
"AutoFileName",
"Babel",
"BracketHighlighter",
"Chai Completions",
"Color Highlighter",
"Colorcoder",
"CSS Extended Completions",
"DocBlockr",
"Dockerfile Syntax Highlighting",
"DotENV",
"Edge Syntax Highliter",
"Emmet",
"HTML-CSS-JS Prettify",
"JavaScript & NodeJS Snippets",
"JavaScript Completions",
"JavaScript Snippets",
"JavaScriptNext - ES6 Syntax",
"JSON Reindent",
"LanguageTool",
"Laravel Blade Highlighter",
"LESS",
"MarkdownEditing",
"MarkdownPreview",
"nginx",
"Nunjucks Syntax",
"Package Control",
"PHP Companion",
"PHP Completions Kit",
"PHP-Twig",
"phpfmt",
"PHPGrammar",
"PhpNamespace",
"PHPUnit Completions",
"Select Quoted",
"SideBarEnhancements",
"SublimeCodeIntel",
"SublimeLinter",
"SublimeLinter-annotations",
"SublimeLinter-tslint",
"TypeScript",
"TypeScript Syntax",
"TypescriptCompletion",
"Vue Syntax Highlight",
"Vuejs Complete Package",
"zenburn"
Unfortunately, the only way to tell which package is highjacking your HTML commenting is to put (nearly) all of them in your "ignored_packages" setting, verify that the desired behavior has returned, then start removing packages from "ignored_packages" and see which one triggers the undesired behavior.
You can find (or create) "ignored_packages" in Preferences.sublime-settings in your Packages/User folder. The Packages directory is the one opened when selecting Preferences → Browse Packages…:
Linux: ~/.config/sublime-text-3/Packages
OS X: ~/Library/Application Support/Sublime Text 3/Packages
Windows Regular Install: C:\Users\YourUserName\AppData\Roaming\Sublime Text 3\Packages
Windows Portable Install: InstallationFolder\Sublime Text 3\Data\Packages
You can make the process go a little faster by removing packages from "ignored_packages" three or five at a time, then going down to one by one when the bad behavior comes back. Also, you don't need to ignore clearly innocent packages like Package Control, Zenburn, A File Icon, etc. Good luck!

Sublime Text 2 different indentations settings

I want to configure my Sublime Text 2 to have two different types of indentations:
4 spaces for general use
2 spaces for my html pages
I think it should be done by editing the settings, but I don't know what to write.
The key setting is "tab_size". By default, if you look at Preferences -> Settings-Default, it is
"tab_size": 4
The items in this file should absolutely not be modified. Instead, copy anything you want to change to the file opened by Preferences -> Settings-User, and alter the values there. It is saved as Packages/User/Preferences.sublime-settings where Packages is the folder opened by selecting Preferences -> Browse Packages....
If you would like to have specific settings for certain syntaxes, open a new file in Sublime with JSON syntax. Like any other Sublime preferences file, open and close it with curly braces { }. Put your desired settings in it, one per line, each followed by a comma , except the last entry (basically, it should be valid JSON, except JavaScript comments are also allowed).
{
"tab_size": 2,
"translate_tabs_to_spaces": true
}
Finally, save it in your Packages/User folder as Syntax Name.sublime-settings - in your case, it should be HTML.sublime-settings. These settings should now be applied to any newly-opened or newly-created HTML files.

How to edit multiple files through "Find results" in Sublime Text

When I search multiple files via Command + Shift + F, the result is returned as something like a text file. This text file is editable, but changes made don't affect the original files.
Is it possible to do such that changes in "Find Results" propagates to the original source file?
The Find Results Apply Changes plugin was created to do just that.
You can install it through Package Control's "Install Package" option.
Before using this plugin, make sure that you have UTF-8 encoding enabled using the menu:
File > Save with Encoding > UTF-8
Once installed, you can apply any change you made to a "Find Results" buffer back to the files:
Search for "foo" in a folder (Sublime's default shortcut is CTRL+SHIFT+S)
This will open a "Find Results" buffer listing all the files with "foo" in it.
Change the instances of "foo" for "bar" or something else...
Go to the menu:
Find > Find Results - Apply Changes
This will write all the changes made back to the files and save the modified files automatically.
By default, using menus is the only way to make it work. However, it is quite tiresome and doesn't save as much time as it does with a keyboard shortcut. You can set your chosen keyboard shortcut by adding a new line in
Preferences > Key Bindings - User
by adding:
{ "keys": ["ctrl+r"], "command": "find_results_apply_changes" },
Don't use CTRL+S as it will overwrite saving file shortcut.
Warning!: According to the author of the plugin:
Uses regions to allow you do multiline changes, but when inserting new
newlines, will corrupt files if you commit more than once, this
because the new newlines will shift the line numbers. Will also
'corrupt' files if you add/remove newlines in other instances of the
modified files. eg in another tab. To prevent corruption this packages
will alert you and prevent most of these.
(This is a modified version of the description from the Find Results Apply Changes Github page.)
The shortest workaround I can think of would be to open the target file from search results by simply double clicking the path and then jumping to the according line using Ctrl+G on Windows or ⌃+G on Mac OS.
That's the way I do it and must say it is only a matter of seconds, even without the plugin.

Where does Sublime Text 2 store editing information?

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.

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!