Linux gnu less: long lines in buffer are broken on copy + paste

On one of my Linux machines, I create a long string and pass it to gnu less:

seq -w 1 999 | xargs echo | less 

If I select the text that appears from gnu less (version 394) and copy + paste it somewhere else, the long line is split into several lines, each until the terminal width is not what I expected .

If I do the same in another Linux block (less than version 444), I can select gnu less from the buffer and copy + paste it somewhere else as one long line, which is the desired behavior. See Image:

enter image description here

The effect of sticking on emacs, an effect starting over, the desired effect below:

enter image description here

In both linux blocks, if I use cat instead of a smaller size and select from the output in the terminal, I can also copy + paste everything into one line:

 seq -w 1 999 | xargs echo > /tmp/f cat /tmp/f 

In contrast, in both linux blocks, the more command behaves the other way around, also breaking a long line into several lines when choosing to copy + paste:

 seq -w 1 999 | xargs echo > /tmp/f more /tmp/f 

Any ideas what could happen? How can I copy + paste from gnu less buffer with the same consistent behavior that I see when I make cat ?

+6
source share
4 answers

I compiled a newer version less, and now it behaves as expected.

+2
source

less has the -S option, which tells it to break long lines. It is not enabled by default.

Fortunately, most less flags can be changed even when they are launched. Just press -S to switch the long line / polyline mode

+2
source

Let me answer the part of the question “what is happening” without referring to the part “how to fix”. The main difference between cat and less or more from your final point of view is the mode of operation. When you cat something, the terminal sees the actual characters, and when it reaches the end of the line, the responsibility for emulating the terminal lies with the terminal emulator. Modern terminal emulators remember whether they made such line breaks for each line, and when you copy text, line breaks are not included in the copy buffer.

Now less and more use your terminal in a completely different way (with ncurses). These tools are aware of the width of the terminal and will not cause line breaks when line overflows. They will release the line themselves. Your terminal emulator cannot distinguish such a line break from a “significant” line break, so when copying text, these line breaks are included in the copy buffer.

You can ask more not to include these line breaks with the -f option, but for less corresponding option does not exist mainly because you can scroll backward.

+2
source

this can be done using vim:

afaik, the only drawback is that vim opens large files (tens of megabytes) more slowly than smaller ones. although this can be fixed, see http://vim.wikia.com/wiki/Faster_loading_of_large_files .

+1
source

Source: https://habr.com/ru/post/953702/


All Articles