How to remove carriage return in vi

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
0
down vote

favorite












I have a file that's failing due to a single carriage return at the end (0x0D). It was originally a carriage return/new line combination (0x0D, 0x0A). I've tried:



  • deleting it in INSERT mode (deletes the last printing character and leaves the carriage return)


  • %s/r// (E486: Pattern not found: r)


  • %s/^M// (Ctrl+V, Ctrl+M to get ^M) (E486: Pattern not found: ^M)


  • J to join with the next line (appears to do nothing to the last line)

All of them leave the carriage return in place.



How can I get rid of this character from within vi (not vim)?



EDIT



Now it appears it's adding a new line character (0x0A) whenever I save the file. So, the 0x0D is gone, but I still have an invalid character at the end of my file.



I tried adding two blank lines to see if it would add 0x0A or 0x0D, 0x0A (I'm using PuTTY from Windows) and it added two 0x0A characters, for a total of three.



If you have three lines, shouldn't you only need two line separators?




  • %s/n// (no error, but doesn't remove the character)






share|improve this question


























    up vote
    0
    down vote

    favorite












    I have a file that's failing due to a single carriage return at the end (0x0D). It was originally a carriage return/new line combination (0x0D, 0x0A). I've tried:



    • deleting it in INSERT mode (deletes the last printing character and leaves the carriage return)


    • %s/r// (E486: Pattern not found: r)


    • %s/^M// (Ctrl+V, Ctrl+M to get ^M) (E486: Pattern not found: ^M)


    • J to join with the next line (appears to do nothing to the last line)

    All of them leave the carriage return in place.



    How can I get rid of this character from within vi (not vim)?



    EDIT



    Now it appears it's adding a new line character (0x0A) whenever I save the file. So, the 0x0D is gone, but I still have an invalid character at the end of my file.



    I tried adding two blank lines to see if it would add 0x0A or 0x0D, 0x0A (I'm using PuTTY from Windows) and it added two 0x0A characters, for a total of three.



    If you have three lines, shouldn't you only need two line separators?




    • %s/n// (no error, but doesn't remove the character)






    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a file that's failing due to a single carriage return at the end (0x0D). It was originally a carriage return/new line combination (0x0D, 0x0A). I've tried:



      • deleting it in INSERT mode (deletes the last printing character and leaves the carriage return)


      • %s/r// (E486: Pattern not found: r)


      • %s/^M// (Ctrl+V, Ctrl+M to get ^M) (E486: Pattern not found: ^M)


      • J to join with the next line (appears to do nothing to the last line)

      All of them leave the carriage return in place.



      How can I get rid of this character from within vi (not vim)?



      EDIT



      Now it appears it's adding a new line character (0x0A) whenever I save the file. So, the 0x0D is gone, but I still have an invalid character at the end of my file.



      I tried adding two blank lines to see if it would add 0x0A or 0x0D, 0x0A (I'm using PuTTY from Windows) and it added two 0x0A characters, for a total of three.



      If you have three lines, shouldn't you only need two line separators?




      • %s/n// (no error, but doesn't remove the character)






      share|improve this question














      I have a file that's failing due to a single carriage return at the end (0x0D). It was originally a carriage return/new line combination (0x0D, 0x0A). I've tried:



      • deleting it in INSERT mode (deletes the last printing character and leaves the carriage return)


      • %s/r// (E486: Pattern not found: r)


      • %s/^M// (Ctrl+V, Ctrl+M to get ^M) (E486: Pattern not found: ^M)


      • J to join with the next line (appears to do nothing to the last line)

      All of them leave the carriage return in place.



      How can I get rid of this character from within vi (not vim)?



      EDIT



      Now it appears it's adding a new line character (0x0A) whenever I save the file. So, the 0x0D is gone, but I still have an invalid character at the end of my file.



      I tried adding two blank lines to see if it would add 0x0A or 0x0D, 0x0A (I'm using PuTTY from Windows) and it added two 0x0A characters, for a total of three.



      If you have three lines, shouldn't you only need two line separators?




      • %s/n// (no error, but doesn't remove the character)








      share|improve this question













      share|improve this question




      share|improve this question








      edited May 11 at 1:42

























      asked May 11 at 1:24









      CJ Dennis

      1103




      1103




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          I finally found an answer elsewhere:



          :set noendofline binary



          Removes the final new line when the file is saved.






          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "89"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1034725%2fhow-to-remove-carriage-return-in-vi%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            I finally found an answer elsewhere:



            :set noendofline binary



            Removes the final new line when the file is saved.






            share|improve this answer
























              up vote
              0
              down vote













              I finally found an answer elsewhere:



              :set noendofline binary



              Removes the final new line when the file is saved.






              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                I finally found an answer elsewhere:



                :set noendofline binary



                Removes the final new line when the file is saved.






                share|improve this answer












                I finally found an answer elsewhere:



                :set noendofline binary



                Removes the final new line when the file is saved.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 11 at 2:07









                CJ Dennis

                1103




                1103






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1034725%2fhow-to-remove-carriage-return-in-vi%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    pylint3 and pip3 broken

                    Missing snmpget and snmpwalk

                    How to enroll fingerprints to Ubuntu 17.10 with VFS491