Visual Studio Code - delete all blank lines - regex

后端 未结 15 1242
心在旅途
心在旅途 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:05

    For those who might be interested - what worked for me in version 1.3.1 (and still works in 1.33.1) to delete blank lines I used ctrl+h (find and replace) alt+r (Use regular expression)

    In find box then:

    \n\n
    

    In replace box:

    \n
    

    This should make two consecutive end of line signs into one.

    edited:

    If you need to replace more empty lines (more than two) at once, you can use following regular expression in find box:

    \n+
    

    If you need to replace also empty lines with whitespaces, then you need to use following regular expression in find box:

    \n+\s*\n
    

    VS code is using javascript regular expressions

提交回复
热议问题