11[ ![ Travis Build Status] ( https://travis-ci.org/google/vim-codefmt.svg?branch=master )] ( https://travis-ci.org/google/vim-codefmt )
22
3- codefmt is a utility for syntax-aware code formatting. It contains several
3+ codefmt is a utility for syntax-aware code formatting. It contains several
44built-in formatters, and allows new formatters to be registered by other
55plugins.
66
77For details, see the executable documentation in the ` vroom/ ` directory or the
8- helpfiles in the ` doc/ ` directory. The helpfiles are also available via
9- ` :help codefmt` if codefmt is installed (and helptags have been generated).
8+ helpfiles in the ` doc/ ` directory. The helpfiles are also available via ` : help
9+ codefmt` if codefmt is installed (and helptags have been generated).
1010
1111# Supported File-types
1212
13- * [ Bazel] ( https://www.github.com/bazelbuild/bazel ) BUILD files (buildifier)
14- * C, C++ (clang-format)
15- * [ Clojure] ( https://clojure.org/ ) ([ zprint] ( https://github.com/kkinnear/zprint ) ,
16- [ cljstyle] ( https://github.com/greglook/cljstyle ) )
17- * CSS, Sass, SCSS, Less (js-beautify)
18- * Dart (dartfmt)
19- * Fish ([ fish_indent] ( https://fishshell.com/docs/current/commands.html#fish_indent ) )
20- * Go (gofmt)
21- * [ GN] ( https://www.chromium.org/developers/gn-build-configuration ) (gn)
22- * Haskell ([ ormolu] ( https://github.com/tweag/ormolu ) )
23- * HTML (js-beautify)
24- * Java (google-java-format or clang-format)
25- * JavaScript (clang-format or [ prettier] ( https://prettier.io ) )
26- * JSON (js-beautify)
27- * Kotlin ([ ktfmt] ( https://github.com/facebookincubator/ktfmt ) )
28- * OCaml ([ ocamlformat] ( https://github.com/ocaml-ppx/ocamlformat ) )
29- * Proto (clang-format)
30- * Python (Autopep8, Black, or YAPF)
31- * Ruby ([ rubocop] ( https://rubocop.org ) )
32- * Rust ([ rustfmt] ( https://github.com/rust-lang/rustfmt ) )
33- * TypeScript (clang-format)
34- * Shell (shfmt)
35- * [ Vue] ( http://vuejs.org ) (prettier)
36- * Nix (nixpkgs-fmt)
37- * Swift ([ swift-format] ( https://github.com/apple/swift-format ) )
13+ * [ Bazel] ( https://www.github.com/bazelbuild/bazel ) BUILD files (buildifier)
14+ * C, C++ (clang-format)
15+ * [ Clojure] ( https://clojure.org/ )
16+ ([ zprint] ( https://github.com/kkinnear/zprint ) ,
17+ [ cljstyle] ( https://github.com/greglook/cljstyle ) )
18+ * CSS, Sass, SCSS, Less (js-beautify, prettier)
19+ * Dart (dartfmt)
20+ * Elixir ([ ` mix format ` ] ( https://hexdocs.pm/mix/main/Mix.Tasks.Format.html ) )
21+ * Fish
22+ ([ fish_indent] ( https://fishshell.com/docs/current/commands.html#fish_indent ) )
23+ * [ GN] ( https://www.chromium.org/developers/gn-build-configuration ) (gn)
24+ * Go (gofmt)
25+ * Haskell ([ ormolu] ( https://github.com/tweag/ormolu ) )
26+ * HTML (js-beautify, prettier)
27+ * Java (google-java-format or clang-format)
28+ * JavaScript (clang-format, js-beautify, or [ prettier] ( https://prettier.io ) )
29+ * JSON (js-beautify)
30+ * Jsonnet ([ jsonnetfmt] ( https://jsonnet.org/learning/tools.html ) )
31+ * Julia ([ JuliaFormatter] ( https://github.com/domluna/JuliaFormatter.jl ) )
32+ * Kotlin ([ ktfmt] ( https://github.com/facebookincubator/ktfmt ) )
33+ * Lua
34+ ([ FormatterFiveOne] ( https://luarocks.org/modules/ElPiloto/formatterfiveone )
35+ * Markdown (prettier)
36+ * Nix (nixpkgs-fmt)
37+ * OCaml ([ ocamlformat] ( https://github.com/ocaml-ppx/ocamlformat ) )
38+ * Protocol Buffers (clang-format)
39+ * Python (Autopep8, Black, isort, or YAPF)
40+ * Ruby ([ rubocop] ( https://rubocop.org ) )
41+ * Rust ([ rustfmt] ( https://github.com/rust-lang/rustfmt ) )
42+ * Shell (shfmt)
43+ * Swift ([ swift-format] ( https://github.com/apple/swift-format ) )
44+ * TypeScript (clang-format)
45+ * [ Vue] ( http://vuejs.org ) (prettier)
3846
3947# Commands
4048
41- Use ` :FormatLines ` to format a range of lines or use ` :FormatCode ` to format
42- the entire buffer. Use ` :NoAutoFormatBuffer ` to disable current buffer
43- formatting.
49+ Use ` :FormatLines ` to format a range of lines or use ` :FormatCode ` to format the
50+ entire buffer. Use ` :NoAutoFormatBuffer ` to disable current buffer formatting.
4451
4552# Usage example
4653
@@ -78,8 +85,8 @@ Glaive codefmt plugin[mappings]
7885Glaive codefmt google_java_executable="java -jar /path/to/google-java-format-VERSION-all-deps.jar"
7986```
8087
81- Make sure you have updated maktaba recently. Codefmt depends upon maktaba
82- to register formatters.
88+ Make sure you have updated maktaba recently. Codefmt depends upon maktaba to
89+ register formatters.
8390
8491# Autoformatting
8592
@@ -89,27 +96,38 @@ Want to just sit back and let autoformat happen automatically? Add this to your
8996``` vim
9097augroup autoformat_settings
9198 autocmd FileType bzl AutoFormatBuffer buildifier
92- autocmd FileType c,cpp,proto,javascript,arduino AutoFormatBuffer clang-format
99+ autocmd FileType c,cpp,proto,javascript,typescript,arduino AutoFormatBuffer clang-format
100+ autocmd FileType clojure AutoFormatBuffer cljstyle
93101 autocmd FileType dart AutoFormatBuffer dartfmt
94- autocmd FileType go AutoFormatBuffer gofmt
102+ autocmd FileType elixir,eelixir,heex AutoFormatBuffer mixformat
103+ autocmd FileType fish AutoFormatBuffer fish_indent
95104 autocmd FileType gn AutoFormatBuffer gn
105+ autocmd FileType go AutoFormatBuffer gofmt
106+ autocmd FileType haskell AutoFormatBuffer ormolu
107+ " Alternative for web languages: prettier
96108 autocmd FileType html,css,sass,scss,less,json AutoFormatBuffer js-beautify
97109 autocmd FileType java AutoFormatBuffer google-java-format
110+ autocmd FileType jsonnet AutoFormatBuffer jsonnetfmt
111+ autocmd FileType julia AutoFormatBuffer JuliaFormatter
112+ autocmd FileType kotlin AutoFormatBuffer ktfmt
113+ autocmd FileType lua AutoFormatBuffer luaformatterfiveone
114+ autocmd FileType markdown AutoFormatBuffer prettier
115+ autocmd FileType ocaml AutoFormatBuffer ocamlformat
98116 autocmd FileType python AutoFormatBuffer yapf
99117 " Alternative: autocmd FileType python AutoFormatBuffer autopep8
118+ autocmd FileType ruby AutoFormatBuffer rubocop
100119 autocmd FileType rust AutoFormatBuffer rustfmt
101- autocmd FileType vue AutoFormatBuffer prettier
102120 autocmd FileType swift AutoFormatBuffer swift-format
121+ autocmd FileType vue AutoFormatBuffer prettier
103122augroup END
104123```
105124
106125# Configuring formatters
107126
108127Most formatters have some options available that can be configured via
109- [ Glaive] ( https://www.github.com/google/vim-glaive )
110- You can get a quick view of all codefmt flags by executing ` :Glaive codefmt ` , or
111- start typing flag names and use tab completion. See ` :help Glaive ` for usage
112- details.
128+ [ Glaive] ( https://www.github.com/google/vim-glaive ) You can get a quick view of
129+ all codefmt flags by executing ` :Glaive codefmt ` , or start typing flag names and
130+ use tab completion. See ` :help Glaive ` for usage details.
113131
114132# Installing formatters
115133
@@ -127,25 +145,22 @@ vroom/FORMATTER-NAME.vroom to learn more about usage for individual formatters.
127145## Creating a New Formatter
128146
129147Assume a filetype ` myft ` and a formatter called ` MyFormatter ` . Our detailed
130- guide to creating a formatter [ lives
131- here] ( https://github.com/google/vim-codefmt/wiki/Formatter-Integration-Guide ) .
148+ guide to creating a formatter
149+ [ lives here] ( https://github.com/google/vim-codefmt/wiki/Formatter-Integration-Guide ) .
132150
133151* Create an issue for your new formatter and discuss!
134152
135153* Create a new file in ` autoload/codefmt/myformatter.vim ` See
136- `autoload/codefmt/buildifier.vim for an example. This is where all the
137- logic for formatting goes.
154+ `autoload/codefmt/buildifier.vim for an example. This is where all the logic
155+ for formatting goes.
138156
139- * Register the formatter in
140- [ plugin/register.vim] ( plugin/register.vim )
141- with:
157+ * Register the formatter in [ plugin/register.vim] ( plugin/register.vim ) with:
142158
143159 ``` vim
144160 call s:registry.AddExtension(codefmt#myformatter#GetFormatter())
145161 ```
146162
147- * Create a flag in
148- [instant/flags.vim](instant/flags.vim)
163+ * Create a flag in [instant/flags.vim](instant/flags.vim)
149164
150165 ```vim
151166 ""
0 commit comments