Visual Studio Code - delete all blank lines - regex

后端 未结 15 1190
心在旅途
心在旅途 2021-01-29 18:36

I spent some time trying to figure out how to delete all blank lines in Visual Studio Code and I can\'t get it working. Anybody knows how to do it please?

If I search fo

相关标签:
15条回答
  • 2021-01-29 19:12

    At My case. kobi7 solution (\r?\n){2,} only worked for me, I had to run it again with small modification to make it work for single lines (just changed 2 to 1)

    ^(\r?\n){1,}
    
    0 讨论(0)
  • 2021-01-29 19:12

    There is my version for cleaning empty lines with white space:

    find:    (?:\s*$(\r?\n)){2,}
    replace: $1
    
    0 讨论(0)
  • 2021-01-29 19:15

    Here's my regex, it catches all extra new lines and empty lines that contain only space,tabs etc

    \n\s*\n
    

    And I replace all matches with \n

    Explanation

    \n       : New Line
    \s*      : Zero or more consecutive white space characters or new lines
    \n       : Another New Line
    

    P.S :Remember to choose the regex option in the search window!!

    0 讨论(0)
提交回复
热议问题