打印时如何在vim中启用自动换行 [英] How do you enable word wrap in vim when printing

查看:69
本文介绍了打印时如何在vim中启用自动换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打印一个简单的文本文档并确保单词在单词边界上换行.我两个都试了

I wanted to print a simple text document and make sure words wrap on word boundaries. I tried both

set linebreak

set wrap

但是在打印时,它只是在单词中间的右列上中断.这可以打印吗?

but when printing, it just breaks on the right column in the middle of words. Is this possible for printing?

推荐答案

您正在创建一个没有任何内置换行符的文本文件,因此每个段落都是一个单独的行",即使设置了换行符和换行符,它看起来像它们是多行).这就是打印在固定位置中断的原因.(根据 http://www.vim.org/htmldoc/various.html#printing 在打印过程中,您似乎无法让 vim 尊重换行/换行.)

You are creating a text file without any built-in linebreaks so each paragraph is a single "line", even though with linebreak and wrap set, it looks like they are multiple lines). This is why printing breaks at fixed places. (According to http://www.vim.org/htmldoc/various.html#printing it does not seem like you can have vim respect linebreak/wrap during print.)

为避免这种情况,如果您想在编辑时换行,请执行

To avoid this, if you want text to wrap while you are editing, do

set textwidth=70

在第 70 列换行.如果你希望你的文件有很长的行(例如,当加载到 MS Word 或其他东西时它的格式很好),那么你必须在打印之前对文本版本进行预处理.因此,例如,您可以尝试:

to wrap at the 70th column. If you want your file to have long lines (e.g., so it formats fine when loaded into MS Word or something), then you will have to pre-process the text version before printing it. So, for example, you can try:

fmt file.txt | lpr

或者如果您安装了 enscript,您应该可以尝试:

or if you have enscript installed, you should be able to try:

enscript --word-wrap file.txt

打印.可以通过在 vim 中运行来包装现有文件:

to print. An existing file can be wrapped by running in vim:

gggqG

也就是说,gg"转到文件开头,gqG"将gq"从当前位置(即第一行)重新格式化到最后一行(通过转到G").'gq' 将尊重您当前的 textwidth 设置.

that is, 'gg' to go to start of file and 'gqG' to reformat 'gq' from the current position (i.e. the first line) to the last line (by going to 'G'). 'gq' will respect your current textwidth setting.

这篇关于打印时如何在vim中启用自动换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆