How do you enable word wrap in vim when printing

廉价感情. 提交于 2019-12-21 05:07:34

问题


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

set linebreak

and

set wrap

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


回答1:


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

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

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

enscript --word-wrap file.txt

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

gggqG

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.



来源:https://stackoverflow.com/questions/533385/how-do-you-enable-word-wrap-in-vim-when-printing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!