Vim delete blank lines

后端 未结 14 2465
情歌与酒
情歌与酒 2020-12-02 03:33

What command can I run to remove blank lines in Vim?

相关标签:
14条回答
  • 2020-12-02 03:57

    This worked for me:

    :%s/^[^a-zA-Z0-9]$\n//ig
    

    It basically deletes all the lines that don't have a number or letter. Since all the items in my list had letters, it deleted all the blank lines.

    0 讨论(0)
  • 2020-12-02 03:59

    This works for me

    :%s/^\s*$\n//gc

    0 讨论(0)
  • 2020-12-02 03:59

    I tried a few of the answers on this page, but a lot of them didn't work for me. Maybe because I'm using Vim on Windows 7 (don't mock, just have pity on me :p)?

    Here's the easiest one that I found that works on Vim in Windows 7:

    :v/\S/d
    

    Here's a longer answer on the Vim Wikia: http://vim.wikia.com/wiki/Remove_unwanted_empty_lines

    0 讨论(0)
  • 2020-12-02 03:59

    If something has double linespaced your text then this command will remove the double spacing and merge pre-existing repeating blank lines into a single blank line. It uses a temporary delimiter of ^^^ at the start of a line so if this clashes with your content choose something else. Lines containing only whitespace are treated as blank.

    %s/^\s*\n\n\+/^^^\r/g | g/^\s*$/d | %s/^^^^.*
    
    0 讨论(0)
  • 2020-12-02 04:02

    The following can be used to remove only multi blank lines (reduce them to a single blank line) and leaving single blank lines intact:

    :g/^\_$\n\_^$/d
    
    0 讨论(0)
  • 2020-12-02 04:04

    work with perl in vim:

    :%!perl -pi -e s/^\s*$//g

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