Remove empty lines from a fileDuplicating line content by substitutionRun global substitute for each match of a regex, with incrementHow do I remove lines where its content already occured in the previous line?In a regex, why aren't the multi + and 1, always parsed exactly the same way?How to move multiple IPs to different linesHow can I make two substitution command in one lineCan vim perform all substitutions simultaneously?How to remove lines which have lower numbers than before, and keep only the sequential?substituting /* in vimscript

In Cura, can I make my top and bottom layer be all perimiters?

Should I do a regression analysis even if the variables do not seem to be associated at all?

Novel in which space traders train a spearman army for a decaying medieval empire

Why did the people of Zion never find evidence of the previous cycles?

Proof that if covariance is zero then there is no linear relationship

Homogeneous vector bundles with zero chern classes

What game(s) does Michael play in Mind Field S2E4?

How much caffeine would there be if I reuse tea leaves in a second brewing?

Can a trainer send me a gift every day without opening my gift?

network cable - why T-568A and B standard

Starting a fire in a cold planet that has full of flammable gas

What is this second smaller runway next to London City Airport?

What is more proper notation in piano sheet music to denote that the left hand should be louder?

Create a program that prints the amount of characters it has, in words

Alias to open a graphical Program (nautilus) opens it in Terminal too

Number of possible polynomials

Is the ''yoi'' meaning ''ready'' when doing karate the same as the ''yoi'' which means nice/good?

Scrum Team and Product Owner working against each other

For a command to increase something, should instructions refer to the "+" key or the "=" key?

Router model and/or firmware version identifiable in network traffic?

Noise reduction using multiple recordings of the same signal

How to capture a possible figure of speech with "E se io fossi vago" in translation?

Regular sized fonts in oubraces package

Command which removes data left side of ";" (semicolon) on each row



Remove empty lines from a file


Duplicating line content by substitutionRun global substitute for each match of a regex, with incrementHow do I remove lines where its content already occured in the previous line?In a regex, why aren't the multi + and 1, always parsed exactly the same way?How to move multiple IPs to different linesHow can I make two substitution command in one lineCan vim perform all substitutions simultaneously?How to remove lines which have lower numbers than before, and keep only the sequential?substituting /* in vimscript






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









2

















I'm able to find empty lines with /^$, but when I go to remove them using :%s/^$//, nothing seems to happen. Yet, some form of substitution is being made, because the status line reads XX substitutions on XX lines where XX is the number of empty lines in the file.



Questions:



  1. What substitutions are being made, as indicated by the status line?

  2. How do I accomplish what I want to do (eliminate empty lines from a file)?









share|improve this question


























  • One answer to #2 is :g/^$/d

    – chb
    Jun 1 at 1:46











  • A solution would be to replace an actual character: :%s/^n// but that depends on file format.

    – aragaer
    Jun 1 at 10:26

















2

















I'm able to find empty lines with /^$, but when I go to remove them using :%s/^$//, nothing seems to happen. Yet, some form of substitution is being made, because the status line reads XX substitutions on XX lines where XX is the number of empty lines in the file.



Questions:



  1. What substitutions are being made, as indicated by the status line?

  2. How do I accomplish what I want to do (eliminate empty lines from a file)?









share|improve this question


























  • One answer to #2 is :g/^$/d

    – chb
    Jun 1 at 1:46











  • A solution would be to replace an actual character: :%s/^n// but that depends on file format.

    – aragaer
    Jun 1 at 10:26













2












2








2








I'm able to find empty lines with /^$, but when I go to remove them using :%s/^$//, nothing seems to happen. Yet, some form of substitution is being made, because the status line reads XX substitutions on XX lines where XX is the number of empty lines in the file.



Questions:



  1. What substitutions are being made, as indicated by the status line?

  2. How do I accomplish what I want to do (eliminate empty lines from a file)?









share|improve this question















I'm able to find empty lines with /^$, but when I go to remove them using :%s/^$//, nothing seems to happen. Yet, some form of substitution is being made, because the status line reads XX substitutions on XX lines where XX is the number of empty lines in the file.



Questions:



  1. What substitutions are being made, as indicated by the status line?

  2. How do I accomplish what I want to do (eliminate empty lines from a file)?






substitute






share|improve this question














share|improve this question











share|improve this question




share|improve this question










asked Jun 1 at 1:24









chbchb

1154 bronze badges




1154 bronze badges















  • One answer to #2 is :g/^$/d

    – chb
    Jun 1 at 1:46











  • A solution would be to replace an actual character: :%s/^n// but that depends on file format.

    – aragaer
    Jun 1 at 10:26

















  • One answer to #2 is :g/^$/d

    – chb
    Jun 1 at 1:46











  • A solution would be to replace an actual character: :%s/^n// but that depends on file format.

    – aragaer
    Jun 1 at 10:26
















One answer to #2 is :g/^$/d

– chb
Jun 1 at 1:46





One answer to #2 is :g/^$/d

– chb
Jun 1 at 1:46













A solution would be to replace an actual character: :%s/^n// but that depends on file format.

– aragaer
Jun 1 at 10:26





A solution would be to replace an actual character: :%s/^n// but that depends on file format.

– aragaer
Jun 1 at 10:26










1 Answer
1






active

oldest

votes


















8



















  1. ^ and $ are zero-width items, so when you do :%s/^$// you’re substituting zero characters for zero characters

  2. To actually perform the substitution, the idioms are


:g/^$/d


and



:g/^$/j





share|improve this answer





























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "599"
    ;
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f20182%2fremove-empty-lines-from-a-file%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown


























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    8



















    1. ^ and $ are zero-width items, so when you do :%s/^$// you’re substituting zero characters for zero characters

    2. To actually perform the substitution, the idioms are


    :g/^$/d


    and



    :g/^$/j





    share|improve this answer
































      8



















      1. ^ and $ are zero-width items, so when you do :%s/^$// you’re substituting zero characters for zero characters

      2. To actually perform the substitution, the idioms are


      :g/^$/d


      and



      :g/^$/j





      share|improve this answer






























        8














        8










        8










        1. ^ and $ are zero-width items, so when you do :%s/^$// you’re substituting zero characters for zero characters

        2. To actually perform the substitution, the idioms are


        :g/^$/d


        and



        :g/^$/j





        share|improve this answer

















        1. ^ and $ are zero-width items, so when you do :%s/^$// you’re substituting zero characters for zero characters

        2. To actually perform the substitution, the idioms are


        :g/^$/d


        and



        :g/^$/j






        share|improve this answer















        share|improve this answer




        share|improve this answer








        edited Jun 2 at 12:46

























        answered Jun 1 at 3:23









        D. Ben KnobleD. Ben Knoble

        4,9011 gold badge7 silver badges27 bronze badges




        4,9011 gold badge7 silver badges27 bronze badges































            draft saved

            draft discarded















































            Thanks for contributing an answer to Vi and Vim Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f20182%2fremove-empty-lines-from-a-file%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown









            Popular posts from this blog

            Tamil (spriik) Luke uk diar | Nawigatjuun

            Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

            Where does the image of a data connector as a sharp metal spike originate from?Where does the concept of infected people turning into zombies only after death originate from?Where does the motif of a reanimated human head originate?Where did the notion that Dragons could speak originate?Where does the archetypal image of the 'Grey' alien come from?Where did the suffix '-Man' originate?Where does the notion of being injured or killed by an illusion originate?Where did the term “sophont” originate?Where does the trope of magic spells being driven by advanced technology originate from?Where did the term “the living impaired” originate?