I recently had to work with a file, in VS Code, that had several empty lines I wanted to remove all at once.
最近,我不得不使用VS Code中的文件,其中有几个空行,我想一次将其全部删除。
We’re talking about 700+ empty lines with some text in between, and I didn’t want to do this manually.
我们谈论的是700多个空行,中间有一些文本,我不想手动执行此操作。
I’m a programmer, so I’d rather spend 5 minutes making a task easier rather than spend the same amount of time doing an annoying job.
我是一名程序员,所以我宁愿花5分钟简化任务,也不愿花相同的时间来完成烦人的工作。
I searched a bit and found this simple way to do so: replace \n\n
with \n
.
我搜索了一下,发现这样做的简单方法:用\n\n
替换\n\n
\n
。
I ran “replace all” inside the file, and half of the lines were removed. So I ran it again, and again and again, until I got to 1 empty line.
我在文件中运行了“全部替换”,并且删除了一半的行。 因此,我一次又一次地运行它,直到到达1个空行。
Update:
\n\n+
will replace all lines at once without having to repeat the operation更新:
\n\n+
将一次替换所有行,而无需重复操作