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

1

6

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.

Safelight answered 19/11, 2016 at 14:47 Comment(1)
Possible duplicate of vim: how to execute automatically execute a shell command after saving a file?Foresheet
R
11

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.

Reheat answered 19/11, 2016 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.