Vim delete blank lines

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

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

14条回答
  •  执笔经年
    2020-12-02 03:49

    1. how to remove all the blanks lines

      :%s,\n\n,^M,g
      

      (do this multiple times util all the empty lines went gone)

    2. how to remove all the blanks lines leaving SINGLE empty line

      :%s,\n\n\n,^M^M,g
      

      (do this multiple times)

    3. how to remove all the blanks lines leaving TWO empty lines AT MAXIMUM,

      :%s,\n\n\n\n,^M^M^M,g
      

      (do this multiple times)

    in order to input ^M, I have to control-Q and control-M in windows

提交回复
热议问题