{"id":24083270,"url":"https://github.com/mitranim/sublime-fmt","last_synced_at":"2025-04-30T18:23:01.277Z","repository":{"id":44431144,"uuid":"305936693","full_name":"mitranim/sublime-fmt","owner":"mitranim","description":"Sublime Text generic formatter plugin; formats arbitrary code by calling arbitrary executables, such as `gofmt`","archived":false,"fork":false,"pushed_at":"2023-11-07T10:03:21.000Z","size":37,"stargazers_count":23,"open_issues_count":5,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-26T06:56:57.961Z","etag":null,"topics":["autoformat","fmt","formatter","formatting","sublime-text","sublime-text-plugin"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mitranim.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-10-21T07:02:59.000Z","updated_at":"2024-08-19T10:43:07.000Z","dependencies_parsed_at":"2023-11-07T11:24:05.947Z","dependency_job_id":null,"html_url":"https://github.com/mitranim/sublime-fmt","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitranim%2Fsublime-fmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitranim%2Fsublime-fmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitranim%2Fsublime-fmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitranim%2Fsublime-fmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mitranim","download_url":"https://codeload.github.com/mitranim/sublime-fmt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251758639,"owners_count":21639072,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autoformat","fmt","formatter","formatting","sublime-text","sublime-text-plugin"],"created_at":"2025-01-09T23:56:15.254Z","updated_at":"2025-04-30T18:23:01.252Z","avatar_url":"https://github.com/mitranim.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Overview\n\nSublime Text plugin for auto-formatting arbitrary code by calling arbitrary executables. Works for `gofmt`, `rustfmt`, any similar tool that's an executable and uses standard input/output.\n\nFeatures:\n\n* Format on demand. Optionally auto-format on save.\n* Configure executables and other settings per _scope_ (syntax type: `source.go`, `source.rust` and so on).\n* Optionally preserve cursor and scroll position when formatting, via `\"merge_type\": \"diff\"`.\n* Show errors in an output panel (configurable).\n* Format either an entire file, or only selection.\n  * Selection formatting works for embedded syntaxes, such as JS inside HTML.\n\nLimitations:\n\n* Invokes a subprocess every time. Good enough for formatters written in compiled languages, such as `gofmt` and `rustfmt`. If a given formatter is written in JS and takes a second to start up, this tool might not be suitable.\n\nBased on https://github.com/mitranim/sublime-gofmt and fully replaces it. Also replaces [RustFmt](https://github.com/mitranim/sublime-rust-fmt) and countless others.\n\n## Why\n\nWhy this exists?\n\nPackage Control has special-case formatter plugins for different languages, and the monstrous Formatter with too many batteries included. This makes it hard to add formatters: someone has to make and publish a new plugin every time, or fork a repo and make a PR, etc.\n\nMany formatters just call a subprocess and use stdio. One plugin can handle them all, while letting the _user_ specify any new formatter for any new syntax! This works for `gofmt`, `rustfmt`, `clang-format`, and endless others.\n\n## Installation\n\n### Package Control\n\n1. Get [Package Control](https://packagecontrol.io).\n2. Open the command palette: ⇪⌘P or ⇪^P.\n3. `Package Control: Install Package`.\n4. `Fmt`.\n\n### Manual\n\nClone the repo and symlink it to your Sublime packages directory. Example for MacOS:\n\n```sh\ngit clone https://github.com/mitranim/sublime-fmt.git\ncd sublime-fmt\nln -sf \"$(pwd)\" \"$HOME/Library/Application Support/Sublime Text 3/Packages/Fmt\"\n```\n\nTo find the packages directory on your system, use Sublime Text menu → Preferences → Browse Packages.\n\n## Usage\n\nThe plugin has _no default formatters_. It invokes CLI programs installed globally on your system. You must specify them in the plugin settings. Example for Go:\n\n```json\n{\n  \"rules\": [\n    {\n      \"selector\": \"source.go\",\n      \"cmd\": [\"goimports\"],\n      \"format_on_save\": true,\n      \"merge_type\": \"diff\",\n    },\n  ],\n}\n```\n\nTo understand Sublime scopes and selector matching, read this short official doc: https://www.sublimetext.com/docs/selectors.html.\n\n**How to get scope name**. Option 1: menu → Tools → Developer → Show Scope Name. Option 2: run the command `Fmt: Format Buffer`, and if not configured for the current scope, it will tell you!\n\nTo format on demand, run the `Fmt: Format Buffer` command from the command palette. See below how to configure hotkeys.\n\nTo auto-format on save, set `\"format_on_save\": true` in the settings. Can be global or per rule.\n\n## Settings\n\nSee [`Fmt.sublime-settings`](Fmt.sublime-settings) for all available settings. To override them, open:\n\n```\nmenu → Preferences → Package Settings → Fmt → Settings\n```\n\nThe plugin looks for settings in the following places, with the following priority:\n\n  * `\"Fmt\"` dict in general Sublime settings, project-specific or global.\n  * `Fmt.sublime-settings`, user-created or default.\n\nFor overrides, open project or global settings and make a `\"Fmt\"` entry:\n\n```json\n{\n  \"Fmt\": {\n    \"rules\": [\n      {\n        \"selector\": \"source.some_lang\",\n        \"cmd\": [\"some_lang_fmt\", \"--some_arg\"],\n      },\n    ],\n  },\n}\n```\n\nA rule may contain _any_ of the root-level settings, such as `format_on_save`. This allows fine-tuning.\n\n## Commands\n\nIn Sublime's command palette:\n\n* `Fmt: Format Buffer`\n* `Fmt: Format Selection`\n\n## Hotkeys\n\nHotkeys? More like _notkeys_!\n\nTo avoid potential conflicts, this plugin does not come with hotkeys. To hotkey\nthe format commands, add something like this to your `.sublime-keymap`:\n\n```sublime-keymap\n{\"keys\": [\"primary+k\", \"primary+j\"], \"command\": \"fmt_format_buffer\"},\n{\"keys\": [\"primary+k\", \"primary+k\"], \"command\": \"fmt_format_selection\"},\n```\n\nSublime automatically resolves \"primary\" to \"super\" on MacOS and to \"ctrl\" on other systems.\n\n## Changelog\n\n**2022-07-18**. Ignore informational output over stderr when the subprocess exits with 0 and stdout is non-empty.\n\n**2022-07-11**. Use `\"merge_type\": \"replace\"` by default. Diff is now opt-in due to extreme performance degradation for large amounts of diffs.\n\n**2020-12-28**. Support env variable substitution. Format-on-save is no longer enabled by default.\n\n**2020-11-26**. Support variable substitution in `cmd`.\n\n**2020-11-25**. Use scope selectors instead of exactly matching the scope name.\n\n**2020-10-25**. Support subprocess timeout, always kill the subprocess.\n\n**2020-10-23**. Support several ways of printing errors. By default, errors are shown in a transient output panel at the bottom.\n\n## License\n\nhttps://unlicense.org\n\n`difflib.py` is based on code which is published under Apache license, see the hyperlink in the file. It underwent significant edits, and its licensing status is unknown to me. Everything else is original and under Unlicense.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitranim%2Fsublime-fmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmitranim%2Fsublime-fmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitranim%2Fsublime-fmt/lists"}