The indent features of Vim are very helpful for indenting source code.
:help autoindent :help smartindent
https://vim.fandom.com/wiki/Indenting_source_code#Methods_for_automatic_indentation