@@ -3,7 +3,11 @@ if exists('g:loaded_clang_format')
3
3
endif
4
4
5
5
try
6
- call operator#user#define (' clang-format' , ' operator#clang_format#do' , ' let g:operator#clang_format#save_pos = getpos(".") \| let g:operator#clang_format#save_screen_pos = line("w0")' )
6
+ call operator#user#define (' clang-format' ,
7
+ \ ' operator#clang_format#do' ,
8
+ \ 'let g: operator #clang_format#save_pos =
9
+ \ getpos (" ." ) \|
10
+ \ let g: operator #clang_format#save_screen_pos = line (" w0" )')
7
11
catch /^Vim\%((\a\+)\)\=:E117/
8
12
" vim-operator-user is not installed
9
13
endtry
@@ -14,9 +18,22 @@ command! -range=% -nargs=0 ClangFormatEchoFormattedCode echo clang_format#format
14
18
15
19
augroup plugin - clang- format- auto- format
16
20
autocmd !
17
- autocmd BufWritePre * if &ft = ~# ' ^\%(c\|cpp\|objc\|java\|javascript\|typescript\)$' && g: clang_format #auto_format && ! clang_format#is_invalid () | call clang_format#replace (1 , line (' $' )) | endif
18
- autocmd FileType c,cpp,objc,java,javascript,typescript if g: clang_format #auto_format_on_insert_leave && ! clang_format#is_invalid () | call clang_format#enable_format_on_insert () | endif
19
- autocmd FileType c,cpp,objc,java,javascript,typescript if g: clang_format #auto_formatexpr && ! clang_format#is_invalid () | setlocal formatexpr = clang_format#replace (v: lnum ,v: lnum+ v: count- 1 ) | endif
21
+ autocmd BufWritePre *
22
+ \ if &ft = ~# ' ^\%(c\|cpp\|objc\|java\|javascript\|typescript\)$' &&
23
+ \ g: clang_format #auto_format &&
24
+ \ ! clang_format#is_invalid () |
25
+ \ call clang_format#replace (1 , line (' $' )) |
26
+ \ endif
27
+ autocmd FileType c,cpp,objc,java,javascript,typescript
28
+ \ if g: clang_format #auto_format_on_insert_leave &&
29
+ \ ! clang_format#is_invalid () |
30
+ \ call clang_format#enable_format_on_insert () |
31
+ \ endif
32
+ autocmd FileType c,cpp,objc,java,javascript,typescript
33
+ \ if g: clang_format #auto_formatexpr &&
34
+ \ ! clang_format#is_invalid () |
35
+ \ setlocal formatexpr = clang_format#replace (v: lnum ,v: lnum+ v: count- 1 ) |
36
+ \ endif
20
37
augroup END
21
38
22
39
command ! ClangFormatAutoToggle call clang_format#toggle_auto_format ()
0 commit comments