These are cases when index notations becomes extremely helpful. Denote by $\partial_1 = \partial_x, \partial_2 = \partial_y, \partial_3 = \partial_z$ and for a vector write its components as $ \vec{v} = v_1 \hat{x} + v_2 \hat{y} + v_3 \hat{z}$ Then the divergence of a vector field is $ \vec{\nabla}\cdot\vec{v} = \sum_{i = 1}^3 \partial_i v_i $ The gradient vector of a scalar field has components $ (\vec{\nabla f})_i = \partial_i f $ and the Laplacian of a function is $ \triangle f = \sum_i \partial_i \partial_i f $
When doing computations, do them term by term (that is, expand out the sums if necessary) and in the end, when the $\partial_i$ hits on a scalar quantity, it is a gradient, and when the $\partial_i$ hits on a vector quantity indexed also by $i$ you get a divergence.
To illustrate: if $f$ be function a $\vec{v}$ a vector field, then the object $f \vec{v}$ is a vector field. Let us compute its divergence. We do it like so:
$ \vec{\nabla}\cdot(f\vec{v}) = \sum_i \partial_i \left( f v_i\right)= \sum_i (\partial_i f)v_i + f \partial_i v_i \tag{1}$
The first term then is interpreted as the dot product of the gradient vector $\vec{\nabla f}$ against the vector $\vec{v}$, so for this term "the divergence outside changed to a gradient inside". The second term contains the divergence of the vector field $\vec{v}$ it self, multiplied against the function $f$. So for this term the divergence remains a divergence.
The use of index notations is also extremely helpful when there are multiple sets of indices in play. Let $\vec{v}$ be a vector field, we can consider the gradient of its divergence $\vec{\nabla}(\vec{\nabla} \cdot \vec{v})$. Now, since partial derivatives commute, what happens when we try to interchange the derivatives? In index notation you have
$ \underbrace{\partial_j}_{\text{the gradient}} \underbrace{\sum_i \partial_i v_i}_{\text{the divergence}} = \sum_i \partial_j \partial_i v_i = \sum_i \partial_i (\partial_j v_i)$
which is now a divergence of an object with two indices (a tensor field, in fact). Using indices help enormously in keeping track where various operators hit: for example compare the above expression with the similar but different expression $ (\triangle \vec{v})_j = \sum_i \partial_i \partial_i v_j $
As an aside, (1) is basically the same as the integration by parts formula which you described.