[sublime text] add sublime text to context menu 右键菜单中添加“Open with Sublime Text”
Google Gemini生成
推荐方法:
对于windows用户,可以直接使用batch script来实现
添加到右键菜单
@echo off :: Set your variables here SET "APP_PATH=C:\Program Files\Sublime Text\sublime_text.exe" SET "TITLE=Open with Sublime Text" :: 1. Add to File Context Menu reg add "HKEY_CLASSES_ROOT\*\shell\%TITLE%" /v "Icon" /t REG_SZ /d "\"%APP_PATH%\"" /f reg add "HKEY_CLASSES_ROOT\*\shell\%TITLE%\command" /t REG_SZ /d "\"%APP_PATH%\" \"%%1\"" /f :: 2. Add to Folder Context Menu reg add "HKEY_CLASSES_ROOT\Directory\shell\%TITLE%" /v "Icon" /t REG_SZ /d "\"%APP_PATH%\"" /f reg add "HKEY_CLASSES_ROOT\Directory\shell\%TITLE%\command" /t REG_SZ /d "\"%APP_PATH%\" \"%%1\"" /f :: 3. Add to Background Context Menu (Right-click inside a folder) reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\%TITLE%" /v "Icon" /t REG_SZ /d "\"%APP_PATH%\"" /f reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\%TITLE%\command" /t REG_SZ /d "\"%APP_PATH%\" \"%%V\"" /f echo Finished! Context menu items added. pause
如何删除呢?
@echo off SET "TITLE=Open with Sublime Text" :: Delete from File, Folder, and Background reg delete "HKEY_CLASSES_ROOT\*\shell\%TITLE%" /f reg delete "HKEY_CLASSES_ROOT\Directory\shell\%TITLE%" /f reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\%TITLE%" /f echo %TITLE% has been removed from the context menu. pause
如果想用GUI的方法,请往下看:
Adding Sublime Text to your right-click (context) menu makes opening files and folders much faster. The process differs depending on whether you are using Windows or macOS.
For Windows Users
If you didn't check the "Add to explorer context menu" box during the initial installation, you can add it manually via the Registry Editor.
-
Press
Win + R, type regedit, and hit Enter. -
Navigate to:
HKEY_CLASSES_ROOT\*\shell -
Right-click on shell and select New > Key. Name it
Open with Sublime Text. -
(Optional) To add an icon: Right-click the new key, select New > String Value, name it
Icon, and set its value to the path of yoursublime_text.exe(usuallyC:\Program Files\Sublime Text\sublime_text.exe). -
Right-click your
Open with Sublime Textkey and select New > Key. Name this onecommand. -
Double-click the (Default) value inside the command folder and paste the following (including quotes):
"C:\Program Files\Sublime Text\sublime_text.exe" "%1"
For macOS Users
macOS doesn't use a registry; instead, you can create a "Quick Action" using Automator.
-
Open Automator from your Applications folder.
-
Select Quick Action as the document type.
-
At the top, set "Workflow receives current" to files or folders in Finder.
-
Search for the Open Finder Items action and drag it to the workflow area on the right.
-
In the "Open with" dropdown, select Sublime Text.
-
Go to File > Save and name it "Open in Sublime Text".
Now, when you right-click a file in Finder, you will see "Open in Sublime Text" under the Quick Actions menu.
For Linux Users (Ubuntu/Gnome)
If you use Nautilus, you can add a script to the scripts folder:
-
Navigate to
~/.local/share/nautilus/scripts. -
Create a new file named
Open in Sublime. -
Paste the following into the file:
Bash#!/bin/bash subl "$@" -
Make the file executable:
chmod +x "Open in Sublime".
Would you like me to walk you through how to add the "Open Folder as Project" option specifically for Windows?

浙公网安备 33010602011771号