It happens that text copied form a terminal and pasted into nano ends up like this:

auto host0
iface host0 inet static

There is apparently a problem in how the combo shell (fish in my case, but this also happens with bash) + editor handle line returns. Interestingly enough, in my example above the first two lines whre handled correctly (that is, the first line return).

The same file open with vi allows for a normal paste (the format of the file is preserved).

What is the setting which manages this behaviour?


Traditionally, pasting into terminal emulators used to be nothing more than pretending that the user quickly type the given letters from the keyboard. Combined with the autoindent feature of many editors (e.g. nano -i), if the pasted (pseudo-"typed") text contains spaces or a TAB at the beginning of each line, this obviously results in increasing indentation, that is, the so-called staircase effect that you see.

One possible way to avoid this is to disable autoindent for the duration of pasting. Consult nano's documentation to see if it's possible to toggle this setting runtime, I don't know.

Recently most terminal emulators have introduced "bracketed paste mode" to improve this situation. This is a special mode that applications (e.g. vim, nano) might enable, and instructs the terminal emulator to enclose the pasted text between special control symbols. One of the main intents is for text editors to automatically disable autoindent when this happens, that is, to avoid the staircase effect. At this moment I can't see any sign of nano supporting this. The feature request is filed here, maybe you could ask the developers if they're planning to address this.

  • Thank you. I did not realize that this was a feature of the editor and not a problem with handling newlines. When starting nano without autoindent the pasted text was correct. I will consider another editor (maybe go back to joe which was my editor for so many years) – WoJ May 3 '17 at 14:04
  • Haha, I've been using joe for like 20 years now... and yes, it supports bracketed paste mode :) – egmont May 3 '17 at 14:06
  • 20 years of joe ... that would be more or less me as well. Moved from Wordprint (I hope that this is the right name of the DOS editor, I guess so) so the key bindings were easy. I do not recall why I moved to nano a few years ago but the more I use it, the less I like it. – WoJ May 3 '17 at 14:11
  • Wasn't it "wordstar"? Whatever... – egmont May 3 '17 at 14:13
  • 1
    now I remember, it was WordPerfect – WoJ May 3 '17 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.