比如我有一段文字:
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 可以自动换行,但是它是在屏幕上显示换行,并不是在一行的末尾真正地插入了一个换行符。)
![]() | 1 UnknoownUser OP 可能有这样的 vscode 插件,但是我不知道? |
![]() | 2 aijam 2022-12-31 12:01:04 +08:00 |
3 yfugibr 2022-12-31 12:07:07 +08:00 via Android vim, :set tw=80 选中 gq |
![]() | 4 xuchkang171 2022-12-31 12:39:21 +08:00 「但是它是在屏幕上显示换行」的功能叫 soft wrap ,不改变文本; 「在一行的末尾真正地插入了一个换行符」则是 hard wrap ,改变文本。 BBEdit 编辑器的 hard wrap 功能入口在 Text > Hard Wrap... |
5 TrembleBeforeMe 2022-12-31 12:49:38 +08:00 fill-column |
![]() | 6 wenmin92 2022-12-31 13:12:08 +08:00 linux 的 fold 命令。 ``` fold (1) - wrap eac input line to fit in specified width ``` |
![]() | 7 UnknoownUser OP @aijam 完美地解决了我的问题 |
8 jones2000 2022-12-31 22:44:26 +08:00 canvas 用 measureText 自己算下, 不就知道一行能显示多少个了, 然后 fillText 一行一行输出不就可以了, 十几行代码的事。 |
9 ireqhawk 2022-12-31 22:52:42 +08:00 如果你是为了便于查看,那么 word wrap 功能已经很完美解决这个问题了. --因为你的窗口可能会放大或者缩小,所以固定字符插入换行并不适用. 如果你的需求真的是要固定字符插入一个换行,这不管什么语言都很好实现吧. |