Skip to content

Instantly share code, notes, and snippets.

@zouyang08
Forked from cstewart90/OpenWithSublimeText3.bat
Last active January 15, 2020 07:28
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save zouyang08/ba9bebb264260da8f17f778cc18d4c81 to your computer and use it in GitHub Desktop.
Save zouyang08/ba9bebb264260da8f17f778cc18d4c81 to your computer and use it in GitHub Desktop.
Open folders and files with Sublime Text 3 from windows explorer context menu (tested in Windows 10)
@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" /t REG_SZ /v "" /d "Open with Sublime Text" /f
@reg add "HKEY_CLASSES_ROOT\Directory\shell\Open with Sublime Text" /t REG_EXPAND_SZ /v "Icon" /d "%st3Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\Directory\shell\Open with Sublime Text\command" /t REG_SZ /v "" /d "%st3Path% \"%%1\"" /f
pause
@echo off
SET st3Path=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 "%st3Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st3Path% \"%%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 "%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_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime Text 3" /f
@reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\Open with Sublime Text 3" /t REG_EXPAND_SZ /v "Icon" /d "%st3Path%,0" /f
@reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st3Path% \"%%v\"" /f
pause
@JosephMainaDev
Copy link

Thank you. It works in Windows 10 X86.

@tascott
Copy link

tascott commented Sep 20, 2016

This is awesome, thank you (Y) (Windows 10 x86)

@d-d22
Copy link

d-d22 commented Feb 26, 2017

i don't fully understand. where do i paste this ??

@jacobmartinez3d
Copy link

jacobmartinez3d commented Aug 5, 2017

It's a .bat file so just copy-paste to a text file and save as something.bat (then right-click run as administrator). Or download zip using the link.

@Believe2Be
Copy link

How to delete it from the context menu plz?

@ahmedhamdy2121
Copy link

ahmedhamdy2121 commented Nov 27, 2017

@belive2be You can do so by replacing add with delete in the file and then run it again.

@llan-ml
Copy link

llan-ml commented Nov 28, 2017

@ahmedhamdy90 cannot delete it by replacing add with delete,
Hint: Error: Invalid syntax

@P450
Copy link

P450 commented Jun 9, 2018

@llan-ml
You can do it manually on regedit.

Or change relevant lines to:

rem delete it for all file types
@reg delete "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3" /f

rem delete it for folders
@reg delete "HKEY_CLASSES_ROOT\Directory\shell\Open with Sublime Text 3" /f

You get an invalid syntax error since options /d, /t , etc. don't exist for reg delete

For reference:

C:\Users\P450>reg delete /?

REG DELETE KeyName [/v ValueName | /ve | /va] [/f] [/reg:32 | /reg:64]

C:\Users\P450>reg add /?

REG ADD KeyName [/v ValueName | /ve] [/t Type] [/s Separator] [/d Data] [/f]
        [/reg:32 | /reg:64]

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