Skip to content
Advertisement

mouse select copy from “vim” and “less” show different results

Case1: Open file1 in vi. Select a few lines(select copy is enabled). Paste in a different place. Case 2: run the command less file1. From the console, select some lines. Paste in a different place.

In case2, I see that there are new lines introduced at where the line display shifts to new line. So, if the terminal width is 80 characters and my line is 100 characters, then 20 characters will be shown in the new line. If I copy from vim, all 100 characters are copied without any line-break. However, if I copy from “less” command, line-break is introduced after 80th character.

This messes up things like path.

Does “less” introduce line-break dynamically for lines longer than the display width?

Advertisement

Answer

less is not designed to handle mouse events. So when you select text while running it, the selection will be handled by the terminal behind, which doesn’t give any sense to lines, paragraphs and so on; the text buffer is copied as it is displayed, that’s all.

On the opposite, if you use vim with the right configuration, mouse events will be detected and treated by vim itself : the terminal will gracefully let vim handle them, for convenience. Then the line layout will be restored correctly when copying lines of text.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement