Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make vim run "cpplint" after every "save" command?

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.

like image 258
Troskyvs Avatar asked Nov 19 '16 14:11

Troskyvs


1 Answers

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.

like image 104
Jonas Avatar answered Nov 15 '22 09:11

Jonas