forked from rhysd/vim-clang-format
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclang-format.txt
307 lines (214 loc) · 12.1 KB
/
clang-format.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
*clang-format.txt* Format C, C++, Objective-C using clang-format
Author : rhysd <lin90162@yahoo.co.jp>
CONTENTS *vim-clang-format-contents*
Introduction |vim-clang-format-introduction|
Usage |vim-clang-format-usage|
Install |vim-clang-format-install|
Dependency |vim-clang-format-dependency|
Commands |vim-clang-format-commands|
Mappings |vim-clang-format-mappings|
Functions |vim-clang-format-functions|
Variables |vim-clang-format-variables|
Setup Example |vim-clang-format-setup-example|
Repository Page |vim-clang-format-repository-page|
License |vim-clang-format-license|
==============================================================================
INTRODUCTION *vim-clang-format-introduction*
*vim-clang-format* formats your C, C++ and Objective-C code with specific coding
style using clang. Automatic formatting is supported for the following file
types by default.
* c
* cpp
* objc
* javascript
* java
* typescript
* proto
* arduino
Screenshot:
http://gifzo.net/BIteGJ9Vasg.gif
==============================================================================
USAGE *vim-clang-format-usage*
|:ClangFormat| command is available. If you use it in normal mode, the whole
code will be formatted. If you use it in visual mode, the selected code will
be formatted. It is more convenient to map |:ClangFormat| to your favorite key
mapping in normal mode and visual mode.
|'shiftwidth'| and |'expandtab'| are used for formatting.
In addition, |<Plug>(operator-clang-format)| is an operator mapping to format
the |text-objects|. It is also very useful for expert users.
==============================================================================
DEPENDENCY *vim-clang-format-dependency*
|clang-format| (3.4 or later is required)
http://clang.llvm.org/docs/ClangFormat.html
Note:
clang-format 3.4 in Ubuntu 13.04 seems to be old. Please use LLVM's
official apt repository.
http://llvm.org/apt/
|vim-operator-user| (highly recommended)
https://github.com/kana/vim-operator-user
|vimproc| (recommended in Windows)
https://github.com/Shougo/vimproc.vim
==============================================================================
INSTALL *vim-clang-format-install*
Using Vim plugin package manager is recommended. I use |neobundle| and |vundle|
seems the most famous.
If you want to install manually, it is not recommended, copy files and
directories in autoload, doc and plugin directories to your vim config
directory. Vim config directory is usually $HOME/vimfiles on Windows or
~/.vim in other operating systems.
==============================================================================
COMMANDS *vim-clang-format-commands*
:[range]ClangFormat *:ClangFormat*
Format a entire current buffer with clang-format. If [range] is
given, |:ClangFormat| formats the range. In visual mode, |:ClangFormat|
formats the selected region with linewise way.
:[range]ClangFormatEchoFormattedCode *:ClangFormatEchoFormattedCode*
Echo version of |:Clangformat|. Instead of editing buffer directly, echo
the formatted text.
==============================================================================
MAPPINGS *vim-clang-format-mappings*
<Plug>(operator-clang-format) *<Plug>(operator-clang-format)*
Operator mapping to format source code with clang-format. To use this
mapping, |operator-user| is required.
==============================================================================
FUNCTIONS *vim-clang-format-functions*
clang_format#replace({start_line}, {last_line}) *clang_format#replace()*
This is function version of |:ClangFormat|. {start_line} and {last_line}
are required.
clang_format#format({start_line}, {last_line}) *clang_format#format()*
This function returns a formatted code as |String|.
==============================================================================
VARIABLES *vim-clang-format-variables*
g:clang_format#command *g:clang_format#command*
Name of clang-format command.
The default value is "clang-format".
g:clang_format#git *g:clang_format#git*
Name of the git command.
The default value is "git".
g:clang_format#code_style *g:clang_format#code_style*
Base coding style for formatting. Available coding styles are "llvm",
"google", "chromium" and "mozilla".
The default value is "google".
g:clang_format#style_options *g:clang_format#style_options*
Coding style options to specify the rule of format in more detail. For
example, using {} in short if statement or not, use C++11 feature or not,
access modifier offset and so on. This value is a |Dictionary| whose key
and value are |String| or |Number|.
The key and the value are options passed to clang-format's -stryle option.
You can look up them by executing `clang-format -dump-config` command. If
you want to know all of the keys and values, clang-format's documentation
and API documentation is useful. In paticular, the following link is
useful to know.
CLANG-FORMAT STYLE OPTIONS
http://clang.llvm.org/docs/ClangFormatStyleOptions.html
g:clang_format#filetype_style_options
*g:clang_format#filetype_style_options*
If you want to use language-specific style options, you can use this
variable. This variable is a |Dictionary| and its key is |filetype|. You
can specify the filetype specific style options as a value of the key.
The format to specify options is the same as |g:clang_format#style_options|.
For example, if you want to set "C++11" to "Standard", you can specify it
only when the filetype is "cpp" as below:
>
" Your common style options
let g:clang_format#style_options = {
\ 'AllowShortIfStatementsOnASingleLine' : 'true',
\ }
" Your filetype specific options
let g:clang_format#filetype_style_options = {
\ 'cpp' : {"Standard" : "C++11"},
\ }
<
g:clang_format#extra_args *g:clang_format#extra_args*
Extra arguments for clang-format. This |String| value is passed to
clang-format directly.
g:clang_format#detect_style_file *g:clang_format#detect_style_file*
When the value is 1, |vim-clang-format| automatically detects the style file
like .clang-format or _clang-format and applies the style to formatting.
The default value is 1.
g:clang_format#auto_format *g:clang_format#auto_format*
When the value is 1, |vim-clang-format| automatically formats a current
buffer on saving the buffer. Formatting is executed at |BufWritePre| event.
The default value is 0.
g:clang_format#auto_format_git_diff *g:clang_format#auto_format_git_diff*
When this value is 1, and when g:clang_format#auto_format is 1, the auto
format only formats modified lines is the file is tracked in git.
If the file is not tracked, or even not in a git project, fallback
behavior depends on |g:clang_format#auto_format_git_diff_fallback|.
WARNING: this option should not be used with
|g:clang_format#auto_format_on_insert_leave|.
The default value is 0.
g:clang_format#auto_format_git_diff_fallback
*g:clang_format#auto_format_git_diff_fallback*
Fallback behavior when |g:clang_format#auto_format_git_diff| is 1 and the
current file is not tracked. The value can be:
- 'file': the whole file is formatted (which is the default
|g:clang_format#auto_format| behavior).
- 'pass': the file is not formatted.
g:clang_format#auto_format_on_insert_leave
*g:clang_format#auto_format_on_insert_leave*
When the value is 1, the inserted lines are automatically formatted on
leaving insert mode. Formatting is executed on |InsertLeave| event.
g:clang_format#auto_formatexpr *g:clang_format#auto_formatexpr*
When the value is 1, 'formatexpr' option is set automatically in |c|, |cpp|
and |objc| codes. Vim's format mappings (e.g. |gq|) get to use |clang-format|
to format. This option is not comptabile with Vim's `textwidth` feature. You
must set `textwidth` to `0` when the `formatexpr` is set.
g:clang_format#auto_filetypes *g:clang_format#auto_filetypes*
List of file types to which |g:clang_format#auto_format|,
|g:clang_format#auto_format_on_insert_leave|, and
|g:clang_format#auto_formatexpr| should be applied.
The default value is [ "c", "cpp", "objc", "java",
\ "javascript", "typescript", "proto", "arduino" ].
g:clang_format#enable_fallback_style *g:clang_format#enable_fallback_style*
When the value is 0, "-fallback-style=none" option is added on executing
clang-format command. It means that vim-clang-format does nothing when
".clang-format" is not found.
The default value is 1.
==============================================================================
SETUP EXAMPLE *vim-clang-format-setup-example*
Below is an example for .vimrc.
>
" your favorite style options
let g:clang_format#style_options = {
\ "AccessModifierOffset" : -4,
\ "AllowShortIfStatementsOnASingleLine" : "true",
\ "AlwaysBreakTemplateDeclarations" : "true",
\ "Standard" : "C++11"}
augroup ClangFormatSettings
autocmd!
" map to <Leader>cf in C++ code
autocmd FileType c,cpp,objc nnoremap <buffer><Leader>cf :<C-u>ClangFormat<CR>
autocmd FileType c,cpp,objc vnoremap <buffer><Leader>cf :ClangFormat<CR>
" if you install vim-operator-user
autocmd FileType c,cpp,objc map <buffer><Leader>x <Plug>(operator-clang-format)
augroup END
<
==============================================================================
REPOSITORY PAGE *vim-clang-format-repository-page*
The latest version of |vim-clang-format| is available at
https://github.com/rhysd/vim-clang-format
Contributions (pull requests) are welcome. None of them is too short.
Especially, English check is very helpful because I'm poor at English :(
==============================================================================
LICENSE *vim-clang-format-license*
|vim-clang-format| is distributed under MIT license.
Copyright (c) 2013-2021 rhysd
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==============================================================================
vim:tw=78:colorcolumn=78:ts=8:ft=help:norl:noet:fen:fdl=0: