Sublime Text Community Documentation

repository·master·Indexed 42 days ago

https://github.com/sublimetext-io/docs.sublimetext.io

Community-driven documentation designed to supplement the official Sublime Text guides. Includes detailed instructions on customizing color schemes, key bindings, menus via .sublime-menu files, and managing the .sublime-settings hierarchy and precedence.

Tokens
53.2K
Snippets
132
Records
275
Agent score
53%

What's inside Sublime Text

  1. Explore the Sublime Text Community Documentation

    master

    The Sublime Text Community Documentation provides supplemental resources for the Sublime Text editor. You can navigate the documentation through three primary sections:

    • The Guide: Covers basic information, usage, and customization of Sublime Text.
    • The Reference: Provides technical details on structuring custom key bindings and disabling menu items for plugins.
    • The Glossary: Defines terms used throughout the documentation to help clarify technical concepts.
  2. How command dispatching works in Sublime Text

    master

    Commands in Sublime Text are typically bound to one of three objects: the application object, a window object, or a view object.

    When calling commands on a window object, the window will automatically dispatch the command based on the current input focus. This means you can issue a command intended for a specific view through the window object, and Sublime Text will resolve the correct view instance for you.

  3. Understand Legacy Syntax Definitions (.tmLanguage)

    master

    Legacy syntax definitions in Sublime Text use the .tmLanguage format (inherited from TextMate). These are technically Plist files, though YAML is often used for readability in documentation.

    Note: For new projects, it is highly recommended to use the newer .sublime-syntax format introduced in Sublime Text 3.0 (Build 3084) instead of this legacy format.

    Sublime Text also supports .hidden-tmLanguage files, which are used by plugins (like "Find in Files") and cannot be manually selected by users or included via import statements.

  4. Define package metadata using `details`

    master

    For packages hosted on GitHub, Bitbucket, or GitLab, you can provide a details URL. Package Control will automatically retrieve most properties from this URL.

    Note: For package submissions to the default repository, details must always be provided.

    You can override any property retrieved from details by setting it explicitly in the package object. Supported override properties include:

    • name: If the package name differs from the Git repository name.
    • author: A string or array of strings (if different from the Git owner).
    • description: If different from the Git repository description.
    • readme: A URL to the raw source of the README file.
    • issues: A URL to a different bug tracker.
    • homepage: A project website URL.
    • donate: A URL for user donations.
    • buy: A URL for commercial packages.
    • previous_names: Used to redirect existing installations during a rename.
    • labels: Tags to help users find the package.
    {
    	"packages": [
    		{
    			"name": "Solarized Color Scheme",
    			"details": "https://github.com/braver/Solarized",
    			"homepage": "https://ethanschoonover.com/solarized/",
    			"donate": "https://paypal.me/koenlageveen",
    			"labels": ["color scheme"],
    			"releases": [
    				{
    					"sublime_text": ">=3000",
    					"tags": true
    				}
    			]
    		}
    	]
    }
  5. Understand the Package Control channel.json structure

    master

    The channel.json file is a compiled manifest used by the Package Control client in Sublime Text to discover and install packages and libraries. It is generated by a crawler that visits registered repositories and resolves metadata for all available packages and libraries.

    A standard channel.json file includes the following top-level properties:

    • $schema: Used by LSP and LSP-json for linting and completions.
    • schema_version: The version of the file format (current latest is 4.0.0).
    • repositories: An array of locations to fetch package metadata.
    • packages_cache: A performance-optimized cache of package data.
    • libraries_cache: A performance-optimized cache of library data.
    {
        "$schema": "sublime://packagecontrol.io/schemas/channel",
        "schema_version": "4.0.0",
        "repositories": [],
        "packages_cache": {},
        "libraries_cache": {}
    }
  6. Use regular expressions for complex searches

    master

    Sublime Text supports regular expressions (regex) to find complex patterns in text. To use them, you must explicitly toggle the regular expression mode in the search or replace panel (using <Key k="alt+r" />).

    Sublime Text uses the Perl Compatible Regular Expressions (PCRE) engine from the Boost library.

    Note on Format Strings: Sublime Text additionally interprets \{n} as ${n}.

    (?:Sw|P)i(?:tch|s{2})\s(?:it\s)?of{2}!
  7. How Projects work in Sublime Text

    master

    Projects are used to group sets of files and folders to keep your work organized. They enable project-specific settings, build systems, and allow for quick switching between different work contexts.

    Key concepts:

    • Anonymous Projects: When no project is opened, you are working in an 'anonymous project'. This has limited functionality and is the default state for new windows.
    • Project Files: Project metadata is stored in .sublime-project JSON files. It is generally safe to commit these to source control.
    • Navigation: Adding folders to a project is required for features like Goto Anything and project-wide Goto Definition to function correctly.
  8. How recursion works with $self in Syntax Definitions

    master

    To handle nested structures (like a complex field that can contain other fields), use the include key within a patterns array inside a begin-end rule.

    By setting include: $self, you tell Sublime Text to recursively apply the entire current syntax definition to the text captured between the begin and end markers. This allows for infinite nesting of the defined rules, provided the regexes are not overly greedy.

    # Inside a begin-end rule's patterns array:
    - include: $self
  9. Understand Sublime Text package locations and types

    master

    Sublime Text uses different directories to store packages depending on their purpose and how they are distributed:

    • Shipped Packages (Application/Packages): Default packages provided by Sublime Text. This folder should not be modified manually. Includes core packages (required for functionality, e.g., Default, Theme - Default) and other language support packages.
    • Installed Packages (Data/Installed Packages): Contains .sublime-package zip archives, typically managed by a package manager like Package Control. These are considered read-only.
    • User Packages (Data/Packages): Folders created by users to extend functionality. This includes:
      • Standard User Packages: Folded under Data/Packages.
      • Override Packages: Folders under Data/Packages named identically to a .sublime-package (minus the extension) used to customize read-only archives.
      • User Settings: Located in Packages/User.

    Precedence Rules

    If multiple packages share the same name or files, Sublime Text follows this priority:

    1. Any file in a Packages/PackageName folder takes precedence over an identically named file in an Installed Packages/PackageName.sublime-package or a shipped package.
    2. If a package exists in both Installed Packages and Shipped Packages, the one in Installed Packages is used.

    Typical package resources include .sublime-build, .sublime-color-scheme, .sublime-keymap, .py (plugins), .sublime-settings, and .sublime-syntax.

  10. What are Input Handlers?

    master

    Input Handlers are a mechanism to query a user for one or multiple input parameters via the Command Palette. They provide a unified user experience, replacing the older Window.show_input_panel and Window.show_quick_panel methods.

    There are two primary kinds of input handlers:

    1. Text input handlers: Accept arbitrary text input and forward the entered text to the command.
    2. List input handlers: Provide a list of options for the user to choose from. These can handle any JSON-serializable value, accompanied by a caption for the list entry.

    Note: To use an input handler for a command, the command must have an entry in the Command Palette (via a .sublime-commands file).