Visual Studio Code - delete all blank lines - regex

后端 未结 15 1217
心在旅途
心在旅途 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 18:50

    Visual Studio Code 1.13.0 Linux Lite:

    • Hit CTRL+H
    • Select "Use Regular Expression"
    • Find box: ^(\s)*$\n (enter many ending \n as you need)
    • Replace box: empty
    • Click replace all

    Empty lines gone!

    0 讨论(0)
  • 2021-01-29 18:55

    What also works is this regex pattern:

    ^\s*$\n
    

    Then CTRL+Enter to replace all lines.

    Explanation of the above pattern:

    -----------------------------------------------
    |  ^ | beginning of string anchor             |
    -----------------------------------------------
    | \s | any whitespace character               |
    -----------------------------------------------
    | '*'| zero or more repetitions               |
    -----------------------------------------------
    |  $ | end of string anchor                   |
    -----------------------------------------------
    | \n | new line                               |
    -----------------------------------------------
    
    0 讨论(0)
  • 2021-01-29 18:55

    Try using ^\s*\n in the Replace dialog of VS Code -

    0 讨论(0)
  • 2021-01-29 18:55

    Code Maid Extension is all you need. You can use shortcut Ctrl M + Space bar to Cleanup your file, It will remove empty lines and format your code. You also can configure about format and cleanup rule. Hope this useful.

    0 讨论(0)
  • 2021-01-29 18:58

    I found the following works best for me in Visual Studio:

    Replace: ^\n$ With: <no value here>

    This will find all empty lines and clear them out.

    0 讨论(0)
  • 2021-01-29 19:01

    Replace: ^\n$ With: "blank space"

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