UnknoownUser
V2EX  ›  问与答

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

  •  
  •   UnknoownUser · Dec 31, 2022 · 2727 views
    This topic created in 1364 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
        1
    UnknoownUser  
    OP
       Dec 31, 2022
    可能有这样的 vscode 插件,但是我不知道?
    aijam
        2
    aijam  
       Dec 31, 2022
    yfugibr
        3
    yfugibr  
       Dec 31, 2022 via Android
    vim,
    :set tw=80
    选中
    gq
    xuchkang171
        4
    xuchkang171  
       Dec 31, 2022
    「但是它是在屏幕上显示换行」的功能叫 soft wrap ,不改变文本;
    「在一行的末尾真正地插入了一个换行符」则是 hard wrap ,改变文本。

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