105

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.

brett rogers
  • 6,501
  • 7
  • 33
  • 43
doque
  • 2,723
  • 6
  • 27
  • 44
  • 8
    http://www.binaryfortress.com/NotepadReplacer/ – Tim Lewis Apr 18 '13 at 16:59
  • NotepadReplacer uses image hijack by setting itself up as a debugger for notepad.exe and passing argv to your preferred text editor instead. – Brian Reiter May 29 '14 at 14:35
  • 6
    Flagged as off topic. This question is more about using Windows and Sublime Text than programming, so I think it belongs on SuperUser, not StackOverflow. – ArtOfWarfare Jul 21 '14 at 16:33

11 Answers11

214

Actually it is not my answer, I have just googled it:

  1. Open regedit (Win+R, type "regedit", select OK).
  2. Navigate to HKEY_CLASSES_ROOT\Applications\sublime_text.exe\shell\open\command
  3. Verify that the path is accurate, correct it if it is not. Exit regedit.
  4. 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).
  5. 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).

zzzzBov
  • 174,988
  • 54
  • 320
  • 367
avp
  • 4,895
  • 4
  • 28
  • 40
  • 42
    BTW, you can use Ctrl+Shift+Esc to open taskmanager.exe directly – Andrey Starodubtsev Aug 02 '12 at 15:03
  • with win7 and new version of sublime (2.0.2) this solution did NOT worked for me. So I used the sollution from Findekano (https://github.com/grumpydev/Sublime-Notepad-Replacement) and that did the job :) – gospodin Jul 17 '13 at 09:36
  • Worked for me as well! I didn't need step 4 either, simply going through steps 1-3 and then trying again and it all worked nicely. – Silwing Jul 29 '13 at 12:23
  • 21
    Worked, my registry was still pointing to Sublime2 I uninstalled when going to Sublime3. – phemios Aug 17 '13 at 09:57
  • 3
    For me, my registry "Data" value needed to be set to: `"C:\Program Files\Sublime Text 2\sublime_text.exe" %1` – Jace Browning Dec 10 '13 at 16:25
  • 2
    thanks, fixed my problem on Win7 - didn't even need to kill explorer.exe, it just worked. – Shahar Apr 23 '14 at 15:11
  • Good answer, however I'm not able to launch explorer.exe with `Win` + `R`, because the run window is not opening. – kleinfreund Jun 28 '14 at 14:55
  • 1
    Thanks, worked for me as well. I previously installed/uninstalled Sublime 3 leaving the registry reference pointing to Sublime 3 instead of my current Sublime 2. – BustedSanta Oct 02 '14 at 12:55
  • 2
    My value was previously `"C:\Program Files\Sublime Text 3\sublime_text.exe" "%1"` - that is with double-quotes around %1. I removed these double-quotes, so the value was `"C:\Program Files\Sublime Text 3\sublime_text.exe" %1`, restarted explorer.exe and Sublime, and then it worked – Frederik Struck-Schøning Sep 19 '15 at 08:31
  • @kleinfreund, open TaskManager via Ctrl+Alt+Del, then "File -> New Task...". Also, Win7+ doesn't require Explorer restart (but may need to press F5 in regedit, to apply changes), as Shahar mentioned – ankhzet Feb 20 '16 at 06:16
37

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

Community
  • 1
  • 1
Jay Zhu
  • 1,636
  • 13
  • 17
  • 3
    A more generic version of this is NotepadReplacer: http://www.binaryfortress.com/NotepadReplacer/ – Tim Lewis Apr 18 '13 at 17:00
  • This is erroring out with "The Application was unable to start" for me Findekano on Windows 7 64 bit with Sublime Text 3. @Tim Lewis thanks this works great! – fIwJlxSzApHEZIl May 22 '14 at 03:42
21

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"
robertcollier4
  • 742
  • 10
  • 10
  • Thanks! Setting Sublime to replace notepad is amazing, however it doesn't work with paths containing spaces (at least for me!), it just opens a tab for each space-separated path element. Any idea on fixing that? – Dan Sep 03 '13 at 07:47
  • 1
    @Dan - search in registry for `notepad.exe %1` and replace all found instances with `notepad.exe "%1"` – robertcollier4 Oct 17 '18 at 21:54
  • This was the only thing of all these answer that worked for me on Windows 10: `[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\Notepad.exe] "Debugger"="\"C:\Program Files\Sublime Text 3\sublime_text.exe\" -z"` – tedi Jun 11 '20 at 18:53
21

1: You can also set your associations in Control Panel:

Control Panel > Default Programs > Associate a file or protocol with a specific program:

enter image description here

2: Or, call it from code via IApplicationAssociationRegistrationUI::LaunchAdvancedAssociationUI ;)

HRESULT LaunchAdvancedAssociationUI(
   [in]  LPCWSTR pszAppRegName
);
Dariusz Woźniak
  • 9,640
  • 6
  • 60
  • 73
5

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.

kick3rzzz
  • 51
  • 1
  • 2
2

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

  1. open CMD as administrator
  2. run this line: FTYPE sublime="C:\Program Files\Sublime Text 3\sublime_text.exe" "%1"
  3. for .php files use this command: ASSOC .php=sublime for js use this: ASSOC .js=sublime and so on...
Chris D
  • 13
  • 1
  • 4
Bassem Shahin
  • 656
  • 7
  • 13
2

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".

Andrey Starodubtsev
  • 5,139
  • 3
  • 32
  • 46
  • 6
    This won't work for anyone who used the version that modified the registry. See my answer for details. – avp Aug 02 '12 at 11:43
  • 2
    -1 StackOverflow is not "Windows for Dummies". Clearly there was more to the question! – Riegardt Steyn Jul 16 '13 at 08:58
  • This may still help someone who is afraid to edit the registry. You should not assume everyone is at the same level as you are. – Eoin Nov 09 '16 at 17:16
1

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

Ijas Ameenudeen
  • 9,069
  • 3
  • 41
  • 54
1

sublime can be set as the default text editor by following these steps:

  1. right-click on the .txt file and select properties.
  2. then in Open with: option click on Change.
  3. 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
kiranr
  • 2,087
  • 14
  • 32
0

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

-3

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.

nnnn
  • 149
  • 1
  • 10