【发布时间】:2018-08-05 12:28:18
【问题描述】:
我已阅读此How can I autoformat/indent C code in vim? 关于如何格式化 C/C++ 代码的内容,但我想在保存文件时自动格式化代码,例如 vim-go 在保存 Golang 代码时如何调用 gofmt。
如何配置我的 vimrc?我正在使用 clang-format,并使用 Vundle 安装了带有 spf13vim 的 vim-clang-format。
【问题讨论】:
我已阅读此How can I autoformat/indent C code in vim? 关于如何格式化 C/C++ 代码的内容,但我想在保存文件时自动格式化代码,例如 vim-go 在保存 Golang 代码时如何调用 gofmt。
如何配置我的 vimrc?我正在使用 clang-format,并使用 Vundle 安装了带有 spf13vim 的 vim-clang-format。
【问题讨论】:
找到了。
g:clang_format#detect_style_file当此变量的值为
1时,vim-clang-format 会自动检测.clang-format或_clang-format之类的样式文件并将该样式应用于格式化。
所以这段代码应该在.vimrc:
let g:clang_format#auto_format=1
【讨论】: