1

Is there a sure-fire method to cut & paste word-wrap on X-based terminals? That is, if I select, then paste via button-3, if the text goes to the end of the line and wraps, the paste assumes carriage return and inserts it. I'd rather:

if (endcolumn==non-space character) {
  assume wordwrap
}
else {
  insert carriage return after last non-space character
}

This drives me crazy. Especially when pasting code that is > 80 columns. Sometimes it works, most of the time it doesn't.

2
  • since the clicknpaste action is something that is controlled by the terminal .. which one do you use?
    – akira
    Feb 11, 2011 at 18:48
  • Most often I'm in gnome-terminal. Feb 14, 2011 at 15:33

2 Answers 2

1

Unix terminals don't do word wrap. This is a feature of the application running inside the terminal. The terminal receives the same instructions to display

|This is text formatted  |        |This is line 1.         |
|to 24 columns           |   or   |This is line 2.         |

If you can, tell your application not to do any wrapping. This way the terminal will wrap, but always on the last column.

|This is a single long li|
|ne of text.             |

If you triple-click on this, you get This is a single long line of text with a newline only at the end (or no newline at all depending on the terminal emulator).

When pasting, the terminal just sends the text to the application, as if you had typed it. If you observe any behavior such as wrapping that depends on the terminal width, it's due to the application, not to the terminal.

1
  • You are right, this is not a function of terminals. Incidentally, KDE Konsole has functionality (that you can enable, in advanced) where triple-click selects only to the end of the line. This is really useful to grab a command after your prompt without having to grab the whole line. Nov 17, 2014 at 15:40
0

I agree this makes a huge difference in usability. I find it very important to be able to triple-click and copy/paste lines which have wrapped. There are two ways this can work correctly. Either triple-click (and click drag) selects past the end of line onto the next visible line, with no CR inserted. Or else triple click selects only one visible line, but when you paste it, there is no CR.

The broken way is when triple-click selects only the visible line, and then it assumes a CR at the end when it pastes. I have seen bad behavior from xterm and gnome terminal. I've seen good behavior from Mac Terminal app, and from iTerm which is another Mac terminal app.

I have no hints for turning a bad situation into a good one other than trying a different terminal program. I'm certain this ties into whether the terminal program actually remembers the locations of all the CRs it sees, or whether it simply interprets the CR and then forgets it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .