Logo

Contents:

  • 1. Introduction
    • 1.1. Getting Sublime Text
    • 1.2. Basics
      • 1.2.1. Terminology
      • 1.2.2. Starting Sublime Text
      • 1.2.3. User Interface
        • 1.2.3.1. Application
        • 1.2.3.2. Window
        • 1.2.3.3. Side Bar
        • 1.2.3.4. Editing Area
        • 1.2.3.5. View Group
        • 1.2.3.6. Window Layout
        • 1.2.3.7. Sheet
        • 1.2.3.8. View
        • 1.2.3.9. Buffer
        • 1.2.3.10. Panel
        • 1.2.3.11. Overlay
        • 1.2.3.12. Popup
        • 1.2.3.13. Menu
        • 1.2.3.14. Status Bar
        • 1.2.3.15. Run-Time Object Model
        • 1.2.3.16. Context Menus
        • 1.2.3.17. Viewport
        • 1.2.3.18. Key Bindings
        • 1.2.3.19. Scope
        • 1.2.3.20. Selector
        • 1.2.3.21. Context
        • 1.2.3.22. Commands
        • 1.2.3.23. Settings
        • 1.2.3.24. Project
        • 1.2.3.25. Completions
        • 1.2.3.26. Snippets
        • 1.2.3.27. Plugins
        • 1.2.3.28. Packages
        • 1.2.3.29. Data Directory
        • 1.2.3.30. Console Panel
      • 1.2.4. Path Syntax
      • 1.2.5. Sublime Python
      • 1.2.6. Sublime API
      • 1.2.7. JSON
    • 1.3. Additional Resources
      • 1.3.1. Documentation
      • 1.3.2. In-Application References
      • 1.3.3. Training Videos
      • 1.3.4. Sublime Text Community
      • 1.3.5. 3rd-Party Contributions, Examples, Etc.
  • 2. Editing
    • 2.1. Keyboard Editing
      • 2.1.1. Expanding the Selection
      • 2.1.2. Multiple Selections
        • 2.1.2.1. Arbitrary Positions
        • 2.1.2.2. Variable or Function Names
        • 2.1.2.3. Columns
        • 2.1.2.4. Selecting Columns
        • 2.1.2.5. Beginning/End of Line
        • 2.1.2.6. Lines and Words
        • 2.1.2.7. Find All (Power Feature)
        • 2.1.2.8. Bound Find All (Power Feature)
        • 2.1.2.9. Find All from Selected Text (Power Feature)
      • 2.1.3. Column Selection
      • 2.1.4. Navigation
        • 2.1.4.1. Goto Menu
        • 2.1.4.2. Goto Overlay
          • 2.1.4.2.1. Goto Overlay Operators
          • 2.1.4.2.2. Goto Overlay Special Key Combinations
      • 2.1.5. Bookmarks
      • 2.1.6. Using the Mark
        • 2.1.6.1. The Kill Ring
      • 2.1.7. Paste from History
      • 2.1.8. MarkerStack
        • 2.1.8.1. The Problem MarkerStack Solves
        • 2.1.8.2. Why MarkerStack is Better than Bookmarks for Interruptions
      • 2.1.9. Spell Checking
      • 2.1.10. Bracket-Type Key Behaviors
      • 2.1.11. Find and Replace
        • 2.1.11.1. Power Feature: Find All
          • 2.1.11.1.1. Find All from Selection
        • 2.1.11.2. Regular Expressions
        • 2.1.11.3. Find in Files, a.k.a. Recursive File Searching
          • 2.1.11.3.1. Accumulative Find Results
          • 2.1.11.3.2. Find-in-Files Replace Operation
        • 2.1.11.4. Leaving the Find Panel Open
        • 2.1.11.5. After the Find Panel Has Closed
      • 2.1.12. Side-by-Side Editing
        • 2.1.12.1. Two Views on Same File
          • 2.1.12.1.1. Keyboard Shortcut
        • 2.1.12.2. Two Views on Different Files
      • 2.1.13. Layouts
        • 2.1.13.1. window.set_layout() and Window’s set_layout Command Arguments
      • 2.1.14. Multi-Window Editing
      • 2.1.15. Macros
        • 2.1.15.1. Macro Files
      • 2.1.16. Further Reading
    • 2.2. Editing with the Mouse
      • 2.2.1. Mouse Features Covered Above
      • 2.2.2. Mouse Features Not Covered Above
    • 2.3. File Diffing
  • 3. Settings
  • 4. Projects
    • 4.1. Creating a New Project
    • 4.2. Project File Format
      • 4.2.1. “folders” Key
      • 4.2.2. “settings” Key
      • 4.2.3. “build_systems” Key
    • 4.3. Template Project File
  • 5. Commands
    • 5.1. Adding Existing Commands to Command Palette
      • 5.1.1. Variables Available in .sublime-commands Args
      • 5.1.2. Paths
    • 5.2. Further Reading
  • 6. Command List
    • 6.1. Default
      • 6.1.1. ApplicationCommand
      • 6.1.2. TextCommand
      • 6.1.3. WindowCommand
    • 6.2. A File Icon
      • 6.2.1. ApplicationCommand
    • 6.3. Diff
      • 6.3.1. TextCommand
      • 6.3.2. WindowCommand
    • 6.4. HTML
      • 6.4.1. TextCommand
    • 6.5. Package Control
      • 6.5.1. ApplicationCommand
      • 6.5.2. TextCommand
      • 6.5.3. WindowCommand
    • 6.6. User
      • 6.6.1. ApplicationCommand
      • 6.6.2. TextCommand
      • 6.6.3. WindowCommand
  • 7. Scope, Selectors and Context
    • 7.1. Scope
    • 7.2. Scope Name
    • 7.3. Selector
    • 7.4. Selector Match
    • 7.5. Logical Operators in Selectors
    • 7.6. Context
    • 7.7. API
  • 8. Key Bindings
    • 8.1. Recommended Key Binding Changes
    • 8.2. Keymap Files
    • 8.3. How Key Bindings are Chosen
      • 8.3.1. Keymap File Loading Order
    • 8.4. Multi-Keypress Bindings
    • 8.5. Key-Binding Definitions
      • 8.5.1. Keypress Lists
        • 8.5.1.1. Modifier Keys
          • 8.5.1.1.1. Windows Modifier Keys
          • 8.5.1.1.2. Linux Modifier Keys
          • 8.5.1.1.3. OSX Modifier Keys
        • 8.5.1.2. Main Key Names
      • 8.5.2. Command Names
      • 8.5.3. Args
        • 8.5.3.1. “Variables” in Args
      • 8.5.4. Contexts
        • 8.5.4.1. Context Condition Syntax
          • 8.5.4.1.1. Test Names
            • 8.5.4.1.1.1. Custom Test Names
          • 8.5.4.1.2. Operators
            • 8.5.4.1.2.1. Equality Operator Names
            • 8.5.4.1.2.2. Match Operator Names
          • 8.5.4.1.3. Operands (Values to Compare Against)
        • 8.5.4.2. Creating Custom Conditions
          • on_query_context()
    • 8.6. Blocking a Key Binding
    • 8.7. Diagnosing Binding Problems
    • 8.8. Key Binding Conflicts
      • 8.8.1. Terminology
      • 8.8.2. Overview
      • 8.8.3. What Is a Key-Binding Conflict?
        • 8.8.3.1. Details
      • 8.8.4. Single- vs Multi-Keypress Bindings
      • 8.8.5. Detecting Potentially-Conflicting Key Bindings
      • 8.8.6. User Experience Considerations
      • 8.8.7. Detecting the Problem Presented in the Overview
  • 9. Default Key Bindings
    • 9.1. Default Key Bindings (Windows)
      • 9.1.1. Number Keys
      • 9.1.2. Letter Keys
      • 9.1.3. Function Keys
      • 9.1.4. Symbol Keys
      • 9.1.5. Named Keys
        • 9.1.5.1. Tab Key
        • 9.1.5.2. Shift Tab
      • 9.1.6. Keypad Keys
      • 9.1.7. Leading Key: Ctrl-J
      • 9.1.8. Leading Key: Ctrl-K
    • 9.2. Default Key Bindings (Linux)
      • 9.2.1. Number Keys
      • 9.2.2. Letter Keys
      • 9.2.3. Function Keys
      • 9.2.4. Symbol Keys
      • 9.2.5. Named Keys
      • 9.2.6. Keypad Keys
      • 9.2.7. Leading Key: Ctrl-J
      • 9.2.8. Leading Key: Ctrl-K
    • 9.3. Default Key Bindings (OSX)
      • 9.3.1. Number Keys
      • 9.3.2. Letter Keys
      • 9.3.3. Function Keys
      • 9.3.4. Symbol Keys
      • 9.3.5. Named Keys
      • 9.3.6. Keypad Keys
      • 9.3.7. Leading Key: Command-J
      • 9.3.8. Leading Key: Command-K
  • 10. Mouse Bindings
  • 11. Default Mouse Bindings
  • 12. Menus
    • 12.1. Customizing Menus
    • 12.2. Menu-Item Structure
    • 12.3. Adding to Existing Sub-Menus
    • 12.4. Dynamically Changing Menu Items
    • 12.5. Customizing Existing Menu Items
    • 12.6. Controlling Menu Item Locations in Existing Menus
    • 12.7. Side Bar “Magic”
    • 12.8. Other Context Menu “Magic”
    • 12.9. Lastly
    • 12.10. Further Reading
  • 13. Completions
    • 13.1. Using Completions
    • 13.2. Creating Your Own Completions
    • 13.3. Completions File Format
      • 13.3.1. Trigger
      • 13.3.2. Contents
      • 13.3.3. Kind
      • 13.3.4. Annotation
      • 13.3.5. Details
      • 13.3.6. Example
    • 13.4. Implementing Completions in a Plugin
    • 13.5. Further Reading
  • 14. Snippets
    • 14.1. Snippets vs Completions
    • 14.2. Snippet Files
    • 14.3. Smart-Template Syntax
      • 14.3.1. Literal “$”
      • 14.3.2. Fields
        • 14.3.2.1. Default Text
      • 14.3.3. Predefined Variables
      • 14.3.4. Combining Form Fields with Variables
      • 14.3.5. The insert_snippet Command
        • 14.3.5.1. insert_snippet Arguments
      • 14.3.6. Custom Variables
      • 14.3.7. Substitutions
    • 14.4. Creating Snippets
    • 14.5. Finding Snippets
    • 14.6. Further Reading
  • 15. Build Systems
    • 15.1. Selecting a Build System
    • 15.2. Launching a Build
    • 15.3. Navigating Among Results
    • 15.4. Creating Your Own Build System
      • 15.4.1. Variables
    • 15.5. Further Reading
  • 16. Plugins
    • 16.1. Creating Commands
      • 16.1.1. Text Commands
        • 16.1.1.1. Types of Views
      • 16.1.2. Window Commands
      • 16.1.3. Application Commands
      • 16.1.4. All Commands
    • 16.2. Other Command Methods
      • 16.2.1. Inherited Methods
    • 16.3. More on Text Commands
      • 16.3.1. Some Data Types You Need to Know About
      • 16.3.2. What Happens Inside the run() Method
        • 16.3.2.1. Editing the Buffer
        • 16.3.2.2. Change Position of Caret
        • 16.3.2.3. Rows and Columns
        • 16.3.2.4. Finding New Region(s)
          • 16.3.2.4.1. sublime.FindFlags
          • 16.3.2.4.2. view.find()
          • 16.3.2.4.3. view.find_all()
          • 16.3.2.4.4. view.find_by_selector()
        • 16.3.2.5. Running Other Commands
      • 16.3.3. Further Reading
    • 16.4. Adding Python Packages
      • 16.4.1. Further Reading
    • 16.5. Example Basic Plugin with Package Settings
    • 16.6. Generating Reports
  • 17. Packages
    • 17.1. Sublime Text Packages vs Python Packages
    • 17.2. Locations
    • 17.3. Overriding
      • 17.3.1. Overriding Whole Files from a Zipped Package
    • 17.4. Creating a New Package
      • 17.4.1. Python Version
      • 17.4.2. Managing Complexity
        • 17.4.2.1. Caveat for Subpackages
    • 17.5. Sharing Your Package
      • 17.5.1. Package Distribution
        • 17.5.1.1. Distribution Data Tree
        • 17.5.1.2. Flow of Package Data
        • 17.5.1.3. Version Tag
        • 17.5.1.4. Current State of Package Control
        • 17.5.1.5. More About Package Control
    • 17.6. Further Reading
  • 18. Input Handlers
    • 18.1. Flow of Execution
      • 18.1.1. TextInputHandler
      • 18.1.2. ListInputHandlers
      • 18.1.3. Example
  • 19. Event Listeners
    • 19.1. Creating an Event Listener
    • 19.2. Example
    • 19.3. Notes on on_query_context()
  • 20. Event list
    • 20.1. EventListener
      • EventListener.on_init()
      • EventListener.on_exit()
      • EventListener.on_new()
      • EventListener.on_new_async()
      • EventListener.on_associate_buffer()
      • EventListener.on_associate_buffer_async()
      • EventListener.on_clone()
      • EventListener.on_clone_async()
      • EventListener.on_load()
      • EventListener.on_load_async()
      • EventListener.on_reload()
      • EventListener.on_reload_async()
      • EventListener.on_revert()
      • EventListener.on_revert_async()
      • EventListener.on_pre_move()
      • EventListener.on_post_move()
      • EventListener.on_post_move_async()
      • EventListener.on_pre_close()
      • EventListener.on_close()
      • EventListener.on_pre_save()
      • EventListener.on_pre_save_async()
      • EventListener.on_post_save()
      • EventListener.on_post_save_async()
      • EventListener.on_modified()
      • EventListener.on_modified_async()
      • EventListener.on_selection_modified()
      • EventListener.on_selection_modified_async()
      • EventListener.on_activated()
      • EventListener.on_activated_async()
      • EventListener.on_deactivated()
      • EventListener.on_deactivated_async()
      • EventListener.on_hover()
      • EventListener.on_query_context()
      • EventListener.on_query_completions()
      • EventListener.on_text_command()
      • EventListener.on_window_command()
      • EventListener.on_post_text_command()
      • EventListener.on_post_window_command()
      • EventListener.on_new_window()
      • EventListener.on_new_window_async()
      • EventListener.on_pre_close_window()
      • EventListener.on_new_project()
      • EventListener.on_new_project_async()
      • EventListener.on_load_project()
      • EventListener.on_load_project_async()
      • EventListener.on_pre_save_project()
      • EventListener.on_post_save_project()
      • EventListener.on_post_save_project_async()
      • EventListener.on_pre_close_project()
    • 20.2. ViewEventListener
      • ViewEventListener.on_load()
      • ViewEventListener.on_load_async()
      • ViewEventListener.on_reload()
      • ViewEventListener.on_reload_async()
      • ViewEventListener.on_revert()
      • ViewEventListener.on_revert_async()
      • ViewEventListener.on_pre_move()
      • ViewEventListener.on_post_move()
      • ViewEventListener.on_post_move_async()
      • ViewEventListener.on_pre_close()
      • ViewEventListener.on_close()
      • ViewEventListener.on_pre_save()
      • ViewEventListener.on_pre_save_async()
      • ViewEventListener.on_post_save()
      • ViewEventListener.on_post_save_async()
      • ViewEventListener.on_modified()
      • ViewEventListener.on_modified_async()
      • ViewEventListener.on_selection_modified()
      • ViewEventListener.on_selection_modified_async()
      • ViewEventListener.on_activated()
      • ViewEventListener.on_activated_async()
      • ViewEventListener.on_deactivated()
      • ViewEventListener.on_deactivated_async()
      • ViewEventListener.on_hover()
      • ViewEventListener.on_query_context()
      • ViewEventListener.on_query_completions()
      • ViewEventListener.on_text_command()
      • ViewEventListener.on_post_text_command()
    • 20.3. TextChangeListener
      • TextEventListener.on_text_changed()
      • TextEventListener.on_text_changed_async()
      • TextEventListener.on_revert()
      • TextEventListener.on_revert_async()
      • TextEventListener.on_reload()
      • TextEventListener.on_reload_async()
  • 21. Dialog Boxes and User Messaging
  • 22. Clipboard Utilities Available to Plugins
  • 23. View Settings List Example
  • 24. Paths
  • 25. Popups
  • 26. Phantoms
  • 27. Viewport
    • 27.1. What Is a View’s Viewport?
    • 27.2. Viewport Terminology
    • 27.3. Enhanced Viewport API
    • 27.4. Example
  • 28. Color Schemes
  • 29. Themes
  • 30. Indexing
  • 31. Glossary
  • 32. Troubleshooting
    • 32.1. Safe Mode
    • 32.2. Diagnosing Trouble from the Data Directory
      • 32.2.1. Diagnosis by Isolating Packages
      • 32.2.2. Diagnosis by Isolating Customizations
  • 33. Notes
    • 33.1. Features I Would Like
Sublime Text QuickRef
  • 12. Menus
  • View page source
Previous Next

12. Menus

Sublime Text has a number of different menus. All of them can be customized.

The Main Menu is the row of click-able words just under each Window’s Title Bar. The Main Menu’s default definition can be found in the Default Package’s Main.sublime-menu file.

Context Menus are a pop-up menus that open as a result of right-clicking any of several objects in the Sublime Text GUI. (Some keyboards also have the ability to open Context Menus.)

The objects in Sublime Text that can host a Context Menu are (Context Menu names are in parentheses):

  • Sheets

    • Views (Context)

    • Images (Image Context)

    • Tabs (Tab Context)

  • Side Bar

    • OPEN FILES list (Tab Sidebar Context)

    • FOLDERS

      • Mount Points (Side Bar Mount Point)

      • Folders and Files, possible multiple items selected (Side Bar)

  • Status Bar

    • Encoding Status (Encoding)

    • Line Ending Status (Line Endings)

    • Indentation Status (Indentation)

    • Current Syntax Status (Syntax)

  • Panels

    • Console (Console Input Widget)

    • Find-in-Files Panel (Find in Files)

    • Other input panels (Widget Context)

Each Menu’s content can be found (and customized) in Package Resource files named:

<menu_name>.sublime-menu

The default version of these are in the Default Package, and customizations of these can be found in various other Packages.

To view them: Tools ‣ Command Palette ‣ View Package File: and type in “sublime-menu”. This will display a list of all menu resource files known to Sublime Text.

All of these menus are customizable, but how to do so is neither intuitive, nor is it per the current documentation (or at minimum the current documentation on it is unclear). Here’s how to do it.

12.1. Customizing Menus

If you haven’t already done so, go ahead and open Sublime Text’s default main menu:

Tools ‣ Command Palette ‣ View Package File > type “sublime-menu Main”

to select it, and hit Enter to open it.

Notice that it is read only. Also notice that it “appears” to be in the folder

<data_path>/Packages/Default/`

but if you look on your file system, you will find that there is no such directory! That’s because Sublime Text uses that file from

<executable_path>/Packages/Default.sublime-package

which contains that file internally and shows it to you as if it was in the <data_path>/Packages/Default/` directory. You can both copy text from it into the clipboard as well as perform a File ‣ Save As... on it if you want it somewhere on your file system, perhaps so you can do searches on it (and other menus) using Find-in-Files. (Note you will have to close it and re-open it to remove the “read-only” state of the View.)

If you want to OVERRIDE that menu completely, you can simply do a File ‣ Save, and it will save it in <data_path>/pkg_name/ directory, creating the directory if necessary to do so. Beware of doing this however: it will forever after override the entire menu file in the parent Package, including if it is the Default Package, which would prevent updates to that menu file with subsequent updates to Sublime Text.

To customize any of these menus, like many other customization actions for Sublime Text, you must create a valid JSON file in your <data_path>/Packages/User/` directory (or a directory for the applicable Package) using the EXACT same file name. Example: Main.sublime-menu. If you use any other file name, Sublime Text ignores it, since the file name is how Sublime Text tells what menu you are adding to or modifying.

Once your file is there, you simply add the parts of the menu that you want to add or change. The top-level is always a JSON array object, and its elements are Menu Item JSON objects with the structure shown below.

For context menus (menus that pop-up when you right-click something), whatever menu-item objects you create in your JSON file simply gets added to the bottom of the context menu. For the main menu, however, the structure is a little different:

  • you only need to include menu items that you want to add, but

  • you have to match both the STRUCTURE and the SEQUENCE in the default Main.sublime-menu file, or else Sublime Text will silently not show them.

12.2. Menu-Item Structure

Menus in Sublime Text are defined by files ending in .sublime-menu. As noted above, the filename must exactly match the default filename of the menu you are modifying, and be stored in your <data_path>/Packages/User/ directory. Menus use JSONC format, with the top-level structure being an array. Each contained object in the array is a “Menu Item”: a JSON object containing information to define the text and behaviors of the displayed menu entry.

Example:

[
    {
        "caption": "File",
        "mnemonic": "F",
        "id": "file",
        "children":
        [
            { "command": "new_file", "caption": "New File", "mnemonic": "N" },

            { "command": "prompt_open_file", "caption": "Open File…", "mnemonic": "O", "platform": "!OSX" },
            { "command": "prompt_open_folder", "caption": "Open Folder…", "platform": "!OSX" },
            { "command": "prompt_open", "caption": "Open…", "platform": "OSX" }
        ]
    }
]

As you can see, Menu Items can be nested in a tree structure. To carry out an action, “leaf” Menu Items contain “command” elements that lead to commands that Sublime Text knows about. (You can create new commands using Plugins.) If Sublime Text doesn’t know about them, they will be disabled (grayed out).

Supported keys:

“caption”:

The text of the menu entry.

“mnemonic”:

The character to use as the key to press to activate the entry. This only applies to Windows and Linux. Must match the case of the character in the “caption”.

“command”:

A string of the command to execute when the entry is activated.

“args”:

A JSON object of args to send to the command.

“children”:

A JSON array of Menu-Item objects, which, when not empty, creates a submenu.

“id”:

A unique string for the menu entry. This is used for menu entries with “children” to allow others to add additional child entries.

“platform”:

One of the strings: “OSX”, “!OSX”, “Windows”, “!Windows”, “Linux” or “!Linux”. Controls what platforms the entry is shown on.

Each menu entry requires at minimum, the key “caption” for a non-functionality entry. “command” is required for an entry that performs an action.

Menu Items that have a caption value of “-” will be shown as a divider in the menu.

12.3. Adding to Existing Sub-Menus

To add to an existing sub-menu, you have to “build out” the existing structure using “empty” menu items. To build an “empty” menu item, simply create its structure with the existing “id” key with matching value, and include a “children” element with an array.

Important:

The structure you build has to match both the SEQUENCE and the STRUCTURE of the Main Menu. If you don’t, Sublime Text will silently not show it, and won’t say why.

There is one exception to this: if you create a top-level Menu Item, it will be shown on the right side of the normal (default) top-level Menu Items, no matter where you put it in the structure (so long as it is a top-level Menu Item). It’s probably best to put it last (to match the shown structure) in case the Sublime Text developers decide to change or restrict that behavior.

Example to add to the Preferences ‣ Package Settings sub-menu:

{
    "id": "preferences",
    "children":
    [
        {
            "id": "package-settings",
            "children":
            [
                {
                    "caption": "Your Package Name",
                    "children":
                    [
                        {
                            "caption": "Documentation",
                            "command": "open_url",
                            "args": {
                                "url": "https://your-site.com/YourPackage/"
                            }
                        },

                        { "caption": "-" },

                        {
                            "caption": "Settings",
                            "command": "edit_settings",
                            "args": {
                                "base_file": "${packages}/YourPackage/YourPackage.sublime-settings",
                                "default": "{\n\t$0\n}\n"
                            }
                        },

                        { "caption": "-" },

                        {
                            "caption": "Key Bindings",
                            "command": "edit_settings",
                            "args": {
                                "base_file": "${packages}/YourPackage/Default ($platform).sublime-keymap",
                                "default": "[\n\t$0\n]\n"
                            }
                        },
                    ]
                }
            ]
        }
    ]
},

12.4. Dynamically Changing Menu Items

Dynamic Menu-Item state can be implemented by overriding certain inherited methods in the Command class the menu item is associated with (in whatever Plugin implements it). Command arguments beyond self are passed as keyword arguments.

Action

Method to Override

Inherited Value

disabling Menu Item

is_enabled(self) returning False [1]

True

hiding Menu Item

is_visible(self) returning False

True

adding a check mark

is_checked(self) returning True [2]

False

changing its caption

description(self) returning caption string [3]

empty string

[1]

Menu Items are also disabled when the Command is associated with a Key Binding, and the Key Binding’s Selector evaluates to False.

[2]

This requires "checkbox": true be one of the entries in the JSON menu item object in the .sublime-menu file.

[3]

In order for the description(self) method to have an effect, the Menu Item object in the .sublime-menu file must either: A) have a “caption” entry that provides an empty string, or B) have no “caption” entry.

12.5. Customizing Existing Menu Items

Looking at Tools ‣ Command Palette ‣ View Package File ‣ Default/Main.sublime-menu you will note that some menu items have an "id" entry. These menu items can be referenced later in order to change them or add to their children. If a menu item does not have this "id" entry, it is not customizable.

Given the above-mentioned restrictions about having to match both the STRUCTURE and the SEQUENCE in the default Main.sublime-menu file, specifying the menu item’s "id" exactly allows you to edit its other properties, including caption, mnemonic and children. [4]

[4]

The limitation with children is that you can only ADD to Sublime Text’s existing menu items. You cannot change them unless they have an associated ID. The only way around this is to save the entire default (or Package) menu file in the Override Package. This practice is generally not recommended for the Default/Main.sublime-menu file because when Sublime Text is updated, it would continue to override the main menu file such that new or modified menu items would not appear.

12.6. Controlling Menu Item Locations in Existing Menus

Generally, when creating new menu items, you reference the existing parent menu by its "id" value (recreating the structure and sequence of the menu tree as covered above) and then create a single “children” entry with a list. Whatever you put in this list gets generally added at the bottom of the menu. This is normally what you want.

In extreme cases, however, you may wish to change the meaning of existing menu items that do not have an "id" entry or remove menu items, etc.. To do this, you Tools ‣ Command Palette ‣ View Package File ‣ <pkg_name>/<menu_name>.sublime-menu and then File ‣ Save in order to save it in an Override Package under the <data_path> directory. You will need to close the file and re-open it to remove the “read-only” attribute of the View. At this point, the entire menu can be modified.

This practice is generally not recommended for menu files, however, because when the source Package gets updated, an updated menu file in that Package would continue to be overridden by your file. So the recommended practice is to create a User/<menu_name>.sublime-menu file so that it ADDS to existing menus instead, thus not blocking menu updates by the Package author.

12.7. Side Bar “Magic”

If you add your own Menu Items to the Side Bar context menu, you will want to know that you can use certain arguments with your commands:

“files”: []:

If your command has a files argument, it will receive an array containing the full path of each file that was selected when the right-click was performed.

“dirs”: []:

If your command has a dirs argument, it will receive an array containing the full path of each directory that was selected when the right-click was performed.

“paths”: []:

If your command has a paths argument, it will receive an array containing the full path of each file and directory that was selected when the right-click was performed.

12.8. Other Context Menu “Magic”

For all other context menus, calling the command copy_path will receive the full path of the file in the current View (or None if its Buffer is not stored on disk).

Example:

[
    {
        "caption": "Your Copy Path",
        "command": "copy_path"
    }
]

12.9. Lastly

In case you were not already aware, it is customary (though not required) to add an ellipsis (“...”) to captions whose commands launch a dialog box or open a panel to get information before the command is carried out. That helps the user know that when he clicks Menu Items that do not have this, to expect that the command will be carried out immediately, whereas with Menu Items with the “...”, he can expect some type of intermediate dialog box or panel to show up first before any action is taken.

12.10. Further Reading

See https://www.sublimetext.com/docs/menus.html and https://docs.sublimetext.io/reference/menus.html for more details.

Previous Next

© Copyright 2025-2026 WGA Crystal Research, Inc. All rights reserved. Last updated on 15-May-2026.

Built with Sphinx using a theme provided by Read the Docs.