Edit: It looks like my answer below is completely unnecessary since TikZ has a standard name prefix
key that acts much the same way as what I wrote (although it doesn't separate with the prefix from the name with spaces).
The manual has this to say about the name prefix
key:
The value of this key is prefixed to every node inside the current
scope. This includes both the naming of the node (via the name key or
via the implicit (⟨name⟩) syntax) as well as any referencing of the
node. Outside the scope, the nodes can (and need to) be referenced
using “full name” consisting of the prefix and the node name.
The net effect of this is that you can set the name prefix at the
beginning of a scope to some value and then use short and simple names
for the nodes inside the scope. Later, outside the scope, you can
reference the nodes via their full name:
\tikz {
\begin{scope}[name prefix = top-]
\node (A) at (0,1) {A};
\node (B) at (1,1) {B};
\draw (A) -- (B);
\end{scope}
\begin{scope}[name prefix = bottom-]
\node (A) at (0,0) {A};
\node (B) at (1,0) {B};
\draw (A) -- (B);
\end{scope}
\draw [red] (top-A) -- (bottom-B);
}
Using built-in functionality is almost certainly the best choice.
Original answer:
Loop Space gave a nice answer that works as long as you don't need to refer to the nodes by their unprefixed names.
For example, if you add a \draw (u) -- (v);
inside each of those scopes, you get the somewhat mysterious error, Package pgf Error: No shape named u is known.
A better option is to change the definition of prefix node name
to not change how names are recorded but to add an alias with the prefix.
\tikzset{
prefix node name/.style={%
/tikz/name/.append style={%
/tikz/alias={#1 ##1}%
}%
}
}
In essence, adding prefix node name=foo
to a scope will cause all name=bar
inside the scope to act as if it were name=bar,alias={foo bar}
.
Here's a modification of Loop Space's example using the above definition of prefix node name
and a slight modification to the picture (so the nodes aren't on top of each other) and with some \draw
s added to show the effect.
\documentclass{article}
\usepackage{tikz}
\tikzstyle{vertex}=[circle,draw,fill=black!20]
\tikzset{
prefix node name/.style={%
/tikz/name/.append style={%
/tikz/alias={#1 ##1}%
}%
}
}
\begin{document}
\begin{tikzpicture}
% ---- Copy 1
\begin{scope}[yshift=32pt,prefix node name=G1]
\node[vertex] (u) at (0, 0) {u};
\node[vertex] (v) at (2, 0) {v};
\draw (u) -- (v);
\end{scope}
% ---- Copy 2
\begin{scope}[yshift=-32pt,prefix node name=G2]
\node[vertex] (u) at (0, 0) {u};
\node[vertex] (v) at (2, 0) {v};
\draw (u) -- (v);
\end{scope}
\draw[->] (G1 u) -- (G2 v);
\end{tikzpicture}
\end{document}

name
key in a style that reads the name of the scope and adds the name to it. But then you have to supply names in the options. It can be possible to hack into the naming but the question then becomes is it worth it. Also if you are feeling adventurous you can have a look at the OOP section in the manual.