ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Rust​Fmt

by Nelo Mitranim ST3

Sublime Text plugin that formats Rust code with rustfmt

Labels rust, fmt, format, beautify

Details

Installs

  • Total 12K
  • Win 4K
  • Mac 4K
  • Linux 5K
Apr 25 Apr 24 Apr 23 Apr 22 Apr 21 Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6 Apr 5 Apr 4 Apr 3 Apr 2 Apr 1 Mar 31 Mar 30 Mar 29 Mar 28 Mar 27 Mar 26 Mar 25 Mar 24 Mar 23 Mar 22 Mar 21 Mar 20 Mar 19 Mar 18 Mar 17 Mar 16 Mar 15 Mar 14 Mar 13 Mar 12 Mar 11
Windows 1 0 1 1 1 0 0 0 0 3 3 3 2 5 1 0 0 4 3 4 1 0 3 2 3 2 1 0 1 1 0 2 1 0 2 1 3 3 2 2 1 4 1 1 0 2
Mac 2 0 2 0 3 0 1 0 0 2 2 1 0 0 0 0 2 0 1 2 2 1 0 1 1 0 0 0 0 0 1 2 0 4 0 0 0 1 0 1 1 0 1 3 1 4
Linux 3 1 2 2 2 0 2 4 5 3 2 1 0 2 1 3 0 2 0 0 2 2 5 0 3 3 1 4 2 1 5 0 1 3 3 1 1 5 5 0 0 2 0 2 1 4

Readme

Source
raw.​githubusercontent.​com

Overview

RustFmt is a Sublime Text 3 plugin that auto-formats Rust code with rustfmt or another executable.

Unlike BeautifyRust, it's fast and works on buffers that have yet not been saved as files. Unlike RustFormat, it preserves the buffer scroll position. It also supports rustfmt.toml.

Dependencies

Requires Sublime Text version 3124 or later.

Requires rustfmt to be on PATH). Installation:

rustup component add rustfmt

Installation

Package Control

  1. Get Package Control
  2. Open command palette: Shift+Super+P or Shift+Ctrl+P
  3. Package Control: Install Package
  4. RustFmt

Manual

Clone the repo:

git clone https://github.com/mitranim/sublime-rust-fmt.git

Then symlink it to your Sublime packages directory. Example for MacOS:

mv sublime-rust-fmt RustFmt
cd RustFmt
ln -sf "$(pwd)" "$HOME/Library/Application Support/Sublime Text 3/Packages/"

To find the packages directory, use Sublime Text menu → Preferences → Browse Packages.

Usage

By default, RustFmt will autoformat files before saving. You can trigger it manually with the RustFmt: Format Buffer command in the command palette.

If the plugin can't find the executable:

  • run which rustfmt to get the absolute executable path
  • set it as the executable setting, see Settings below

On MacOS, it might end up like this:

Error: language “sublime-settings” is not supported
"executable": ["/Users/username/.cargo/bin/rustfmt"]

Can pass additional arguments:

Error: language “sublime-settings” is not supported
"executable": ["rustup", "run", "nightly", "rustfmt"]

Settings

See RustFmt.sublime-settings for all available settings. To override them, open:

Preferences → Package Settings → RustFmt → Settings

RustFmt looks for settings in the following places:

  • "RustFmt" dict in general Sublime settings, possibly project-specific
  • RustFmt.sublime-settings, default or user-created

The general Sublime settings take priority. To override them on a per-project basis, create a "RustFmt" entry:

Error: language “sublime-settings” is not supported
"RustFmt": {
    "format_on_save": false
  },

Commands

In Sublime's command palette:

  • RustFmt: Format Buffer

Hotkeys

To avoid potential conflicts, this plugin does not come with hotkeys. To hotkey the format command, add something like this to your .sublime-keymap:

Error: language “sublime-keymap” is not supported
{
  "keys": ["ctrl+super+k"],
  "command": "rust_fmt_format_buffer",
  "context": [{"key": "selector", "operator": "equal", "operand": "source.rust"}]
}

License

https://en.wikipedia.org/wiki/WTFPL