有没有办法在新行之间连接行(返回),并保留新行(返回)?选择新行之间的文本后使用Ctrl+执行此操作,但对于大型文档不实用。J
可以将文本转换为:
Mary had a
little lamb.
His fleece was
white as snow, yeah.
And everywhere
the child went.
That little lamb
was sure to go now.
He followed her
to school one day.
Which broke the
teachers cool.
到:
Mary had a little lamb. His fleece was white as snow, yeah.
And everywhere the child went. That little lamb was sure to go now.
He followed her to school one day. Which broke the teachers cool.
答案1
- 按Ctrl+H
- 找什么:
(?<!\r\n)\r\n(?!\r\n)
- 替换为:无(空字符串)
- 搜索模式:正则表达式
然后全部替换
(?<!\r\n)
和(?!\r\n)
是正则表达式查找,以确保只匹配 1 个新行。如果文件是 Unix 格式,则只需删除\r
如果你还想在标点符号后添加空格,那么使用这个
- 按Ctrl+H
- 找什么:
([[:punct:]])(?=\R\S)
- 替换为:(
\1
末尾有一个空格) - 搜索模式:正则表达式
- 全部替换,然后执行
(?<!\r\n)\r\n(?!\r\n)
上述替换