Closed immersion being an affine-local property on the target. Assume that $f : X \rightarrow Y$ is a morphism of schemes. Then prove that $f$ is a closed immersion if-f there is an affine cover of $Y$ say $\{ U_i \}$, such that the induced scheme morphisms $f^{-1}(U_i) \rightarrow U_i$, is a closed immersion $ \forall \thinspace i \in I$.
(The above is an exercise from Vakil's notes)
 A: 
Lemma/Definition 1: Let $\operatorname{Spec} B \rightarrow \operatorname{Spec} A$ be a morphism of affine schemes induced from $A \rightarrow B$, this is a closed immersion iff $A \rightarrow B$ is a surjective ring homomorphism. 

Let us use the Affine communication lemma, 5.3.2, pg. 158. We define property $P$ by

Definition 2: $\operatorname{Spec} A \hookrightarrow X$ has property  $P$ iff the induced $\operatorname{Spec} B = \pi^{-1}\operatorname{Spec} A \rightarrow \operatorname{Spec} A$ is a closed embedding. 

Now we check the conidtions. 
(i) We show if $ \varphi:A \rightarrow B$ is a surjection, then $A_f \rightarrow B_{\varphi f}=B \otimes A_{f}$ is a surjection for all $f \in A$. This follows as $\otimes A_f$ is right exact. 
(ii) We show if $A_{f_i} \rightarrow B_{\varphi f_i}=B \otimes A_{f_i}$ is surjective for all $f_i$ with $\langle f_1, \ldots, f_n \rangle =A$, then $A \rightarrow B$ is surjective. This then follows from the the two general propositions below. 

Affine communication lemma then implies the property holds for all affine open. 


Prop 1: If $M \rightarrow N \rightarrow P$ is an exact sequence of $A$ modules, then it is exact iff it is so when localize at all maximal ideals. 
Proof: This follows from combining two observations:  
a) $M=0$ iff $M_{m}=0$ for all maximal ideals of $A$. 
b) localization is exact. So homology of the chain complex of $A$-modules commutes with localization.
Prop 2. $M_m=0$  for all $m$ maximal ideal of $A$ iff $M_{f_i}=0$  for all $i$  where $\langle f_1, \ldots, f_n\rangle =A$. 
Proof: One direction follows from a) of Prop 1. Let $m$ be any maximal ideal, there must exist some $f_i$ not in $m$. Thus $M_m \cong (M_{f_i})_m =0$. 

