How do I understand this direct limit? As in Hartshorne page 72, we defined the morphism between locally ringed spaces, say $(f,f^{\sharp})$ is a morphism between $X$ and $Y$. Then we have, for all $P\in X$, an induced homomorphism between local rings, $f^{\sharp}_P:O_{Y,f(P)}\rightarrow O_{X,P}$.
To define this induced homomorphism, we note that for all open neighborhoods, $V$, of $f(P)$, $f^{-1}(V)$ is an open neighborhood of $P$. Then $f^{\sharp}$ defines a homomorphism, $f^{\sharp}: O_Y(V) \rightarrow O_X(f^{-1}(V))$.
Then by taking direct limit over all such $V$, we have a ring homomorphism, $O_{Y,f(P)} \rightarrow \varinjlim O_X(f^{-1}(V))$.
Now, my question is how do I understand this direct limit? Suppose $X=\operatorname{Spec}A$ and $Y=\operatorname{Spec} B$ and the morphism is induced by ring homomorphism $\phi:B \rightarrow A$, is it true that the direct limit above is $A\otimes_{B}B_{\phi^{-1}(P)}$? If it is true how to prove it? A complete proof will be greatly appreciated.
 A: You are correct, the direct limit $\varinjlim\mathcal{O}_X(f^{-1}(V))$ is essentially given by $A\otimes_B B_{\phi^{-1}(P)}$ (once you shrink to affine opens containing $P$ and $f(P)$). Here's a proof.
First, observe that when $X$ and $Y$ are schemes, it suffices to understand the affine case. Choose an affine open neighborhood $\operatorname{Spec}(B)\subseteq Y$ of $f(P)$ and an affine open neighborhood $\operatorname{Spec}(A)\subseteq X$ of $P$ with $\operatorname{Spec}(A)\subseteq f^{-1}(\operatorname{Spec}(B)).$ Then we have $\mathcal{O}_{X,P} = \mathcal{O}_{\operatorname{Spec}(A),P}$ and $\mathcal{O}_{Y,f(P)} = \mathcal{O}_{\operatorname{Spec}(B),f(P)}.$
So, let us assume that $X = \operatorname{Spec}(A)$ and $Y = \operatorname{Spec}(B),$ and that $f : X\to Y$ comes from the morphism $\phi : B\to A$ of rings. Let $\mathfrak{p}\subseteq A$ be the prime ideal of $A$ corresponding to the point $P\in X,$ and let $\mathfrak{q} = \phi^{-1}(\mathfrak{p})$ be the prime ideal of $B$ corresponding to $f(P).$ Since distinguished opens $D(b)$ with $b\in B$ form a basis for the Zariski topology on $Y,$ we may compute the direct limit defining the stalk as
\begin{align*}
\varinjlim_{D(b)\ni f(P)} \mathcal{O}_{\operatorname{Spec}(B)}(D(b)) &\cong \varinjlim_{b\not\in\mathfrak{q}} B[b^{-1}]\\
&\cong B_\mathfrak{q}.
\end{align*}
Now, the direct limit we want to compute is
$$
\varinjlim_{D(b)\ni f(P)}\mathcal{O}_{\operatorname{Spec}(A)}(f^{-1}(D(b))).
$$
We have $f^{-1}(D(b)) = D(\phi(b)),$ so this simplifies as
\begin{align*}
\varinjlim_{D(b)\ni f(P)}\mathcal{O}_{\operatorname{Spec}(A)}(f^{-1}(D(b))) &= \varinjlim_{b\not\in\mathfrak{q}}\mathcal{O}_{\operatorname{Spec}(A)}(D(\phi(b)))\\
&\cong \varinjlim_{b\not\in\mathfrak{q}} A[\phi(b)^{-1}].
\end{align*}
Putting all this together using the fact that the tensor product commutes with colimits, it follows that
\begin{align*}
A\otimes_B B_\mathfrak{q} &\cong A\otimes_B \varinjlim_{b\not\in\mathfrak{q}} B[b^{-1}]\\
&\cong \varinjlim_{b\not\in\mathfrak{q}}\left(A\otimes_B B[b^{-1}]\right)\\
&\cong \varinjlim_{b\not\in\mathfrak{q}}A[\phi(b)^{-1}]\\
&\cong \varinjlim_{D(b)\ni f(P)}\mathcal{O}_{\operatorname{Spec}(A)}(f^{-1}(D(b))).
\end{align*}

EDIT: As requested, we shall prove that the localization of a ring can be interpreted as a suitable colimit.
Let $A$ be a commutative ring, and let $S\subseteq A$ be a multiplicative set. Consider $S$ as a category whose objects are elements of $S,$ and whose hom-sets are given by
$$
\operatorname{Hom}_S(s,t) = \begin{cases}\ast,\qquad\textrm{if there exists }u\in A\textrm{ such that }t = su,\\
\emptyset,\qquad\textrm{otherwise}.
\end{cases}
$$
Then we may define a functor from $S$ to the category of commutative rings (or even commutative $A$-algebras, if you want) by
\begin{align*}
F : S&\to\mathsf{CRing}\\
s&\mapsto A[s^{-1}]\\
(s\to t)&\mapsto\left(A[s^{-1}]\to A[t^{-1}]\right).
\end{align*}
The map $A[s^{-1}]\to A[t^{-1}]$ is simply further localization: $A[t^{-1}]\cong (A[s^{-1}])[u^{-1}].$
Now, we want to show that the colimit of the diagram defined by this functor is the localization $S^{-1}A.$ That is, we want to show
Lemma: With notation as above,
$$\varinjlim_{s\in S} A[s^{-1}]\cong S^{-1} A.$$
Proof: We need to check that the colimit in question has the correct universal property; i.e., we must prove that given any morphism of rings $f : A\to T$ such that every element of $S$ is sent to a unit in $T,$ that we have a unique factorization of $f$ as $A\to \varinjlim_{s\in S} A[s^{-1}]\xrightarrow{f_S} T,$ where the first map is the canonical map.
By the universal property of localization, we find that for each $s\in S,$ $f$ factors uniquely as $A\to A[s^{-1}]\xrightarrow{f_s} T.$ Moreover, if $t\in S$ and $t = su,$ then we find that $f_t$ and $f_s$ are compatible in the sense that the composition
$$
A[s^{-1}]\xrightarrow{\textrm{can}} A[t^{-1}]\xrightarrow{f_t} T
$$
is simply $f_s.$
To see why the above is true, observe that $A[t^{-1}]$ is a localization of $A[s^{-1}]$ and $t\in A[s^{-1}]$ is sent to a unit in $T$ via $f_s,$ so there is a unique map $g : A[t^{-1}]\to T$ such that $f_s : A[s^{-1}]\to T$ factors through $g$ as $$A[s^{-1}]\xrightarrow{\textrm{can}}A[t^{-1}]\xrightarrow{g} T.$$ However, the composition $A\to A[s^{-1}]\xrightarrow{f_s} T$ is $f : A\to T,$ and the composition $A\to A[s^{-1}]\xrightarrow{\textrm{can}} A[t^{-1}]$ is simply the localization away from $t.$ Thus we see that $g$ satisfies the same property that $f_t$ does, and so uniqueness implies that $g = f_t.$
However, this compatibility between the various $f_s$ is precisely what is needed to obtain the map $\varinjlim_{s\in S} A[s^{-1}]\to T$ -- the universal property of a colimit now gives us a unique map $f_S : \varinjlim_{s\in S} A[s^{-1}]\to T$ factoring our given $f : A\to T,$ which is precisely what we needed. $\square$
