Sublime Text 2: How to delete blank/empty lines

前端 未结 19 1533
北恋
北恋 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:17

    There are also some ST2/ST3 Plugins for such tasks. I do like these two:

    • Delete Blank Lines (also available via Package Control)
    • Trailing Spaces (also available via Package Control)

    The first one has two methods for removing empty/unnecessary lines. One of them called Delete Surplus Blank Lines which is cool. It removes only those lines that are followed by another empty line

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

    Simpler than I thought. Ctrl + A Followed by Ctrl + H Then Select Regular Expression .* . Replace \n\n with \n. Voila!

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

    A Find/Replace solution:

    Regex Find:\s+

    Replace with: //single space

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

    Select the text

    Press:

    • Ctrl + H on PC, or
    • Command + Alt + F on Mac or
    • Click Find->Replace.

    Make sure you have selected 'regular expression' by pressing:

    • Alt + R on PC or
    • Command + Alt + R on Mac or
    • Click .* in the Find box.

    Find what: ^\n or ^(\r|\n\r?)

    Replace With: (nothing, leave in blank).

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

    If ^\n does not work properly ===> try .*[^\w]\n

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

    Their is a more easily way to do that without regex. you have just to select the whole text. then go to: Edit--> Permute Lines --> Unique.

    That's all. and all blank lines will be deleted.

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