如何在 Vim 中以每段格式在一行中重新格式化“gq"ed 文本 [英] How to reformat "gq"ed text in one line per paragraph format in Vim
本文介绍了如何在 Vim 中以每段格式在一行中重新格式化“gq"ed 文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些以前在 vim 中使用gggqG"格式化的文本文件.现在我需要将它们转换为每段一行的格式.我以前看到过一种方法(使用 :g 命令)来做到这一点,但我忘记了.有人知道吗?
I have some text files previously formatted in vim using "gggqG". Now I need to convert them to one line per paragraph format. I saw a way(using :g command) to do that before, but I have forgot it. Anyone knows?
推荐答案
我知道有两种方法:
将 textwidth 设置为较大的值并重新格式化:
Set textwidth to something big and reformat:
:set tw=1000000
gggqG
使用替代(如果你想在映射中使用它更合适):</p>
Use substitute (this is more appropriate if you want to do it in a mapping):
:%s/.\zs\n\ze./ /
对后者的解释:
:%s " Search and replace across the whole file
/ " Delimiter
.\zs\n\ze. " Look for a character either side of a new-line (so ignore blank lines).
" The \zs and \ze make the replacement only replace the new-line character.
/ / " Delimiters and replace the new-line with a space.
这篇关于如何在 Vim 中以每段格式在一行中重新格式化“gq"ed 文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文