Visual Studio Code - 删除所有空行 - 正则表达式 [英] Visual Studio Code - delete all blank lines - regex
问题描述
我花了一些时间试图弄清楚如何删除 Visual Studio Code 中的所有空行,但我无法让它工作.请问有人知道怎么做吗?
I spent some time trying to figure out how to delete all blank lines in Visual Studio Code and I can't get it working. Anybody knows how to do it please?
如果我在搜索字段中输入 ^$
时搜索它,VSC 确实找到了空行(完全空行,意味着没有空格)但是当我点击全部替换时它不会删除它们.它什么都不做:
If I search for ^$
while typing it in search field VSC does find the blank lines (completely blank lines, means no white spaces) but it doesn't remove them when I hit Replace All. It does nothing:
对于带有空格的空行 ^\s+$
搜索有效,但不会删除它们.它的作用是用没有空格的空行替换它们:))
For blank lines with spaces ^\s+$
Search works, but it does not remove them. What it does is it replaces them with a blank line without spaces :))
一定是我做错了什么.我只是想不通它是什么.有人知道吗?谢谢.
It must be I am doing something wrong. I just can't figure out what is it. Anybody knows? Thanks.
推荐答案
对于那些可能感兴趣的人 - 在 1.3.1 版中对我有用(并且在 1.33.1 中仍然有效)删除空行我使用 ctrl+h(查找和替换)alt+r(使用正则表达式)
For those who might be interested - what worked for me in version 1.3.1 (and still works in 1.33.1) to delete blank lines I used ctrl+h (find and replace) alt+r (Use regular expression)
在查找框中然后:
\n\n
在替换框中:
\n
这应该使两个连续的行尾符号合二为一.
This should make two consecutive end of line signs into one.
已
如果您需要一次替换更多的空行(超过两个),您可以在查找框中使用以下正则表达式:
If you need to replace more empty lines (more than two) at once, you can use following regular expression in find box:
\n+
如果还需要用空格替换空行,则需要在查找框中使用以下正则表达式:
If you need to replace also empty lines with whitespaces, then you need to use following regular expression in find box:
\n+\s*\n
VS 代码正在使用 javascript 正则表达式
VS code is using javascript regular expressions
这篇关于Visual Studio Code - 删除所有空行 - 正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!