加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式:使用vim为每个句子添加换行符

发布时间:2020-12-14 06:23:40 所属栏目:百科 来源:网络整理
导读:我想知道如何将一个段落变成 vim中的子弹句. 之前: sentence1. sentence2. sentence3. sentence4. sentence5. sentence6. sentence7. 后: sentence1. sentence2. sentence3 sentence4. sentence5. 由于到目前为止所有其他答案都显示了如何使用各种编程语言
我想知道如何将一个段落变成 vim中的子弹句.

之前:

sentence1. sentence2.  sentence3.  sentence4.  sentence5.  sentence6. 
sentence7.

后:

sentence1.

sentence2.

sentence3

sentence4.

sentence5.

由于到目前为止所有其他答案都显示了如何使用各种编程语言,并且您已经使用Vim标记了问题,以下是如何在Vim中执行此操作:
:%s/.(s+|$)/.rr/g

我使用了两个回车符来匹配您在问题中显示的输出格式.您可以使用许多替代正则表达式表单:

" Using a look-behind
:%s/.@<=( |$)/rr/g
" Using 'very magic' to reduce the number of backslashes
:%s/v.( |$)/.rr/g
" Slightly different formation: this will also break if there
" are no spaces after the full-stop (period).
:%s/.s*$?/.rr/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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读