1
1
[ ![ Travis Build Status] ( https://travis-ci.org/google/vim-codefmt.svg?branch=master )] ( https://travis-ci.org/google/vim-codefmt )
2
2
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
4
4
built-in formatters, and allows new formatters to be registered by other
5
5
plugins.
6
6
7
7
For 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).
10
10
11
11
# Supported File-types
12
12
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)
38
46
39
47
# Commands
40
48
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.
44
51
45
52
# Usage example
46
53
@@ -78,8 +85,8 @@ Glaive codefmt plugin[mappings]
78
85
Glaive codefmt google_java_executable="java -jar /path/to/google-java-format-VERSION-all-deps.jar"
79
86
```
80
87
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.
83
90
84
91
# Autoformatting
85
92
@@ -89,27 +96,38 @@ Want to just sit back and let autoformat happen automatically? Add this to your
89
96
``` vim
90
97
augroup autoformat_settings
91
98
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
93
101
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
95
104
autocmd FileType gn AutoFormatBuffer gn
105
+ autocmd FileType go AutoFormatBuffer gofmt
106
+ autocmd FileType haskell AutoFormatBuffer ormolu
107
+ " Alternative for web languages: prettier
96
108
autocmd FileType html,css,sass,scss,less,json AutoFormatBuffer js-beautify
97
109
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
98
116
autocmd FileType python AutoFormatBuffer yapf
99
117
" Alternative: autocmd FileType python AutoFormatBuffer autopep8
118
+ autocmd FileType ruby AutoFormatBuffer rubocop
100
119
autocmd FileType rust AutoFormatBuffer rustfmt
101
- autocmd FileType vue AutoFormatBuffer prettier
102
120
autocmd FileType swift AutoFormatBuffer swift-format
121
+ autocmd FileType vue AutoFormatBuffer prettier
103
122
augroup END
104
123
```
105
124
106
125
# Configuring formatters
107
126
108
127
Most 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.
113
131
114
132
# Installing formatters
115
133
@@ -127,25 +145,22 @@ vroom/FORMATTER-NAME.vroom to learn more about usage for individual formatters.
127
145
## Creating a New Formatter
128
146
129
147
Assume 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 ) .
132
150
133
151
* Create an issue for your new formatter and discuss!
134
152
135
153
* 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.
138
156
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:
142
158
143
159
``` vim
144
160
call s:registry.AddExtension(codefmt#myformatter#GetFormatter())
145
161
```
146
162
147
- * Create a flag in
148
- [instant/flags.vim](instant/flags.vim)
163
+ * Create a flag in [instant/flags.vim](instant/flags.vim)
149
164
150
165
```vim
151
166
""
0 commit comments