简体   繁体   中英

Tool for auto formatting or giving error in VIM

What are the plugnins for vim/gvim that can report about bad formatting esp C++ code and PLSQL code. Like:

  1. blank space after a line.
  2. line having character more than 80 (like 'match' does).
  3. void foo(int x,int y); then it will report forgot a space after ,
  4. And many more formatting errors like above.

Is there any standard practice for reporting the formatting of code before checking into CVS?

In my case, I have a series of syntax rules defined to make such things easy to spot.

highlight ImproperSyntax ctermbg=red guibg=red
au BufWinEnter * syn match ImproperSyntax /\s\+$\| \+\ze\t/  "Spaces at the end of lines or BEFORE tabs
au Filetype cpp,c syn keyword ImproperSyntax dynamic_cast "disallowed keyword
au Filetype cpp,c syn match ImproperSyntax /[^\n]\%$/  display "Last line should be blank
au Filetype cpp,c syn match ImproperSyntax /\t/ display "No tabs!
au Filetype cpp,c syn match ImproperSyntax /,\S/ display "comma always has a space
au Filetype cpp,c syn match ImproperSyntax /\%80v.*$/ "Highlight any characters passed column 80

An additional trick you can use is to incorporate all of these into a function (or list/dictionary), and display them as an error either on the statusline (my preference), or to the user as an error.

Regarding checking into CVS... I'm not sure about CVS, but SVN and hg (and presumably most other version control systems) can be instructed to execute a series of 'pre-commit hooks', before allowing you to commit. One of those could easily be programmed to scan for this same behavior (possibly with some sort of override symbol as well).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM