Although others mentioned tools that break the lines just before the word that
hits the 80-character limit, there is also another tool that tries to not break
the lines just before end of after start of a sentence and does other things
for better readability. Its usage is similar:
echo "…" | fmt -w 80
The `-w` option specifies the maximum width of the text, but the text will use
only 93 percent of the line (this can be overridden by using `-g`).
The long sentence that hits the 80 character column count is this one and here.
这是来自fmt:
Although others mentioned tools that break the lines just before the word
that hits the 80-character limit, there is also another tool that tries
to not break the lines just before end of after start of a sentence and
does other things for better readability. Its usage is similar:
echo "…" | fmt -w 80
The `-w` option specifies the maximum width of the text, but the text will
use only 93 percent of the line (this can be overridden by using `-g`).
The long sentence that hits the 80 character column count is this one
and here.
使用
fold
.-s
包裹在空格上。-w 80
将宽度设置为 80 列。当然
fold
是最好的选择,但您也可以使用grep
or实现此目的sed
:请注意,这将在 80 个字符 + 1 个单词处中断,因此它可能不适合您。
尽管其他人提到了在达到 80 个字符限制的单词之前换行的工具,但还有另一种工具试图在句子开头之后的结尾之前不换行,并执行其他操作以提高可读性。它的用法类似:
该
-w
选项指定文本的最大宽度,但文本将仅使用行的 93%(这可以通过使用 覆盖-g
)。这是
fold
格式化文本的方式:这是来自
fmt
:您会注意到最后一个(正好 80 个字符长)被包装了,但不是在第 75 列(80 的 93%),而是在它之前的一个单词,因为我们不想单独在行上有一个单词(在印刷文本等)。