I am pretty sure I read something about this before, but I can not find it. Mark it as a duplicate if so please.
I am coding inside lstlisting environment using SPACEBAR for separate words and TAB for indent code. Check this MWE:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\usepackage[spanish]{babel}
\newcommand\opstyle{\bfseries\color{red}}
\makeatletter
\usepackage{xcolor,textcomp}
\usepackage{enumitem}
\usepackage{textcomp}
\usepackage{listings}
\usepackage{accsupp}
\usepackage{lmodern}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstset { %
language=C++,
alsoletter=0123456789,
upquote=true,
columns=fullflexible,
keepspaces=true,
backgroundcolor=\color{backcolour},
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lst@AddToHook{OutputOther}{\ProcessOther@silmeth}
\newcommand\ProcessOther@silmeth
{%
\ifnum\lst@mode=\lst@Pmode% % If we're in `Processing' mode...
\def\lst@thestyle{\opstyle}% % ... redefine the style locally
\fi%
}
\makeatother
%========================== Taken from https://tex.stackexchange.com/a/442600/152550
\newcommand{\noncopynumber}[1]{%
\BeginAccSupp{method=escape,ActualText={}}%
#1%
\EndAccSupp{}%
}
\makeatletter %================= Taken from https://tex.stackexchange.com/a/19978/152550
\def\lst@outputspace{{\ifx\lst@bkgcolor\empty\color{white}\else\lst@bkgcolor\fi\lst@visiblespace}}
\makeatother
\begin{document}
\begin{lstlisting}
Example with no tabulation
With one tabulation
With one space
\end{lstlisting}
\end{document}
The output with selected text:
When I paste it anywhere, it turns on the spaces:
This way a compiler could never compile correctly.
Is there an easy way to keep spacing but no with this symbol: ␣?
Thanks!
P.D: I also take a look at the manual, section 2.5 Special characters - Visible tabulators and spaces but it does not say anything about this problem. Also I take a look at section 7, How tos - How to gobble characters.


char linewill not work) and some PDF readers (like Mac's preview) will copy a visible space. It works under Acrobat Reader and it's extremely pleasant to be able to quickly copy/paste code without problem”. Also, on another note, please usebasicstyle=\ttfamilyto display source code. – Ruixi Zhang Jul 22 '18 at 01:59