Expression for $dW$ for a 3D position dependent force $\vec{F}(\vec{r})$. I was looking at the derivation of the infinitesimal element of work done for a 3d position dependent force and I couldn't get over the switching of $\text{d}\vec{v}$ and $\text{d}\vec{r}$ in the third line and how the author went from the penultimate to the last line of working (below): 
$$ \begin{aligned} \text{d}W & = F_x \text{d}x + F_y \text{d}y + F_z \text{d}z \\ &  = \vec{F} \cdot \text{d}\vec{r} \\ & = m \dfrac{\text{d}\vec{v}}{\text{d}t} \cdot \text{d}\vec{r} = m \dfrac{\text{d}\vec{r}}{\text{d}t} \cdot \text{d}\vec{v} \\ & = m \vec{v} \cdot \text{d}\vec{v} \\ & = \text{d} \left( \frac{1}{2} m \vec{v} \cdot \vec{v} \right) \end{aligned} $$
Any help would be greatly appreciated!
Thanks!

This is the well-known derivation of the kinetic energy formula. You'll find it easier to work in scalars initially to see what's happening - so let's make the assumption that the force is always in the direction of motion (thereby obviating the need for the dot products).
The derivation is a "shortcut" application of a change of variables and uses chain rule implicitly.
Here's the longer, more detailed way:
Start with $\displaystyle F = ma = m\frac{dv}{dt}$ and $\displaystyle F = \frac{dW}{dr}$.
Equating the two we get:
$$m\frac{dv}{dt} = \frac{dW}{dr}$$
Note that by chain rule, $\displaystyle \frac{dW}{dr} = \frac{dW}{dv}\cdot \frac{dv}{dr} = \frac{\frac{dW}{dv}}{\frac{dr}{dv}}$
Substituting that and rearranging we get:
$$\frac{dW}{dv} = m\frac{dv}{dt}\cdot \frac{dr}{dv} = m\frac{dr}{dt}$$
with another application of chain rule. 
Now because $\displaystyle v = \frac{dr}{dt}$, we can rewrite that:
$$\frac{dW}{dv} =mv$$
The RHS depends only on the variable $v$ (mass is constant in classical mechanics), so we can simply integrate both sides by $v$ to get:
$$\int_0^v \frac{dW}{dv}dv = \int_0^v mvdv$$
and hence
$$W = \frac{1}{2}mv^2$$
This is a slightly long-winded and unwieldy way of doing this. Most of the time, we can simplify the derivation by cancelling and rearranging infinitesimals directly. Now that you should have understood the "long way", let me show you the "shortcut".
Again, start with:
$$m\frac{dv}{dt} = \frac{dW}{dr}$$
Rearrange by bringing the $dr$ over to the LHS to get:
$$dW = m\frac{dv}{dt}\cdot {dr}$$
Now simply rearrange the infinitesimals on the RHS to get:
$$dW = m\frac{dr}{dt}\cdot dv$$
and since $\displaystyle \frac{dr}{dt}=v$,
$$dW = mvdv$$
Now we can perform integration like before to get the same final result.
You should now be able to put in the dot products appropriately to see exactly how they arrive at your result. The final line is just an alternative formulation of $mvdv$, which can also be expressed as $d(\frac{1}{2}mv^2)$.
If you have trouble "seeing" that, think of how variables are being separated here in this simple example:
$y = x^2 \implies \frac{dy}{dx} = 2x \implies dy = 2xdx$
and since $dy = d(x^2)$, you can also write $d(x^2) = 2xdx$. These are equivalent formulations.
