I wish that each time I ":w" to save a .h/.cpp file in vim, vim will automatically run cpplint to check my format, and change the file if needed.
How to specify this with autocmd?
Thanks.
I wish that each time I ":w" to save a .h/.cpp file in vim, vim will automatically run cpplint to check my format, and change the file if needed.
How to specify this with autocmd?
Thanks.
If you want to use an autocmd for this, you can simply add this to your .vimrc
:
autocmd BufWrite *.cpp :! cppcheck %
However, I would personally recommend using a syntax checking plugin for this. The very popular vim-syntastic supports cpplint out of the box. You can use the following line to set cpplint
as the syntax checker for C++ files.
let g:syntastic_cpp_checkers = ['cpplint']
The advantage of using a plugin is that it will integrate with Vim and highlight where there are issues, rather than just dumping textual output to stdout.
PS: make sure cpplint
is in your $PATH
, without it neither approach will work.
© 2022 - 2024 — McMap. All rights reserved.