I have the VIM Clang Format Plugin and I would like to format my code every time I save it.
This is in my current .vimrc:
" 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> " Format on save autocmd BufWritePost * \ autocmd FileType c,cpp,objc ClangFormat
The first two lines work great. I can hit leader + cf in
normal mode and the code gets formatted. My problems are the last two lines.
I hit save (:wc) and BufWritePost * is triggered.
ClangFormat is only executed if the filetype is c, cpp, or objc (just as in the first two lines).
Well, it doesn't work and I can't find my mistake. Any help is appreciated.