Is there a way to set Sublime Text as the default text editor for file formats on Windows 7?
Also, if anyone knew a Sublime Text Tutorial or Wiki that would be really helpful.
Actually it is not my answer, I have just googled it:
Open regedit (Win+R, type "regedit", select OK).
Navigate to HKEY_CLASSES_ROOT\Applications\sublime_text.exe\shell\open\command
Verify that the path is accurate, correct it if it is not. Exit regedit.
Open task manager via Ctrl+Alt+Del (or Ctrl+Shift+Esc for later versions of Windows), kill explorer.exe, go to run (Win+R) and type "explorer.exe" (or skip this step and simply reboot).
Now attempt the same thing, right click a text file, open with, navigate to sublime, and it should now appear in the list of available applications.
For me that value pointed to the Desktop where portable version previously was placed. Thus it just didn't work.
P.S. And for me the reboot or logout were not necessary (WinXP).
Edit on Nov 21, 2014
Tim Lewis pointed out in the comment that there is a more generic version at http://www.binaryfortress.com/NotepadReplacer/, which works better.
Original Answer
Try this: https://github.com/grumpydev/Sublime-Notepad-Replacement
Here are some ways to associate Sublime Text Portable. The following text needs to be saved as a file with a .reg extension and then on that file Right Click > Merge.
This will add a Sublime right click menu entry to all files:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell]
#="Sublime"
[HKEY_CLASSES_ROOT\*\shell\Sublime]
#="&Sublime"
[HKEY_CLASSES_ROOT\*\shell\Sublime\command]
#="\"D:\\PortableApps\\SublimeText\\sublime_text.exe\" \"%1\""
This will have Sublime Text replace all calls to notepad.exe:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\Notepad.exe]
"Debugger"="\"D:\\PortableApps\\SublimeText\\sublime_text.exe\" -z"
This will create a SublimeFile class which you can then associate with any extension.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\SublimeFile\shell]
#="edit"
[HKEY_CLASSES_ROOT\SublimeFile\DefaultIcon]
#="\"D:\\PortableApps\\SublimeText\\sublime_text.exe\",0"
[HKEY_CLASSES_ROOT\SublimeFile\shell\edit\command]
#="\"D:\\PortableApps\\SublimeText\\sublime_text.exe\" \"%1\""
This will then associate the .ext extension with SublimeFile:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.ext]
#="SublimeFile"
1: You can also set your associations in Control Panel:
Control Panel > Default Programs > Associate a file or protocol with a specific program:
2: Or, call it from code via IApplicationAssociationRegistrationUI::LaunchAdvancedAssociationUI ;)
HRESULT LaunchAdvancedAssociationUI(
[in] LPCWSTR pszAppRegName
);
You can just run CCleaner's registry cleaner tool and then choose and add the default program as usual. It worked for me when upgrading from ST2 to ST3.
Open context menu on file with desired extension in Explorer, than select Open with->You editor ( may be you need to browse for its binary before it appears in the list of available programs ) and set checkbox "Always use the selected program to open this kind of file".
I tried all options to make sublime text 3 as the default program for my .php, .css and/or .js files
I don't exactly know why it all failed, I think it is related to windows 10 current version bug
But the good news is there is some working way for me, also for those who love CMD
open CMD as administrator
run this line: FTYPE sublime="C:\Program Files\Sublime Text 3\sublime_text.exe" "%1"
for .php files use this command: ASSOC .php=sublime for js use this: ASSOC .js=sublime and so on...
Try this,
#echo off
SET st2Path=C:\Program Files\Sublime Text 2\sublime_text.exe
rem add it for all file types
#reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2" /t REG_SZ /v "" /d "Open with Sublime Text 2" /f
#reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2" /t REG_EXPAND_SZ /v "Icon" /d "%st2Path%,0" /f
#reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2\command" /t REG_SZ /v "" /d "%st2Path% \"%%1\"" /f
rem add it for folders
#reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 2" /t REG_SZ /v "" /d "Open with Sublime Text 2" /f
#reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 2" /t REG_EXPAND_SZ /v "Icon" /d "%st2Path%,0" /f
#reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 2\command" /t REG_SZ /v "" /d "%st2Path% \"%%1\"" /f
pause
I tested this for SublimeText 3(Portable) also and working fine. Create a .bat file with the above code and run it as administrator.
Reference : https://gist.github.com/mrchief/5628677
sublime can be set as the default text editor by following these steps:
right-click on the .txt file and select properties.
then in Open with: option click on Change.
if the sublime is listed in the list of apps then select it, if not scroll down and click on the look for another app on this PC and select the sublime app file
I was facing the same problem.
the only solution was correct it manually
--> open regedit and navigate to Computer\HKEY_CLASSES_ROOT\Applications\, find the sublime_text.exe entry, and delete it. You should now be able to set Sublime Text 3 as the default editor for anything you want.
i found this solution in this post:https://forum.sublimetext.com/t/cant-make-default-editor-in-windows/10747/14
If you are using the portable version, you can't set Sublime as the default program for any files because Windows won't acknowledge it as a program that can open things.
Related
I want to add the ability to open a folder with Sublime Text to the context menu, as it is by default in VS Code, I tried the following script:
#echo off
SET st3Path=C:\Program Files\Sublime Text 3\sublime_text.exe
rem add it for folders
#reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime Text 3" /f
#reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 3" /t REG_EXPAND_SZ /v "Icon" /d "%st3Path%,0" /f
#reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st3Path% \"%%1\"" /f
pause
This works, but every time I open a folder, all previous folders open in separate windows too. Can I fix it somehow?
You should use subl.exe and not sublime_text.exe for carrying out this action; subl is meant for interacting with the running instance of Sublime (and will start it if it's not already running), while sublime_text is the application itself.
Regardless of that however, your issue is also (somewhat) related to this setting, which as seen here defaults to being turned on:
// Exiting the application with hot_exit enabled will cause it to close
// immediately without prompting. Unsaved modifications and open files will
// be preserved and restored when next starting.
//
// Closing a window with an associated project will also close the window
// without prompting, preserving unsaved changes in the workspace file
// alongside the project.
"hot_exit": true,
When this is enabled you can quit Sublime at any point and have it save it's session (including unsaved file changes, selection states, etc) and then restore that to put you back to where you were.
So, if you previously quit Sublime while you had windows open, then when you carry out your action above Sublime will restore it's session (and all other windows) and then create the new one.
Turning the setting off stops that from happening so that every startup of Sublime is a "clean" state with no restored windows or state. However this also implies that when you quit Sublime you need to ensure that you save changes or your work will be lost.
Given your provided information and based upon the information provided in the command help, reg add /?, I'd assume that your batch file should look something like this:
#Set "st3Path=%%Program Files%%\Sublime Text 3\sublime_text.exe"
#Set "regPath=HKCU\Software\Classes\Folder\shell\Open with Sublime Text 3"
#%__AppDir__%reg.exe Add "%regPath%" /VE /D "Open with Sublime Text 3" /F >NUL
#%__AppDir__%reg.exe Add "%regPath%" /V Icon /T REG_EXPAND_SZ /D "\"%st3Path%\",0" /F >NUL
#%__AppDir__%reg.exe Add "%regPath%\command" /VE /D "\"%st3Path%\" \"%%~1\"" /F >NUL
As for your Software opening previously opened 'folders', I'm sure that, you can configure the software not to reopen previous files on startup, directly in the Software or by editing its config files. That is therefore outside of the scope of your code issue, and to be dealt with separately.
You'll notice that I've used the 'Current User' registry, not the 'Local Machine', as it doesn't require to be 'Run as administrator' and you shouldn't be globally making personalization changes; not everyone wants them.
If you wish to do it for all users, however, just replace HKCU on line 2 with HKLM.
Please also note, that I have no knowledge of your software itself, so taking account of the information provided in the OdatNurd's answer, please consider whether to replace sublime_text.exe on line 1 with subl.exe
For sublime 4 (not sure about sublime 3) on windows, you just need to run the setup file again.
It will ask you if you want to add it to context menu.
I do not have administrator privileges at office and I would like to add Sublime Text to contextual menu to edit easily my files such as Notepad++. Is it possible? I've only found how to add it with Administrators privileges
Often we do not have administrator privileges at office on our PC, so some weeks ago I found a useful guide to add Sublime to the contextual menu.
First you need create a new text document with any text editor, copy and paste the below script, save it on your desktop with .bat extension
#reg add "HKEY_CURRENT_USER\Software\Classes\*\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime Text 3" /f
#reg add "HKEY_CURRENT_USER\Software\Classes\*\shell\Open with Sublime Text 3" /t REG_EXPAND_SZ /v "Icon" /d "%st3Path%,0" /f
#reg add "HKEY_CURRENT_USER\Software\Classes\*\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st3Path% \"%%1\"" /f
Keep in mind that you must replace %st3Path% with your current SublimeText directory, e.g: C:/Tools/sublime/sublimetext.exe
Double-click on that file to apply the settings. Now you can see Sublime in the context menu.
On the other hand we may need to remove Sublime from contextual menu, for to do that you can use the following script, and repeat the same steps above:
#reg delete "HKEY_CURRENT_USER\Software\Classes\*\shell\Open with Sublime Text 3\command" /f >nul 2>&1
#reg delete "HKEY_CURRENT_USER\Software\Classes\*\shell\Open with Sublime Text 3" /f >nul 2>&1
Or if you prefer, here's the script ready to use it: SublimeText-ContextualMenu.bat
I'd like to add an option on my context menu (Windows 7 and 10) to open an Anaconda Prompt into the file location when I right-click the folder, but I can't figure out the right registry key.
Here's what I know how to do:
Add an item to the context menu that opens a normal command window at the folder location
Open an Anaconda prompt from cmd (run their "activate.bat" file)
What I can't figure out is how to combine these steps into a single registry key so I can open an Anaconda Prompt and then cd in that prompt to the current folder. But maybe I'm approaching this the wrong way.
Help from internet gurus is appreciated.
Run Registry Editor (regedit.exe)
Go to HKEY_CLASSES_ROOT > Directory > Background > shell
Add a key named AnacondaPrompt and set its value to Anaconda Prompt Here
Add a key under this key called command, and set its value to cmd.exe /K C:\Users\user\Anaconda3\Scripts\activate.bat change the location to wherever your Anaconda installation is located.
In recent Anaconda versions (I'm at conda 4.5.5) they have changed the behaviour and the shortcut to Anaconda Prompt, so the new procedure is in fact a bit simpler than described by bdforbes.
The new way to launch Anaconda Prompt in a folder is
cmd.exe /K %%USERPROFILE%%\AppData\Local\Continuum\Anaconda3\Scripts\activate.bat
pushd is to change the current directory, %V is the current directory, and /K is to run a command.
So the modified cwp2.py is not needed anymore. Put the following contents in a .bat-file and run as administrator to add the needed keys to the registry (a modified version of the gist posted by Thibaud Ruelle in the comments to the other answer)
REG ADD HKCR\Directory\Background\shell\Anaconda\ /ve /f /d "Anaconda Prompt Here"
REG ADD HKCR\Directory\Background\shell\Anaconda\ /v Icon /f /t REG_EXPAND_SZ /d %%USERPROFILE%%\\Anaconda3\\Menu\\Iconleak-Atrous-Console.ico
REG ADD HKCR\Directory\Background\shell\Anaconda\command /f /ve /t REG_EXPAND_SZ /d "%windir%\System32\cmd.exe pushd "%V" "/K" %%USERPROFILE%%\Anaconda3\Scripts\activate.bat %%USERPROFILE%%\Anaconda3"
REG ADD HKCR\Directory\shell\Anaconda\ /ve /f /d "Anaconda Prompt Here"
REG ADD HKCR\Directory\shell\Anaconda\ /v Icon /f /t REG_EXPAND_SZ /d %%USERPROFILE%%\\Anaconda3\\Menu\\Iconleak-Atrous-Console.ico
REG ADD HKCR\Directory\shell\Anaconda\command /f /ve /t REG_EXPAND_SZ /d "%windir%\System32\cmd.exe pushd "%V" "/K" %%USERPROFILE%%\Anaconda3\Scripts\activate.bat %%USERPROFILE%%\Anaconda3"
UPDATE: The answer by Filip S. might work better on more recent versions of Anaconda.
ANOTHER UPDATE: I fixed an issue with using this launcher in the drive root (e.g. C:\ or D:\). It's very minor: some whitespace has been added to the registry entry (relevant part: "%V ") so that the trailing backslash does not confuse Windows.
Original post
I also wanted this functionality, so I made it.
The key steps are outlined below, with the explanation further down.
Solution
Warning: Do not proceed unless you are comfortable editing the registry and are using a non-production system. And obviously don't run everything I tell you to, check that it's not doing anything nefarious. You don't know me!
1. Modify the Anaconda script that sets the working directory
Find the Anaconda script cwp.py (mine was in C:\Users\bdforbes\Anaconda3\) and copy it to cwp2.py in the same directory.
Modify cwp2.py to accept a target path as the second argument and change to that directory:
prefix = sys.argv[1]
cwd = sys.argv[2]
args = sys.argv[3:]
... (PATH setting code)
(REMOVE OLD LOGIC THAT CALLED os.chdir)
os.chdir(cwd)
sys.exit(subprocess.call(args, env=env))
Full code here: https://gist.github.com/bdforbes/9ef59cd01c22acefc20c5c92bd9550ae
2. Add the registry keys
In the registry, go to HKEY_CLASSES_ROOT\Directory\Background\shell\ and add a key Anaconda with default value "Open Anaconda Prompt Here", with a sub-key command with the following default value:
C:\Users\bdforbes\Anaconda3\pythonw.exe C:\Users\bdforbes\Anaconda3\cwp2.py C:\Users\bdforbes\Anaconda3 "%V " cmd.exe "/K" C:\Users\bdforbes\Anaconda3\Scripts\activate.bat C:\Users\bdforbes\Anaconda3
Add the same entries to HKEY_CLASSES_ROOT\Directory\shell\.
I've put a .reg file here, you just need to search replace bdforbes and replace it with your Windows account name. Don't run a .reg file without checking it first!
3. Use your fancy new context menu item
Right click on a folder. You should see the new entry there which will let you open a new Anaconda prompt.
I am looking for a way to right click a file in Windows 10, select "Open with" -> "Sublime Text", and then have a new Sublime Text window appear.
The default action is to open the file in a new tab, if Sublime is already open. This is usually not what I want, especially since I usually have Sublime open on a different desktop.
I've tried making a shortcut with the -n flag added, which correctly gives me a new window when just using the shortcut. But when I "Open with" using that shortcut it opens the file in an existing window.
I also tried "Open with" a batch file containing subl -n, ``but alas.
This works for me (and is more comfortable for me than the Open with submenu):
Open regedit.exe
navigate to HKEY_CLASSES_ROOT\*\shell
To apply this only to certain file types replace the * with the appropiate extension
Add key "Open With sublime in new window"
Inside this, add new key "command"
Inside "command" set the (Default) string to:
C:\Program Files\Sublime Text 2\sublime_text.exe -n "%1"
(basically copy the original keys, adding the -n)
Optional:
Inside the key "Open With sublime in new window", add a string named Icon:
C:\Program Files\Sublime Text 2\sublime_text.exe,0
This will add an the Sublime Text icon to the left of the command on the right-click menu.
To add the entries to the context menu for folders, add the same entries in:
HKEY_CLASSES_ROOT\Folder\shell
For the context menu when you click on a folder icon
HKEY_CLASSES_ROOT\Directory\Background\shell
For the context menu when you click on the background of a folder
For this entry you must replace "%1" with "%V" (Thanks Filip)
If you prefer a script to do this, consider using the following in a batch script:
#echo off
SET st3Path=C:\Program Files\Sublime Text 3\sublime_text.exe
rem add it for folders
#reg add "HKEY_CLASSES_ROOT\Directory\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime" /f
#reg add "HKEY_CLASSES_ROOT\Directory\shell\Open with Sublime Text 3" /t REG_EXPAND_SZ /v "Icon" /d "%st3Path%,0" /f
#reg add "HKEY_CLASSES_ROOT\Directory\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st3Path% \"%%1\"" /f
rem add it for current folder
#reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime" /f
#reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\Open with Sublime Text 3" /t REG_EXPAND_SZ /v "Icon" /d "%st3Path%,0" /f
#reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st3Path% \"%%v\"" /f
pause
Put this in a .bat file (mine is called SetSublimeMenuShortcuts.bat) and then run in Powershell as an administrator user invoking it with .\SetSublimeMenuShortcuts.bat. If you see the following, it should be set properly:
The operation completed successfully.
The operation completed successfully.
The operation completed successfully.
The operation completed successfully.
The operation completed successfully.
The operation completed successfully.
Press any key to continue . . .
Open settings, then add the following line between { }:
"open_files_in_new_window": false
I'm deploying a small conversion tool on some systems, and want the users to be able to run it from the right click Open with menu. But I don't want to change the default program users have associated to this file type.
It is easy to associate a file extension/type to a program, but how to do it (programatically of course) without changing the default program?
Setting the following keys worked for me:
key HKLM/SOFTWARE/Microsoft/Windows/CurrentVersion/App Paths/<progname>: "" = <appPath>
key HKCR/Applications/<progname>/SupportedTypes: <fileExt> = ""
key HKCR/<fileExt>: "" = <progID>
key HKCR/<progID>/OpenWithList/<progName>
key HKCR/<fileExt>/OpenWithList/<progName>
key HKCR/SystemFileAssociations/<fileExt>/OpenWithList/<progName>
delete key and subkey at HKCU/SOFTWARE/Microsoft/Windows/CurrentVersion/Explorer/fileExts/<fileExt>
You can add scripts to the context menu (below Open with) by adding it in the windows registry:
Open regedit
Goto HKEY_CLASSES_ROOT\your_class\Shell
Add a new key and give it a name
Edit the (Default) value of this key and insert the text you want to show in the context menu
Add a new key named Command under your newly created key
Edit the (Default) value of this key and insert the command you want to execute
Enjoy!
In the "File Types" Windows Dialog you can click "Advanced" on your file type and there create a custom action tied to your application.
Possibly you can also find a way to do this in a programmatic manner, or at least create a .REG file with the equivalent registry options.
I have achieved the correct FILE ASSOCIATION using these cmd commands.
(just an example):
REG ADD "HKEY_CLASSES_ROOT\Applications\notepad++.exe\shell\open\command" /v # /t REG_SZ /d "\"C:\\Program Files\\Noteepad++\\notepad++.exe\" \"%1\"" /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt" /v "Application" /t REG_SZ /d "notepad++.exe" /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\OpenWithList" /v "g" /t REG_SZ /d "notepad++.exe" /f
assoc .txt=MyCustomType
ftype MyCustomType="C:\Program Files\Noteepad++\notepad++.exe" "%1"
(it's better to put them in .bat file)
here's a worked example for XP adding a command prompt option to folders. Create a .reg file
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\Command Prompt]
[HKEY_CLASSES_ROOT\Directory\shell\Command Prompt\command]
#="cmd.exe /k cd \"%1\""