Over the course of your career you will encounter a variety of formatting styles. My advice is to get used to it--learn to adapt your style to that of the file you're working on. Among other reasons, tools for translating from one style to the next generally don't make the round trip without introducing changes to the file, and that makes it difficult to use a tool like diff to see the substantive changes you made.
That said, Vim provides a number of hooks to execute commands as files are read and written. See
:help autocommand
For example,
au BufWrite * %s/\s\+$//
will remove trailing spaces from a buffer just before you write it to disk. The command can be any ex command including calling a function or filtering the entire buffer through an external program.
The BufWrite event is triggered just before the buffer is written. Another name for it is BufWritePre. If you want to write the buffer, then undo the changes made at the BufWritePre event, you can use the BufWritePost command to revert those changes. The BufRead (a.k.a. BufReadPost) event can be used to trigger commands that format text the way you want it when a file is read.
The * will match any file name. You can use file name patterns such as .c,.cpp to trigger your autocommands only when certain kinds of files are read or written.
As another example,
au BufRead *.[ch] normal gg=G
will re-indent any C source file you read according to your C indenting rules. See
:help =
:help C-indenting