Sublime Text is one of those editors that just works. It's fast, flexible, and delightfully minimal -- until you realize you can make it do even more. That's where custom plugins come in.
Let's explore how to turn Sublime into your editor, one Python file at a time.
You know that repetitive task you do every day? Maybe it's inserting a license header, formatting code, or cleaning up TODOs before a commit. Plugins are your secret weapon to automate all of it.
Sublime's plugin API lets you hook into the editor and make it respond to events -- like saving, typing, or opening a file. You can even add new commands, menus, or shortcuts.
Think of it like this: you're not just using an editor anymore -- you're training it to work your way.
Every plugin starts as a single Python file inside a package folder in Packages/User/.
Here's the smallest possible example -- a command that inserts a friendly header at the top of a file:
import sublime
import sublime_plugin
class InsertHeaderCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.insert(edit, 0, "# Hello from my first Sublime plugin!\n")
Save that file as insert_header.py under Packages/User/, then open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P on macOS) and run Insert Header.
Boom. You just wrote a plugin.
Want to go deeper? Check the official Sublime plugin API reference.
Commands are great, but Sublime can also react to what you do -- like saving or editing a file.
class HelloOnSave(sublime_plugin.EventListener):
def on_post_save(self, view):
sublime.status_message("File saved -- great job!")
This EventListener fires every time you save a file and posts a status message at the bottom. Try it out -- it feels surprisingly rewarding.
Sublime runs plugin code in a helper process called plugin_host. That means a bad plugin won't crash your editor -- but it can still make things sluggish. To keep things smooth, avoid doing heavy work directly in run() or on_modified(). For long-running tasks, offload them with:
sublime.set_timeout_async(my_function)
Once your plugin works, you can package it up with menus, key bindings, and settings. If you're feeling confident, publish it on GitHub and submit it to Package Control so others can use it too.
Sublime plugins aren't just for power users -- they're for anyone who wants their tools to bend to their workflow.
Start small: automate one little annoyance. Then watch your editor evolve into something that feels tailor‑made for you.
Want to go further? Your editor is more powerful than you think.