To format just a few Ruby files with rubyfmt, pass their paths explicitly: rubyfmt -i lib/a.rb lib/b.rb. The -i flag formats those files in place. For broader runs, use .rubyfmtignore and rubyfmt’s Git-ignore or header controls to limit what it touches. Choosing files is different from formatting selected lines inside a file; the latter is experimental in the Formatto VS Code extension.
Install rubyfmt
rubyfmt is described by its project README as “A fast, opinionated Ruby formatter written in Rust.” The project documents installation with Homebrew or by building from source with Cargo and putting the resulting executable on your PATH. See the official rubyfmt README for the current instructions. Homebrew also lists rubyfmt as a Ruby autoformatter and links to the project: rubyfmt on Homebrew.
Format only named files from the command line
Pass the exact file paths you want to process. For example, rubyfmt -i lib/a.rb lib/b.rb formats only those two files in place. If you omit -i, rubyfmt file.rb writes formatted output to standard output instead of replacing the file. Use -c to see a diff rather than applying the formatting.
The same path-based approach works when you want a small, explicit set of files: provide each path as an argument rather than passing a project directory. The README also documents passing directories to process multiple files, which is useful for a broader pass but less precise when you want to avoid touching unrelated code.
#1 Best Overall
Limit directory-wide formatting with ignore rules
When you pass a directory, rubyfmt respects Git ignore rules by default. To add rubyfmt-specific exclusions, create a root-level .rubyfmtignore file using .gitignore syntax. Files already ignored by Git are normally omitted; add --include-gitignored when you explicitly want rubyfmt to include them.
This is a useful distinction: named paths define a narrow run directly, while ignore rules help constrain discovery when you intentionally process a directory. Check the project README for the current command-line behavior and available options.
Rank #2
Opt files in or out with header comments
For repository-level file-by-file control, rubyfmt supports header comments when you activate the matching CLI option:
--header-opt-informats files that begin with# rubyfmt: true.--header-opt-outskips files that begin with# rubyfmt: false.
The comments alone do not activate these policies; use the corresponding option on the rubyfmt command. Consult the README for the exact invocation supported by your installed version.
Recommended Free Tools
Rank #3
Format changed files in VS Code with Formatto
The Formatto extension supports rubyfmt and provides a “Format Pending Changes” command for modified Ruby files in open Git repositories. The operation works on files on disk, so save unsaved edits before running it. For an individual document, configure Formatto and use VS Code’s Format Document command or Format on Save.
Formatto defaults to rubyfmt. Its settings let you choose a formatter, set formatto.rubyfmtPath, add rubyfmt arguments such as --header-opt-in, and define exclusions with formatto.excludePatterns. The extension lists .rb, .rbs, .rbi, .gemspec, and .podspec as supported rubyfmt extensions. See the Formatto extension listing for its documentation and current settings.
Rank #4
Can rubyfmt format only selected lines?
That is a different task from selecting files. Formatto’s range-formatting support is experimental and heuristic, not a dependable promise to format any arbitrary selection. Incomplete or syntactically broken ranges may remain unchanged, and range output can differ from formatting a complete document. Ruby formatters generally expect complete, syntactically valid code, according to the extension documentation.
If you need reliable, reproducible formatting, format the whole file and limit the command to the intended file paths. For editor range formatting, treat the result as best-effort and review the diff.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Best Value
Is there a rubyfmt style configuration file?
The official README reviewed for this article does not document a general style configuration file. Its documented controls for limiting work are paths and directories, ignore rules, Git-ignore behavior, and optional header comments. Do not assume that a .rubyfmt.yml file is supported: the similarly named rfmt project is a different formatter.
Because command options and editor settings can change, check the CLI help and extension documentation for the versions you have installed.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




