Package listings can do that for you.
Let us define the option escapeinside={*@}{@*} with command \lstset. Then you can use is with *@\label{tes:line7}@* for example to set a label for line 7 of your given code (I just use a tex code here, called \jobname-mwe.tex)
Then you can refer to that label with
In line~\ref{tes:line7} you see
With the command
\lstinputlisting[firstline=1,lastline=7]
you define that you want to display only the lines from 1 to 7. Later you can continue with
\lstinputlisting[firstline=9,firstnumber=10]{\jobname-mwe.tex}
displaying 9 and following ...
Complete MWE
\RequirePackage{filecontents}
\begin{filecontents*}{\jobname-mwe.tex}
\documentclass[%
toc=flat, % No intention in toc
toc=listof, % figures and tables in toc
headsepline, % line between head and text *@\label{tes:line7}@*
]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{scrlayer-scrpage}
\lohead{John Doe}
\rohead{Example for tex-stackexchange.com}
\pagestyle{scrheadings}
\usepackage[math]{blindtext}% dummy text with formulas
\begin{document}
\tableofcontents% Table of content
\listoffigures% List of figures
\Blinddocument% includes dummy document
\begin{figure}%
\includegraphics[width=\columnwidth]{example-image-a}% *@\label{tes:line27}@*
\caption{Test image from package mwe}% install package mwe!
\label{fig:ex-a}%
\end{figure}
\blindtext
\begin{figure}%
\includegraphics[width=\columnwidth]{example-image-b}%
\caption{Test image from package mwe}%
\label{fig:ex-b}%
\end{figure}
\blindtext
\end{document}
\end{filecontents*}
\documentclass{scrartcl}
\usepackage{listings}
\usepackage{xcolor}
\lstset{%
basicstyle={\ttfamily},
frame=l,
xleftmargin={0.75cm},
numbers=left,
stepnumber=1,
firstnumber=1,
numberfirstline=true,
language={TeX},
tabsize=2,
showtabs=false,
showspaces=false,
showstringspaces=false,
extendedchars=true,
breaklines=true,
escapeinside={*@}{@*}
}
\begin{document}
Complete listing:
\lstinputlisting{\jobname-mwe.tex}
\clearpage
The following lines lines shows how to~\dots In line~\ref{tes:line7} you see
\lstinputlisting[firstline=1,lastline=7]{\jobname-mwe.tex}
The following lines shows that \dots In line~\ref{tes:line27} you see
\lstinputlisting[firstline=9,firstnumber=10]{\jobname-mwe.tex}
\end{document}
gives you the second page:

enumitempackage allows\begin{enumerate}[resume], without stashing the counter. Also, you can control the indent and format of each counter, as well as spacing between each item. – Sandy G Oct 24 '17 at 22:55