Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add "Open with Sublime Text 3" to Windows Explorer Context Menu (including folders)
@echo off
SET st2Path=C:\Program Files\Sublime Text 3\sublime_text.exe
rem add it for all file types
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime Text 3" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3" /t REG_EXPAND_SZ /v "Icon" /d "%st2Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3\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 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 "%st2Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st2Path% \"%%1\"" /f
pause
@thehighestprimenumber

This comment has been minimized.

Copy link

@thehighestprimenumber thehighestprimenumber commented Oct 10, 2017

works great:
you just need to download the file and run it as administrator.

@mittalyashu

This comment has been minimized.

Copy link

@mittalyashu mittalyashu commented Oct 30, 2017

Everything works fine.

But I have one problem and that is if we select a directory and open in Sublime Text.
The probme is that it open's that directory in new sublime window.

I want to append that directory in the existing sublime window.

@richellyitalo

This comment has been minimized.

Copy link

@richellyitalo richellyitalo commented Nov 11, 2017

With me wire needed to replace '%%1' with '%1'.
Using Windows 8.1

Thanks for sharing. @jackielii

@Qiuzhuang

This comment has been minimized.

Copy link

@Qiuzhuang Qiuzhuang commented Jan 8, 2018

+1 to replace '%%1' with '%1' for window 7

@hasibweb

This comment has been minimized.

Copy link

@hasibweb hasibweb commented Jan 13, 2018

It works on Windows10.
Thanks...

@hassaan-dev

This comment has been minimized.

Copy link

@hassaan-dev hassaan-dev commented Feb 21, 2018

How to remove the above changes?

@salarsoftdev

This comment has been minimized.

Copy link

@salarsoftdev salarsoftdev commented Mar 8, 2018

it worked for me too, thank you,

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Mar 9, 2018

Thanks!

@istvans

This comment has been minimized.

Copy link

@istvans istvans commented May 19, 2018

Perfect, thank you!

@audinue

This comment has been minimized.

Copy link

@audinue audinue commented Jun 1, 2018

Awesome! Thank you!

@arosha445

This comment has been minimized.

Copy link

@arosha445 arosha445 commented Jun 12, 2018

Work like a charm. Thanks!

@manjunathmayur

This comment has been minimized.

Copy link

@manjunathmayur manjunathmayur commented Jul 5, 2018

works great.
make sure that st2Path is set to installed directory if not installed in default directory

@jo2k

This comment has been minimized.

Copy link

@jo2k jo2k commented Aug 7, 2018

Works great for folders, didn't try the files part. Windows 10, Sublime Text 3.
However, I did have to edit the last line and remove an extra %

The last command for opening folders now looks like this:

@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st2Path% \"%1\"" /f
@sererejegede

This comment has been minimized.

Copy link

@sererejegede sererejegede commented Aug 9, 2018

Perfect!!

@roxxshivamsingh

This comment has been minimized.

Copy link

@roxxshivamsingh roxxshivamsingh commented Mar 20, 2019

Thanks dear u save my life!

@metabrez

This comment has been minimized.

Copy link

@metabrez metabrez commented Apr 21, 2019

The steps are as follows.
1.copy all the command above and paste in a notepad or notepad ++.
2.Save it as OpenWithSublime.bat on Desktop.
3.Right click on the OpenWithSublime.bat file.
4.Run as Administrator.
5.You are done.!!!

@YassineCharafi

This comment has been minimized.

Copy link

@YassineCharafi YassineCharafi commented Sep 17, 2019

Thank you sir :)

@shopnobaz

This comment has been minimized.

Copy link

@shopnobaz shopnobaz commented Jan 10, 2020

works like a charm . thank you :)

@icecodder

This comment has been minimized.

Copy link

@icecodder icecodder commented Mar 3, 2020

Perfect, thank you 👍

@Minecr4ck

This comment has been minimized.

Copy link

@Minecr4ck Minecr4ck commented Mar 8, 2020

Your awesome

@amandal1810

This comment has been minimized.

Copy link

@amandal1810 amandal1810 commented Jun 4, 2020

works flawlessly 😍
thanks!

@ask694

This comment has been minimized.

Copy link

@ask694 ask694 commented Jun 4, 2020

Works great Awesome dude..!!

@Sangram92

This comment has been minimized.

Copy link

@Sangram92 Sangram92 commented Jun 5, 2020

Thanks 👍

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jul 16, 2020

Curious why two windows open? One is the folder I'm opening thanks to this great .BAT file you published. The other window is the last folder I was working in when I closed Sublime.

@DanielLavoie90

This comment has been minimized.

Copy link

@DanielLavoie90 DanielLavoie90 commented Jul 18, 2020

I would suggest changing all the "HKEY_CLASSES_ROOT\Folder..." to "HKEY_CLASSES_ROOT\Directory..." instead.
With folder it add the context to some weird place like the recycle bin.

@DanielLavoie90

This comment has been minimized.

Copy link

@DanielLavoie90 DanielLavoie90 commented Jul 18, 2020

For those who wants to "add" to the current window instead of opening a new one juste add "-a"

@echo off
SET st2Path=C:\Program Files\Sublime Text 3\sublime_text.exe
 
rem add it for all file types
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3"         /t REG_SZ /v "" /d "Open with Sublime Text 3"   /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3"         /t REG_EXPAND_SZ /v "Icon" /d "%st2Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st2Path% -a \"%%1\"" /f
 
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 Text 3"   /f
@reg add "HKEY_CLASSES_ROOT\Directory\shell\Open with Sublime Text 3"         /t REG_EXPAND_SZ /v "Icon" /d "%st2Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\Directory\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st2Path% -a \"%%1\"" /f
pause

@rikusen0335

This comment has been minimized.

Copy link

@rikusen0335 rikusen0335 commented Oct 10, 2020

This gist still working! Thanks!

@Akshat-unt

This comment has been minimized.

Copy link

@Akshat-unt Akshat-unt commented Oct 12, 2020

It worked for me, win 10 !!!!!!!

@jfberrio

This comment has been minimized.

Copy link

@jfberrio jfberrio commented Nov 30, 2020

The steps are as follows.
1.copy all the command above and paste in a notepad or notepad ++.
2.Save it as OpenWithSublime.bat on Desktop.
3.Right click on the OpenWithSublime.bat file.
4.Run as Administrator.
5.You are done.!!!

'...paste in a "notepad or notepad ++"'.
And I was thinking these instructions are for Sublime users. Go figure.

@oledid

This comment has been minimized.

Copy link

@oledid oledid commented Dec 2, 2020

There's a regfile in the sublime text 3 install folder: install-context.reg, which is probably maintained. Maybe use that insted

@ryanmwakio

This comment has been minimized.

Copy link

@ryanmwakio ryanmwakio commented Oct 13, 2021

Awesome works like a charm....works even for sublime text 4, all you need is open the .bat file in the editor and point it to the sublime_text.exe which should be in the root of the installation folder.

@lautarojgarcia177

This comment has been minimized.

Copy link

@lautarojgarcia177 lautarojgarcia177 commented Nov 29, 2021

Worked like a charm :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment