Sublime Text 2: How to delete blank/empty lines

前端 未结 19 1535
北恋
北恋 2020-12-12 09:02

Let\'s say I had a text file with the following nine lines:

foo

bar

baz

qux

quux

How can I use Sublime Text 2 to remove all four of the

相关标签:
19条回答
  • 2020-12-12 09:32

    Sublime Text 2 & 3

    The Comments of @crates work for me,

    Step 1: Simply press on ctrl+H

    Step 2: press on RegEX key

    Step 3: write this in the Find: ^[\s]*?[\n\r]+

    Step 4: replace all

    0 讨论(0)
  • 2020-12-12 09:34

    I had to use:

    replace \n^\s*\n with \n

    The https://github.com/NicholasBuse/sublime_DeleteBlankLines plugin did nothing at all.

    0 讨论(0)
  • 2020-12-12 09:35

    Don't even know how this whole thing works, but I tried ^\s*$ and didn't work (leaving still some empty lines).

    This instead ^\s* works for me

    {sublime text 3}

    0 讨论(0)
  • 2020-12-12 09:36

    In my case some empty lines contained the unicode character zero width space (U+200b). To rid empty lines, including the ones with this unicode character:

    \s\x{200b}|^\s
    
    0 讨论(0)
  • 2020-12-12 09:36

    Using find / replace, try pasting a selection starting at the end of the line above the blank line and ends at the beginning of the line after the blank. This works for a single blank line. You can repeat the process for multiple blank lines as well. CTRL-H, put your selection in the find box and put a single newline in the replace box via copy/paste or other method.

    0 讨论(0)
  • 2020-12-12 09:38

    The regexp in Hugo's answer is correct when there is no spaces in the line. In case if there are space regexp can be ^\s+$

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