我想知道如何将一个段落变成
vim中的子弹句.
@H_502_22@
由于到目前为止所有其他答案都显示了如何使用各种编程语言,并且您已经使用Vim标记了问题,以下是如何在Vim中执行此操作:
之前:
sentence1. sentence2. sentence3. sentence4. sentence5. sentence6. sentence7.
后:
sentence1.
sentence2.
sentence3
sentence4.
sentence5.
:%s/\.\(\s\+\|$\)/.\r\r/g
我使用了两个回车符来匹配您在问题中显示的输出格式.您可以使用许多替代正则表达式表单:
" Using a look-behind :%s/\.\@<=\( \|$\)/\r\r/g " Using 'very magic' to reduce the number of backslashes :%s/\v\.( |$)/.\r\r/g " Slightly different formation: this will also break if there " are no spaces after the full-stop (period). :%s/\.\s*$\?/.\r\r/g
可能还有很多其他人.
这种非正则表达方式是:
:let s = getline('.') :let lineparts = split(s,'\.\@<=\s*') :call append('.',lineparts) :delete
看到:
:help pattern.txt :help change.txt :help \@<= :help :substitute :help getline() :help append() :help split() :help :d