34

In Windows 7, I can do this at the command line:

"c:\Program Files\Sublime Text 2\sublime_text.exe" samplefolder

This launches a Sublime Text window, with the contents of samplefolder loaded in Sublime's sidebar.

While this works as needed, it's inconvenient to open a command prompt every single time. Is there any way I can add this behavior to Windows Explorer's right-click menu? I'd like to be able to right-click a folder and "Open with Sublime" just like I can right-click a folder and "Scan for viruses".

5 Answers5

48

This is my .reg file for Vim, but it's quite clear, just replace Vim related string with Sublime's. Then save as .reg file and double click to import.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\vim]
@="&Vim here"

[HKEY_CLASSES_ROOT\Directory\shell\vim\command]
@="\"C:\\Program Files (x86)\\Vim\\vim73\\gvim.exe\" \"%1\""

[HKEY_CLASSES_ROOT\Directory\Background\shell\vim]
@="&Vim here"

[HKEY_CLASSES_ROOT\Directory\Background\shell\vim\command]
@="\"C:\\Program Files (x86)\\Vim\\vim73\\gvim.exe\" \"%V\""

There are two folder context menu, one is direct right click on folder, that's the first two lines, and another one is in folder empty area right click, that's the last two lines. I don't know what did the last %V mean, and haven't found anything related, it just works.

Edit:

For default installation of Sublime Text 2 on Windows 7, here is the full code. Save as whatever.reg and double-click.

Windows Registry Editor Version 5.00

; This will make it appear when you right click ON a folder
; The "Icon" line can be removed if you don't want the icon to appear

[HKEY_CLASSES_ROOT\Directory\shell\sublime]
@="Open Folder as &Sublime Project"
"Icon"="\"C:\\Program Files\\Sublime Text 2\\sublime_text.exe\",0"

[HKEY_CLASSES_ROOT\Directory\shell\sublime\command]
@="\"C:\\Program Files\\Sublime Text 2\\sublime_text.exe\" \"%1\""


; This will make it appear when you right click INSIDE a folder
; The "Icon" line can be removed if you don't want the icon to appear

[HKEY_CLASSES_ROOT\Directory\Background\shell\sublime]
@="Open Folder as &Sublime Project"
"Icon"="\"C:\\Program Files\\Sublime Text 2\\sublime_text.exe\",0"

[HKEY_CLASSES_ROOT\Directory\Background\shell\sublime\command]
@="\"C:\\Program Files\\Sublime Text 2\\sublime_text.exe\" \"%V\""
Mengdi Gao
  • 1,324
1

I found a super solution posted on github gist by Jethro Yu

Installation instructions:

  • Download the OpenWithSublimeTextAsAdmin.bat file in that gist.
  • Copy it into your Sublime Edit installation folder (typically C:\Program files\Sublime Text 3 or similar)
  • Run it.

Features:

  • Super easy installation.
  • Open files with Sublime Text
  • Open files with elevated privileges with Sublime Text. This is particularly handy when you want to edit i.e. system files.
  • Open folders with Sublime Text
Spiralis
  • 181
0

This is what I do

I install Notepad Replacer and point that to my sublime_text.exe (or any other text editor).

I then add the 'Open with Notepad' Registry setting (copy and paste the following into a .reg file and double click to apply it.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Open with Notepad]

[HKEY_CLASSES_ROOT\*\shell\Open with Notepad\command]
@="notepad.exe %1"

What Notepad Replacer does is replaces any command (system wide) to open notepad.exe to open the text editor that you specified in the install (in this case sublime_text.exe).

If you uninstall Notepad Replacer or re-install it pointing to a different text editor, your 'Open with Notepad' context menu will still work with the new default text editor!

Jon Erickson
  • 2,344
0
@echo off
@reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\Sublime Text 2" /t REG_EXPAND_SZ /v "Icon" /d "\"%~dp0sublime_text.exe\",0" /f
@reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\Sublime Text 2\command" /t REG_EXPAND_SZ /v "" /d "\"%~dp0sublime_text.exe\" \"%%1\"" /f
pause

how to use

new a *.bat file

ruanjf
  • 1
-1

You should be able to just open regedit.exe and browse to:

HKEY_CLASSES_ROOT*\shell

Right-click on "shell" and choose to create a new key, calling it "Open with Sublime Text".

Create a new key below that one called "command".

Double-click on the (Default) value in the right-hand pane and enter in the following:

[sublime text .exe name] %1

hardlywired
  • 122
  • 6