rubyfmt
April 4, 2026 · View on GitHub
A fast, opinionated Ruby formatter written in Rust.
- Try it online → rubyfmt.run
Pronunciation: (en) "Ruby Format", (jp) ルビーフォーマット
Quick Start
# Install
brew install rubyfmt
# Format a file in place
rubyfmt -i myfile.rb
# Format and print to stdout
rubyfmt myfile.rb
Installation
Homebrew
brew install rubyfmt
Build from Source
- Make sure you have Cargo installed
- Run
cargo build --release - Copy
target/release/rubyfmt-mainto somewhere on your path asrubyfmt
Usage
Command Line
| Command | Description |
|---|---|
rubyfmt file.rb | Output formatted code to stdout |
rubyfmt -i file.rb | Format file in place |
rubyfmt -c file.rb | Show diff of changes |
cat file.rb | rubyfmt | Read from stdin |
You can also pass directories to format multiple files at once.
For the full command line interface, see rubyfmt --help.
Header Comments
Control formatting on a per-file basis with header comments:
rubyfmt --header-opt-in- Only format files with# rubyfmt: trueat the toprubyfmt --header-opt-out- Skip files with# rubyfmt: falseat the top
Ignoring Files
Create a .rubyfmtignore file in your project root to exclude files from formatting. It uses the same syntax as .gitignore.
By default, rubyfmt also respects your .gitignore. Use --include-gitignored to format those files anyway.
Editor Integration
Visual Studio Code
The popular ruby-lsp extension has a rubyfmt add-on. Install the extension:
# Add to project
bundle add ruby-lsp-rubyfmt-formatter --group development
# Install globally
gem install ruby-lsp-rubyfmt-formatter
And then add the following to your .vscode/settings.json:
{
"[ruby]": {
"editor.defaultFormatter": "Shopify.ruby-lsp",
"editor.formatOnSave": true
},
"rubyLsp.formatter": "rubyfmt"
}
Rubyfmt is also supported by the (now-deprecated) VSCode Ruby extension. Add the following to your settings.json:
{
"ruby.useLanguageServer": true,
"ruby.format": "rubyfmt",
"[ruby]": {
"editor.formatOnSave": true
}
}
This is additionally supported by the Formatto for VS Code extension. Use it as your project's formatter by adding this entry to your .vscode/settings.json after installing the extension:
{
"[ruby]": {
"editor.defaultFormatter": "damolinx.formatto"
},
}
Check its README for additional configuration options.
Neovim + null-ls
The null-ls plugin supports rubyfmt out of the box:
null_ls.setup({
sources = {
null_ls.builtins.formatting.rubyfmt,
},
})
See the null-ls documentation for more details.
Vim
- Run
cargo build --release - Add
source /path/to/rubyfmt.vimto your~/.vimrc - Add
let g:rubyfmt_path = /path/to/target/release/rubyfmt-mainbeneath the source line
RubyMine (and JetBrains IDEs)
- Install the File Watchers plugin
- Go to File | Settings | Tools | File Watchers
- Import
watchers.xmlfromeditor_plugins/rubymine/ - Optionally set Level to Global for all projects
See the File Watchers documentation for more details.
Sublime Text
Install the rubyfmt plugin via Package Control.
Files format on save or with Cmd + ; (macOS) / Alt + ; (other). Settings:
{
"ruby_executable": "ruby",
"rubyfmt_executable": "rubyfmt",
"format_on_save": true
}
Atom
Install the rubyfmt package from Settings > Packages.
Files format on save or with Cmd + ; (macOS) / Alt + ; (other).
Rubocop
For usage with Rubocop, see the rubocop-rubyfmt gem.
Contributing
Please check out our contributing guide.
Maintenance Status
The original author (fables-tales) is no longer working on open source in their spare time.
Other contributors work regularly on rubyfmt, and contributors with commit access are welcome to merge changes that pass CI.