Frankly, that's a very confusing way to derive the Nernst equation. I also think that either the book has a typo in it or you miscopied it. So you know that delta G= delta G0 + RTlnQ. So delta G = -nFE and delta G0 = -nFE0. Sub those in and divide through by -nF. You get E = E0 - (RT/nF)lnQ. That's the general form of the Nernst equation. Note that n here refers to the number of moles of electrons that move around in the reaction (e.g. if LiCl to Li+ + Cl- is a one-electron process - you take an electron from Li and put it on Cl).
What you wrote is the equilibrium Nernst equation. At equilibrium, delta G = 0. Thus, E = 0 by delta G = -nFE. The Nernst becomes: 0 = E0 - (RT/nF)lnK (replacing Q with K to signify equilibrium conditions). That's where you get E0 = (RT/nF)lnK.
What I just discussed above can be used in any electrochemical cell.
Now, you're talking specifically about a membrane here. So you can imagine your "reaction" as an ion from inside the cell moving outside the cell. So ion(inside) ----> ion(outside). So your equilibrium constant for this "reaction" is ion(outside)/ion(inside). The charge that is moving around in the "reaction" is the charge on the ion, z (you can imagine it as electrons moving around if you like). So, just inserting those variables, you get E0 = (RT/zF)ln(ion outside/ion inside).