I find this to be very convenient especially if you're doing a quick code editing or even on a long session of coding, using Vim. And you want to enforce a particular indentation style, in this case, a 4 space indentation.
~/.vimrc file, add this options:
syntax enable set smartindent set tabstop=4 set shiftwidth=4 set expandtab
Your tabs will now be 4 spaces, new lines will be auto-indented and curly braces will be aligned automatically.
Source: Stack Overflow