If I am writing code like this in vim:
and I hit enter, I would like the cursor to be positioned below the d.
Currently it is positioning the cursor as far left as possible.
How can I do this?
There are several options you'll want to look at:
(Those commands are typed exactly as you see them above.)
The 'autoindent' option will do as you describe, but Vim can be more intelligent about indenting, hence the others. Usually it's sufficient to use the last one only in your vimrc and let Vim detect your filetype and the proper indent option(s) to use for that filetype.