Keep line endings on paste (no LF to CRLF or CRLF to LF)?



  • Hi NPP community.
    First of all this is great software that I’ve been using daily for many years now, thx for developping it !

    As the title suggests, I’d like to know how to paste content from one file to another without having the line-endings automatically converted to whatever the destination file mode is.
    If I copy/paste a snippet from a unix (LF) file to a windows one (CRLF), the line-endings are automatically converted to CRLF and I think NPP should make it possible to disable this behavior.

    My use case is the following : I’m working with Git, trying to manually apply a patch which affects multiple files. Those files can either be LF or CRLF as the repo contains code for linux and for windows, resulting in a mixed line-endings patch.
    That patch being very big, I need to cut/paste parts of it from one file to another to keep track of my progress.

    But NPP keeps messing with line-endings, making parts of my copy/pasted patch broken as I can’t apply those cleanly to my repo.

    I understand the current behavior is what’s needed in most conventional use cases, but adding an option to leave line-endings untouched on copy/paste would make my life so much easier right now.
    Any chance this issue might be addressed at some point ?

    U guys have a nice dev.
    Fointard



  • welcome to the notepad++ community, @Fointard

    you have various options to preserve, convert or mix your line endings in notepad++:

    • if you want to preserve the line endings while copying a snippet from a linux file, open the source file in notepad++, select the section you need, and go to edit > paste special > copy binary content as seen at the screenshot below.
      then use edit > paste special > paste binary content on the other file, where you want to paste this snippet.

    Imgur

    • if you want to use the default copy paste, you can switch your current windows document to unix lf, before pasting your linux eol clipboard content to it.
      double click on windows (cr lf) at the lower right of the notepad++ status bar, and select unix (lf) as seen at the screenshot below.

    Imgur

    • if you want to convert your whole new document, where you have pasted the unix (lf) content to, after pasting, go to edit > eol conversion > unix (lf)

    Imgur

    i hope this is of service to you.



  • THANK YOU @Meta-Chuh
    You just saved my day (and you did it quick !).
    That “Paste binary content” was all I needed. Now what I need is a macro/shortcut that will automate my workflow but that’s the easy part.

    Thank you again, long live NPP !



  • @Meta-Chuh ,

    Thank you!

    I had never noticed the Edit > Paste Special binary options. My very first question here was because NUL characters were getting converted to spaces when going through the copy buffer; at the time (v6.8.6), we had to do a regex/copy-paste/anti-regex sequence to protect certain characters.

    My three-year-old question now has the correct, built-in answer.

    Now I’m curious when it was added: per a search of the commits, “Paste Binary Content” was included in March 2011, which was long before the Oct 2015 v6.8.6 release. Looking through release history based on dates, and then confirming with release page: v5.9 included Copy/Cut/Paste Binary Content feature for the first time.

    Apparently, the regulars either didn’t think of it when I asked the question, or didn’t know about it / hadn’t used it. Maybe it was because I couched the original question in TextFX conversions.

    Time to go re-vivify the topic briefly.



  • you’re very welcome @PeterJones and thanks for the thanks from teacher to alumnus 😃👍

    last time i recall copy paste binary content was mentioned, was a pregnancy ago, after i found out that @chcg had ported NPP_HexEdit to x64.

    i got a bit over-euphoric when i heard this and asked if c/p binary could be implemented to hexedit as well.

    btw: a long overdue thanks to @chcg for adding it to the enhancment list back then.

    Time to go re-vivify the topic briefly.

    i did the same right now, revisited both yours and mine 😉👍

    and yes, it’s really strange that paste special and copy binary content is almost inexistent if i do a forum search, considering it’s been there since 5.9 as you’ve found out (thanks for checking 👍)



  • and thanks for the thanks from teacher to alumnus 😃👍

    side note:
    it feels nice to get a thanks from a teacher (peter) to a student (me)
    hope the who is who didn’t get mixed up in it’s context above.


Log in to reply