Vim如何将多个空行替换成一个空行

7

我正在寻找一种方法来将多个空行替换为一个空行,并遇到了以下解决方案:

:g/^$/,/./-j

我理解以下内容:

g/   replace each occurrences
^$   start to end is an empty, basically empty line
,    replace empty line by comma
.    maybe repeat last command
-j   minus is go up and j is go down

但我不明白上述代码中的period和minus j是如何工作的。Vim是一个非常强大的工具,我希望了解它的语法能够帮助我的进一步学习。

我们可以在哪里找到minus j的文档?

这里的period和minus j是如何工作的?

1个回答

8
g    Run the command globally, for the entire file
/^$/ Start executing at an empty line…
,    …and continue executing to…
/./  …the first non-empty line (a line that contains
     regexp '.', i.e. any character)
-j   go up and join all selected lines

也就是说,命令joins将从一个空行到下一个非空行之前的所有空行连接在一起。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接