Another derivation of canonical position-momentum commutator relation I am reading Martin Plenio's lecture notes on Quantum Mechanics from the Imperial College. In page 63 he wants to prove the relation
$$[\hat{x},\hat{p}]=i\hbar $$
via
$$\langle x | [\hat{x},\hat{p}]|\psi\rangle=\langle x | \hat{x}\hat{p}-\hat{p}\hat{x}|\psi\rangle  \overset{?}{=} \langle x | i\hbar|\psi\rangle.\tag{1}$$
I have proven that
$$\langle x | \hat{p}|\psi\rangle = \frac{\hbar}{i}\frac{\partial}{\partial x}\langle x |\psi\rangle.$$
From (1) I get
$$\langle x | \hat{x}\hat{p}-\hat{p}\hat{x}|\psi\rangle = x \langle x | \hat{p}|\psi\rangle - \langle x | \frac{\hbar}{i}\frac{\partial}{\partial x}\left(\int dx\ x|x\rangle\langle x|\psi\rangle\right),$$
where 
$$\hat{p} = \frac{\hbar}{i}\frac{\partial}{\partial x}$$
and 
$$\hat{x} = \int dx\ x |x\rangle\langle x|.$$
If I could get the bra $\langle x |$ into the integral then I would get
$$x \langle x | \hat{p}|\psi\rangle - \frac{\hbar}{i}\frac{\partial}{\partial x}\left( x\langle x|\psi\rangle\right),$$
which would lead to the desired result. However I don't see how getting the bra into the integral would be possible. Any help is appreciated (I have seen the proof in other questions here, but they take $|\psi\rangle$ as an eigenvector of $\hat{x}$). How could I make progress with this way of proving the relation? Any help is very much appreciated!
 A: Although I like knzhou's answer, I'd write it slightly differently. Start with the identtity
$$ {\cal I} = \int |x'\rangle \langle x'| dx' , $$
which one then inserts into the second expression in (1)
$$  \int \langle x| (\hat{x}\hat{p}-\hat{p}\hat{x})(|x'\rangle \langle x'|) |\psi\rangle dx' $$
Next we define the wave function $\langle x'|\psi\rangle = \psi(x')$, so that we get
$$ \int \langle x|x'\rangle (\hat{x}\hat{p}-\hat{p}\hat{x})\psi(x') dx' $$
Then we get the Dirac delta which removes the integral
$$ \int \delta(x-x') (\hat{x}\hat{p}-\hat{p}\hat{x})\psi(x') dx' = (\hat{x}\hat{p}-\hat{p}\hat{x})\psi(x) . $$
Express the operators in terms of their definitions and then evaluate the derivatives
$$ x (-i\hbar)\partial_x \psi(x) - x (-i\hbar)\partial_x [x\psi(x)] = i\hbar \psi(x) . $$
The result is the same as $\langle x|i\hbar|\psi\rangle$. Still pendantic, but not painfully so. :-)
A: The problem is that several $x$'s are being mixed up. Let me rewrite part of your first result making the distinction clear. 
Suppose we want to simplify the quantity
$$\langle x | \hat{p} \hat{x} | \psi \rangle.$$
We first use the identity
$$1 = \int dx' |x' \rangle \langle x'|$$
and insert this 'factor of $1$' into the expression, to get
$$\langle x | \hat{p} \hat{x} | \psi \rangle = \langle x | \hat{p} \hat{x} \left( \int dx' | x' \rangle \langle x' | \psi \rangle \right).$$
Here, $x'$ is an integration variable.
Next, we act with the $\hat{x}$ operator to get
$$\langle x | \hat{p} \left( \int dx' x' | x' \rangle \langle x' | \psi \rangle \right).$$
Now we need to act with the $\hat{p}$ operator. As you stated in your post, this operator differentiates the coefficient of $| x' \rangle$, giving
$$\langle x | \left( \int dx' \frac{\partial}{\partial x'} \left( x' \langle x' | \psi \rangle \right) | x' \rangle \right).$$
Finally, we act with the bra $\langle x| $, using the result
$$\langle x | x' \rangle = \delta(x-x').$$
This simplifies the integral to
$$\int dx' \delta(x-x') \frac{\partial}{\partial x'} \left( x' \langle x' | \psi \rangle \right) = \frac{\partial}{\partial x} \left( x \langle x | \psi \rangle \right).$$
From this point onward, the rest of the derivation is ordinary calculus. In practice, you probably wouldn't want to be as pedantic as I'm being above (this is a really slow way of doing it), but mixing up the $x$'s can be very confusing the first time around.

Let me explain the action of $\hat{p}$. Start from the expression you know,
$$\langle x| \hat{p} | \psi \rangle = \frac{\hbar}{i} \frac{\partial}{\partial x} \langle x | \psi \rangle.$$
This equation is saying that the $|x \rangle$ component of $\hat{p} | \psi \rangle$ is the right-hand side. That is, $\hat{p} |\psi \rangle$ itself is
$$\hat{p} | \psi \rangle = \frac{\hbar}{i} \int dx \frac{\partial}{\partial x} \left( \langle x | \psi \rangle\right) |x \rangle.$$
Note that here, I'm not using $x'$ notation, because there's only one kind of $x$ involved. Some people like to always put a prime for an integration variable, though.
What this equation is saying is that $\hat{p}$ acts on $|\psi \rangle$ by differentiating the $|x \rangle$ component of $|\psi \rangle$. However, this is totally independent of the fact that $|\psi \rangle$ is the state of your system; this is simply how $\hat{p}$ acts on all vectors. (In fact, this is a common way to define $\hat{p}$ in the first place.) This is exactly what we did above, where the $|x'\rangle$ component of our vector in parentheses was $x' \langle x' | \psi \rangle$.
