With the mouse-scrolling selection in the "Alacritty" terminal, and
C for copy, it worked. This has nothing to do with the editor you use (less, vim or whatever), since the output of the editor is embedded in the terminal text in "Alacritty".
I needed to do this as well on an old legacy server that I entered using ssh, to get quite a few pages of log text of a file copied to my system. I wanted this to be done without sending that file around, just with the clipboard.
Sorry, command-not-found has crashed! so that I cannot use
less myfile | xclip.
When opening the file in vim that is installed (outdated 2012 version), checking
:version, I see
-X11, so that I cannot copy to the system clipboard:
I can mark text with the mouse, holding shift, and copy with the right-click menu of the terminal, yet, I cannot scroll while doing so, so that I cannot copy many pages of text in one go.
I then got the hint to use a terminal called "Alacritty" to ssh into the server. And yes, this program has the advantage that it shows the opened text file together with the code that opened it so that you do not have a new vim window. In other words: you keep the vim text in the terminal even if you quit vim again. That again gives you the chance to use terminal tools that you do not have in vim, which in "Alacritty" are also to use the mouse for marking and scrolling at the same time. I can therefore press
G as the vim key to get to the end of the file (only then, it is also loaded in the terminal text), then scroll back or type
:1, mark item 1 of the first line of the file, hold that marking mouse-click, and scroll down to the end so that everything is marked just with the mouse (copying will not work when using vim keys like
ggVG), then press
C and paste it in my system. There is also a way to zoom out in "Alacritty", then you could copy all of the text without scrolling, but I could not set it up.