我以前使用“gggqG”在vim中格式化了一些文本文件。现在,我需要将它们转换为每种段落格式的一行。我以前见过一种方法(使用:g命令),但是我已经忘记了。有谁知道?

最佳答案

我知道两种方法:

  • 将textwidth设置为大并重新格式化:
    :set tw=1000000
    gggqG
    
  • 使用替代(如果要在映射中进行替代,这更合适):
    :%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 - 如何在Vim中以每段格式在一行中重新格式化 "gq"ed文本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2880109/

    10-12 17:59
    查看更多