Vacuum energy of a free scalar field from path integral My question has been asked two other times:
Spinor vacuum energy (misleading title) and
Vacuum Energy Calculation using Path Integral.  I am not completely satisfied with the answers and it looks like they both have errors in their algebraic steps.  Since it has been asked twice, I hope you will look at my VERY DETAILED question which contains and exceeds the clarifications sought in these other questions.
I am using Zee's QFT book and he skipped over far too many steps in section II.5. My questions are about the missing steps.  They are in bold below.  (I think I will read through Zee's section III and then switch to a non-nutshell book but in the meantime I am working through it.)  Let $\varphi$ be a scalar field with ground state $|0\rangle$.  We have, by identity, the energy of the vacuum $E_{\text{vac}}$ as
$$ Z=\langle 0|e^{-i\hat H T} |0\rangle=e^{-iE_{\text{vac}}T} $$
and we want to determine exactly what $E_{\text{vac}}$ is.  We also let the time $T\to\infty$ so our integrals are over all of spacetime.  We write out $Z$ as the generating functional
$$ Z=\int D\varphi e^{    i\int d^4x\frac{1}{2}[(\partial\varphi)^2-m^2\varphi^2 ]      }  .$$
By a standard Gaussian identity and a magical procedure for "discretizing" infinite dimensional path integrals, and for some "non-essential" stuff $C$, we obtain
$$  Z=C\left( \frac{1}{\det [\partial^2+m^2]}  \right) =Ce^{ -\frac{1}{2}\text{Tr}\log(\partial^2+m^2)     } .$$
Therefore, setting the exponentials equal, the energy of the vacuum has the form
$$   iE_{\text{vac}}T \varphi=  \frac{1}{2}\text{Tr}\log(\partial^2+m^2)\varphi  .   $$
(Since $C$ has exponential dependence, this gives the additional energy $A$ obtained below.)  Now this is where Zee skips some steps.  He writes
$$ \text{Tr} \log(\partial^2+m^2)=\int \!d^4x\,\langle x|  \log(\partial^2+m^2)|x\rangle . $$
Is this an identity for the trace?  I kind of see that by the orthogonality of $|x\rangle$ and $|y\rangle$, we will only pick out the diagonal elements of the operator but he introduces this formula from nowhere.  He proceeds to solve the integral inserting the identity twice as
$$   \text{Tr} \log(\partial^2+m^2)= \int\!d^4x\int\!\frac{d^4k}{(2\pi)^4} \int\!\frac{d^4q}{(2\pi)^4} \langle x|k\rangle\langle k|  \log(\partial^2+m^2)   |q\rangle\langle q| x\rangle.   $$
What is $q$?  Is it momentum written as a second dummy variable akin to $(k,q)\sim (k_1,k_2)$?  As if by magic, Zee uses "we obtain" to write
$$  iE_{\text{vac}}T =\frac{1}{2} VT\int\!\frac{d^4k}{(2\pi)^4}  \log(k^2-m^2+i\varepsilon) +A   $$
WHAT HAPPENED HERE?  (How did he know to insert the identity two times?!?!)  I see we get $VT$ from $\int d^4x$, kind of.  I see the $i\varepsilon$ appeared magically in the usual way.  I don't see what else happened there.  Both of the above linked previous questions (Spinor vacuum energy and
Vacuum Energy Calculation using Path Integral) try to explain this, but I am not satisfied and I will begin my own computation. Assuming the trace identity, we have
\begin{align}
iE_{\text{vac}}T&=\frac{1}{2} \int\!d^4x\int\!\frac{d^4k}{(2\pi)^4} \int\!\frac{d^4q}{(2\pi)^4} \langle x|k\rangle\langle k|  \log(\partial^2+m^2)   |q\rangle\langle q| x\rangle.
\end{align}
Use $\langle x| k\rangle=e^{ikx}$, $\langle q| x\rangle=e^{-iqx}$, and $-i\partial|q\rangle=q|q\rangle$  to obtain
\begin{align}
&=\frac{1}{2} \int\!d^4x\int\!\frac{d^4k}{(2\pi)^4} \int\!\frac{d^4q}{(2\pi)^4} e^{ix(k-q)}\log(-q^2+m^2)  \langle k |q\rangle .
\end{align}
Now I use
$$\delta(k-q)=\int \frac{d^4x}{(2\pi)^4}e^{ix(k-q)}$$
to obtain
\begin{align}
&=\frac{1}{2} \int\!\frac{d^4k}{(2\pi)^4} \int \!d^4\!q\,\delta(k-q)\log(-q^2+m^2)  \langle k |q\rangle \\
&=\frac{1}{2} \int\!\frac{d^4k}{(2\pi)^4} \log(-k^2+m^2)  \langle k |k\rangle \\
&=\frac{1}{2} \int\!\frac{d^4k}{(2\pi)^4} \log(-k^2+m^2) .\\
\end{align}
If I proceed here, I do not get the correct answer.  Even if I add $i\varepsilon$ and use an identity for the complex logarithm, there's no way I could get $VT$.  The steps are worked out most clearly in Spinor vacuum energy, but I do not like what he has done.  For instance, his partial operator should have acted to the right to return $q$ but he has acted to the left to obtain $k$.  Seems like he messed up a factor of $(2\pi)^4$ as well.  Mostly my question is about why he delayed the creation of the Dirac delta until after the insertion of a third resolution of the identity.
 A: OP's calculation seems to match Zee's calculation; except for the final step. Here OP has made a mistake:
$$
\left< k | k \right> = (2 \pi)^4 \delta^{(4)}(0) \neq 1.
$$
This is where the factor of $VT$ comes from:
$$
\left< k | k \right> = \left<k | 1 | k \right> = \int d^4 x \left< k | x \right> \left< x | k \right> = \int d^4 x \; e^{-i k x} e^{i k x} = \int d^4 x = V T.
$$
Below are answers to OP's questions in the bold font.

It is a very well known technique from ordinary quantum mechanics to insert resolutions of identity
$$
1 = \int d^d x \left| x \right> \left< x \right|
$$
and
$$
1 = \int \frac{d^d p}{(2\pi)^d} \left| p \right> \left< p \right|
$$
in operator equations. Since both are equal to one, they can be inserted anywhere one desires.
Both operators above act on $L_2(\mathbb{R}^d)$. The notation may be a bit confusing to mathematicians, because $\left| x \right>$ itself doesn't belong to $L_2(\mathbb{R}^d)$, but to the distribution space. However, physicists use this bra-ket notation all the time.
The distributional nature of kets is also the reason a singularity equal to the infinite spacetime volume appears in $\left< k | k \right>$. Squares of distributions are always ill defined and care must be taken to make sure the resulting theory makes sense nevertheless.

W.r.t. traces. The identity he uses is:
$$
\text{tr} (\left| \psi \right> \left< \chi \right|) =
\left< \chi | \psi \right>.
$$
This is almost by definition of the trace. Expand both vectors in some orthonormal basis and write the trace explicitly:
$$
\text{tr} (\left| \psi \right> \left< \chi \right|) =
\left| \psi \right>_a \left< \chi \right|_a =
\left< \chi \right|_a \left| \psi \right>_a = \left< \chi | \psi \right>.
$$

W.r.t. $k$ and $q$ – they are both just mathematical symbols in the momentum-space resolution of identity. We're allowed to insert as many resolutions as we please, and he chose to insert two.
It is a well-known fact from the theory of Fourier integrals that
$$
\left< x | k \right> = e^{i k x},
$$
and so
$$
\partial_{\mu} \left| k \right> = i k_{\mu} \left| k \right>.
$$
He uses it later to put a differential operator into algebraic form.
