How to refresh Sublime Text 3 workspace color schemes? - sublimetext

When you save a project, Sublime Text will create a .sublime-workspace file. In this file, there is an array of buffers, and for each buffer there is a color_scheme property. This is set to whatever color scheme was chosen when the buffers and workspace were created.
I recently changed my theme and color scheme in my user settings file. How can I refresh all of my project's workspaces so that way it uses my new color_scheme provided in my user preference file without needed to edit each project's workspace file one-by-one?

Expanding on the answer given by Tot you can do this for all views in all windows that are open by using a nested list comprehension (remember this is Python so we can be pretty flexible):
[ v.settings().erase("color_scheme") for views in [ w.views() for w in sublime.windows() ] for v in views ]
This way you don't have to run the command in each tab individually.

The only way I found to reset tabs to user's chosen color scheme is to enter this in the console :
view.settings().erase("color_scheme")
This will reset the color scheme of the selected tab - unfortunately you'll have to do it for each tab. But it's still quicker than closing and reopening the tab.
I only have this issue with Sublime Text 3 on Mac OS X.
Source : https://www.sublimetext.com/forum/viewtopic.php?f=3&t=19310
P.S. : If you've just updated your color scheme file, you'll sometimes have to execute this command twice. Just type the up arrow in the console to write the last command again.

Windows 10 AppData-related Solution
Please make sure that you are in a similar situation as me before trying this solution (see below). Steps:
Note the language and package that the Error loading colour scheme reports (my case was: markdown and MarkdownEditing).
Go to your AppData directory (type %AppData% in file explorer address bar).
Open directory Sublime Text 3, or whatever your version is.
Open the .sublime-settings file that matches the language from step 1.
Remove any lines that refer to the package you noted from step 1.
Remember that this file should be a properly formatted JSON file when you remove lines manually. Save this file and restart Sublime Text.
Background
I've decided to post here in case some of the python script solutions didn't work for you and your situation is similar to mine. I'm using GitHub to sync my Sublime Text AppData (Windows 10), in order to keep my workflow settings the same on multiple machines. Recently, I noticed that when I uninstalled a certain package on one of my machines, I accidentally merged some configuration files for that non-existent package on my other machine. This resulted in a persistent Error loading colour scheme, in particular for me when changing syntax to markdown (the package was MarkdownEditing for reference).

Related

Correct the file associations in the registry in windows 7 when a program is deleted

I have a windows 7 operating system and had installed Rstudio in the my documents folder (by just unzipping the .zip file) as I don´t have admin rights to my computer.
I then manually associated the file endings .Rproj .R and .Rmd with rstudio.exe by:
right-clicking on a file with that ending
selecting "Open with..."
Clicking on "Browse"
Going to the "bin" folder within my RStudio installation and selecting "rstudio.exe"
This worked fine, and the files opened automatically in RStudio when I double-clicked on them.
Over the following months, I updated RStudio twice but did not delete the old versions. Then I noticed that the files were always opening in the oldest version of RStudio (the first one that I had installed).
I decided to clean up, and deleted the two older versions.
At this point, the file associations dissappeared (as expected, since I had just deleted the program they had been associated with).
To associated them to the latest version of RStudio, I repeated the manual steps above, but hit a snag: after selecting rstudio.exe by clicking on the "browse" button within the dialogue box, the program did not appear as an option in the main dialogue box and I could not associate the file with it.
I searched for a solution here and elsewhere but was unable to find one with a complete set of steps that fixed my problem. I did note that this problem is by no means unique to Rstudio, and I suppose can happen to any file endings that have been associated with a program that you have deleted (as opposed to uninstalled?).
I had a suspicion that the path to the old version of Rstudio was stuck in the registry somewhere, but trying various iterations of assoc .Rproj in the command-line didn´t help me:
C:\Users\myusername>assoc .Rproj
File association not found for extension .Rproj
C:\Users\myusername>assoc .Rproj = rstudio
Access is denied.
Also, RStudio was not available in the Default Programs list (accessed from the start menu) and the affected file endings were not listed under File associations either.
I eventually found the solution using windows regedit - but since there doesn´t seem to be a post with the complete steps for this, I have posted it as an answer here, in case anyone else faces the same issue. I had to do this the point and click way, so would be grateful if anyone could provide a solution in the command-line interface, or provide some insight into why I got that "Access is denied" message (which occured even when I tried logging in with a temporary admin account).
It turns out I was right - the old file path was still associated to the file endings in the registry. I was unable to access or edit it from the windows command line prompt, but using the windows regedit program worked, as follows:
Go to the start button, type regedit and click on the regedit program icon to open it.
On the left-hand side menu in regedit, click on the arrow to expand the folder HKEY_CLASSES_ROOT
Scroll down the list to look for the file endings that have become unassociated (in my case this was .R, .Rproj and .Rmd)
Click on one of the unassociated file endings to see what details are recorded for it (these will appear in the right-hand panel of regedit).
See what it says under the Data column for your file ending (in my case, for .R it said “R_auto_file”).
This value (e.g. “R_auto_file”) is the key used to point to the program that will be used to open the file.
Now scroll further down the left-hand menu in regedit, past the zs and keep going until you find a sub-folder with the same name as the key you just identified.
Click on the arrow next to this sub-folder (e.g. “R_auto_file”) to expand it and expand the sub-folders within it (shell and open) until you get to command.
Click on command to view the details in the right-hand panel.
Right-click on the icon that says Default under the column Name in the right-hand panel and select Modify… from the menu that appears.
In the dialogue box that appears, under Value data: you will see an editable file path to the program being used to open the file.
This file path will probably be pointing to the old version of the program that you deleted.
Edit the file path so that it points to the new program, and click ok to save the changes.
Repeat steps 3 – 13 for all file types that have become unassociated.
Restart the computer for the changes to take effect.
You should now see that the files have the program icon next to them and open with the correct version when you double-click on them.
I had a similar issue with RStudio on Windows:
After installing RStudio with the installer I have updated to a newer version via the downloadable ZIP file and installed it into another folder.
Since then a double-click on .Rproj opened the old RStudio instead of the new one despite I tried to reassign the extension with the new RStudio.exe file
My solution was to change this registry entry via a Console:
reg add HKEY_USERS\<Windows SID>_Classes\Applications\rstudio.exe\shell\open\command /f /ve /d "\"C:\Users\Public\RStudio\bin\rstudio.exe\" \"%1\""
Please replace the in the code snippet above with your personal windows user ID. You can get your SID with
whoami /user
A SID looks like this:
S-1-8-21-667978445-1323479522-1885766523-895239
BTW: You could also use good old regedit to change the path (no local admin rights required!)

How to unmap sublime text keybinding so standard os action happens?

The normal mac behavior for command+shift+? is to open the help menu search, which is super convenient to do menu commands without a mouse.
Unfortunately a sublime text package I have installed has mapped that key binding to the settings menu. Here's the relevant section of the package Default (OSX).sublime-keymap file
[
{ "keys": ["super+shift+/"], "command": "open_settings" }
]
Based on Related to How to unbind a key binding in Sublime Text 2?
I went ahead and overrode their keybinding in my user keybinding. Here's my user Default (OSX).sublime-keymap file.
[
{ "keys": ["super+shift+/"], "command": "noop" }
]
This stops the package from open settings when I press the key sequence. Same behavior if I use unbound for the command, excluding the command files package keybinding. However, it doesn't bubble up to the Mac layer which opens the help search menu.
I can get things to work the way I want to by modifying the package's key binding file directly, but that's going to get overwritten the next time the package upgrades.
Is there a supported way to remove a keybinding without stopping it from bubble up to the operating system?
The only way to completely remove a key binding in a way that Sublime won't react in any way is to remove it from the sublime-keymap file. This is true whether you want to fully remove a file from the Default/Default (PLATFORM).sublime-keymap (there is one for each platform) that ships with Sublime to remove a default key binding as well as any that might be added by a third party package.
As long as the key remains in a sublime-keymap anywhere, Sublime will see it and try to do something with it, even if the key is bound to a command that doesn't exist such as noop (although that is a good way to block a default key from doing anything if that's your ultimate goal).
Editing the package file
One way to solve the problem is to directly modify the packaged file itself, as you've already mentioned. In most cases that would mean unpacking the related sublime-package file (which is just a zip file), modifying the content of the file, and then repacking it.
As you've already noted, that's not a good way to go because when a package gets updated, the entire sublime-package file gets clobbered away, so your changes will also get discarded.
Overriding the package file
A safer way to do this would be to create a package override file instead. This only works if the package in question is installed as a sublime-package file, which covers all of the packages that ship with Sublime as well as most third party packages.
To do this, you would create a folder in the same name of the package in the Sublime Packages folder, which you can get at via the Preferences menu item Browse Packages.... Once that's done, extract just the file you want to override and place it into that folder, and edit it as desired.
When Sublime loads packages from a sublime-package file, as it loads each file it checks to see if any similarly named "unpacked" files exist in the Packages/PackageName/ folder. If such a file exists, the version inside of the sublime-package file is ignored and the unpacked file is used instead.
This means that even if the package gets updated, since your unpacked version is still there, it will still be used and so your change will remain in place.
The easiest way to create such a file is to use the PackageResourceViewer package. You can use it's PackageResourceViewer: Open Resource command from the command palette to find and open the offending file. If you make changes to the file and save it, PRV will automatically create the override for you.
There are a couple of caveats to this process:
If the package in question is installed already unpacked in the Packages folder, you can't create an override. In this case there's not a lot you can do other than vigilantly re-modify the file when it updates.
Most packages won't fall under this restriction because few actually need to be installed that way (only packages that contain files that need to be exposed outside of Sublime need to be installed this way).
Note also that Sublime Text 2 only installs packages as unpacked, so in that particular case you also can't do this.
When a package override exists, it's always used in place of a packed file of the same name, no matter what. This has the unfortunate side effect that if the package update actually modifies the file that you're updating in any way, those changes are masked from you without warning.
Will the full caveat/disclosure that I'm the one that wrote the package, the OverrideAudit package for Sublime can warn you when this happens by checking every time a package gets updated to see if the version of the packaged file is newer than your overridden version so that you know this is happening and can take appropriate action.
Sublime Text 2 notes
Your question is tagging Sublime Text 2 and Sublime Text 3. In the case of Sublime Text 2, the information above about needing to remove a key binding completely in order to allow the OS to see it still holds.
However as far as I'm aware Sublime Text 2 doesn't support the idea of package overrides because it always installs all packages unpacked. As such the only solution in that particular case is to modify the packaged file and keep an eye out for changes.
At this point with Sublime Text 3 officially released there are not many compelling reasons to keep using ST2. If you purchased your license for ST2 sometime mid/late 2013 or later your license should be valid for ST3.
This is particularly important in that ST2 is no longer supported and as of High Sierra when Apple removed Python 2.6, various Sublime packages will now no longer work.

How do I use Mac OS aliases in Sublime Text 3?

I want to open the tree of folders which contains any code on my Mac in Sublime 3. Something like this:
But I don't have all of it in one folder, and it isn't convenient enough to open many folders in Sublime every time I close the app. So I have created 'aliases' (via Finder) to my folders and put them to one (folder), which i want to open with Sublime.
That didn't work out. Sublime opens these aliases as hex code. While ordinary folders open well.
So the main question: is there a way to make this work as I thought via preferences, or any plugin?
Use symbolic links instead by opening Terminal and using ln -s <SOURCE> <ALIAS>.
You can keep any number of folders you want collected in one place by using projects. Simply drag the folders you want, in the order you want, into the sidebar. Then, select Project -> Save Project As... and save the file anywhere you want with the .sublime-project extension. While you're at it, make sure you have
"hot_exit": true
in your user settings, as this enables you to close windows which have a project assigned to them, and all open files and unsaved changes are automatically preserved. When you next open the project, everything will be the same.

How can I export/import settings of Sublime Text 3 from one PC to another using Windows?

I use Sublime Text 3 in my company and I want to export all the settings, including packages and whatever, to use the same configurations in Sublime Text 3 I have at home. How can I do this?
PS.: I use Windows 8
The best way is to sync the User directory, there are multiple available ways to do this - dropbox, git and manual ways.
Installed packages are registered in Package Control.sublime-settings, which is located in the user folder as well, thus, it does not require you to sync anything besides that. A pretty good guide to syncing can be found here.
You also may wish to check out this package.
For me (Windows installation) transferring all the content from old installation - AppData\Roaming\Subime Text 3, to new installation - AppData\Roaming\Subime Text 3, does the job. All the packages and UI settings are transferred and are working correctly.
None of the manual efforts are needed now (I think). Both sublime text (ver 3) and visual studio code (if anyone cares) have extensions that do this for us.
For VS Code -
https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync
For ST3 -
https://packagecontrol.io/packages/Sync%20Settings
With a few clicks like generating token and configuration, one should be able to easily port the settings from any machine (Win, OSX, Linux) to any machine.
You can try this plugin PackageSync. It can package your settings and packages into a zip or 7z file, then, you can import them on another machine.
As an aside an easy way to locate the 'User' or 'Sublime text {2/3/etc}' folder regardless of OS is to:
Open go-to-anything and just type: 'us'
From the available options select 'Preferences: Package Control Settings - User’ to open that file.
Right click on the file and make the selection to open the containing folder (Mac: reveal in finder)
Navigate back up to the parent folder Sublime Text 3 (or whatever version number you are on)
Copying this folder and replacing the Sublime Text 3 folder in a fresh Sublime install with this one should install all packages and replicate any other settings you have.
source
"If you want to sync settings across machines, the best way to do so is to just sync the Packages\User\ folder. This contains all customized settings, and if you are using Package Control, it includes a list of all installed packages. If Package Control sees that an installed package is not present on the machine, it will automatically install it the next time Sublime Text starts."
PS: if I am not mistaken the author of this post is the key developer of sublime.

How do I configure TortoiseHg to open a file in the right program based on its extension?

I'm using TortoiseHg v2.2.1 with Mercurial 1.9 in WindowsXP. How do I configure TortoiseHg to view a file based on the application Windows has associated with its extension?
For example, if I have a .docx file in the repository and I'm looking at its revision history, I'd like View at revision... to open the selected revision in MS Word. Likewise for other binary file types like ppt and xls, which I can't view using the default text editor or kdiff3.
Can I leverage that Windows already knows what program to use to open certain types of files or will I have to manually configure each file type of interest within the Tortoise config files?
I've found several SVN scripts in the TortoiseHg\diff-scripts folder that look like they solve a similar problem for diffing binaries rather than simply viewing them, but those don't seem to be activated and I'm not sure what if anything I need to mod in the MergePatterns.rc or Mercurial.ini files to make this all work.
To make "View at Revision" use whatever program is associated with the file's extension, try this trick: In the "Global Settings" in the "TortoiseHg" section, enter start "" as "Visual Editor". Note the empty "". This is necessary so that start will not use the file name, which gets passed in quotes by TortoiseHg, as the window title.

Resources