UnknoownUser
V2EX  ›  问与答

有没有工具能够让纯文本段落超过一定字母数量自动换行?

  •  
  •   UnknoownUser · Dec 31, 2022 · 2844 views
    This topic created in 1403 days ago, the information mentioned may be changed or developed.

    比如我有一段文字:

    This document specifies an Internet standards track protocol for the Internet community, and requests discussion and suggestions for improvements.
    

    我想要固定文本每行的字母数,超过了自动换行,如下:

    This document specifies an Internet standards track 
    protocol for the Internet community, and requests 
    discussion and suggestions for improvements.
    

    有什么工具能够达到这一效果?( P.S.我了解到 vscode 的 word wrap 可以自动换行,但是它是在屏幕上显示换行,并不是在一行的末尾真正地插入了一个换行符。)

    9 replies  •  2022-12-31 22:52:42 +08:00
    UnknoownUser
    UnknoownUser
    OP
    Dec 31, 2022
    1
    可能有这样的 vscode 插件,但是我不知道?
    yfugibr
    yfugibr
    Dec 31, 2022 via Android
    3
    vim,
    :set tw=80
    选中
    gq
    xuchkang171
    xuchkang171
    Dec 31, 2022
    4
    「但是它是在屏幕上显示换行」的功能叫 soft wrap ,不改变文本;
    「在一行的末尾真正地插入了一个换行符」则是 hard wrap ,改变文本。

    BBEdit 编辑器的 hard wrap 功能入口在 Text > Hard Wrap...
    TrembleBeforeMe
    TrembleBeforeMe
    Dec 31, 2022
    5
    fill-column
    wenmin92
    wenmin92
    Dec 31, 2022
    6
    linux 的 fold 命令。
    ```
    fold (1) - wrap each input line to fit in specified width
    ```
    UnknoownUser
    UnknoownUser
    OP
    Dec 31, 2022
    7
    @aijam 完美地解决了我的问题
    jones2000
    jones2000
    Dec 31, 2022
    8
    canvas 用 measureText 自己算下, 不就知道一行能显示多少个了, 然后 fillText 一行一行输出不就可以了, 十几行代码的事。
    ireqhawk
    ireqhawk
    Dec 31, 2022
    9
    如果你是为了便于查看,那么 word wrap 功能已经很完美解决这个问题了.
    --因为你的窗口可能会放大或者缩小,所以固定字符插入换行并不适用.
    如果你的需求真的是要固定字符插入一个换行,这不管什么语言都很好实现吧.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5275 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 02:59 · PVG 10:59 · LAX 18:59 · JFK 21:59
    ♥ Do have faith in what you're doing.