你如何让vim在不插入换行符的情况下显示换行? [英] How do you get vim to display wrapped lines without inserting newlines?

查看:37
本文介绍了你如何让vim在不插入换行符的情况下显示换行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于意外的 MacBook 母版(主板)崩溃(我的紧急备份 Linux 机器无法运行 TextMate),我正在与我的内部 (g)vim 重新取得联系.总而言之,我对 vim 的效率和功能很满意,但让我感到羞愧的是,即使是愚蠢的 HTML 文本区域也能毫不费力地实现这种自动换行.

I'm getting back in touch with my inner (g)vim due to an unscheduled MacBook mother(board) of a meltdown (my emergency backup Linux box won't run TextMate). All told I'm happy with vim's efficiency and power, but I'm mortified at how hard it is to get the kind of word wrap that even stupid HTML textareas achieve with no apparent effort.

考虑文本

Etiam ornare mollis tortor. Suspendisse sed neque. Nullam in elit. Cum sociis nullam.

默认情况下,使用 80 个字符的宽度,vim 将其显示为

By default, with an 80-character width vim displays this as

Etiam ornare mollis tortor. Suspendisse sed neque. Nullam in elit. Cum sociis nu
llam.

这种包装不关心空格,所以有时它只是将单词切成碎片(在这种情况下为 nullam).当然,你可以打开自动换行,然后得到这个:

This wrapping doesn't care about whitespace, so sometimes it just slices words into pieces (nullam in this case). Of course, you can turn on word wrap, and get this:

Etiam ornare mollis tortor. Suspendisse sed neque. Nullam in elit. Cum sociis
nullam.

问题是vim在换行符处插入了一个换行符,这是我最想要的.换句话说,我希望文本在打开自动换行的情况下与 vim 显示的完全一样,但不插入换行符.(通过这种方式,它可以粘贴到 HTML 文本区域和电子邮件程序中,以及其他地方.)

The problem is that vim inserts a newline at the linebreak, which I most emphatically do not want. In other words, I want the text to display exactly as vim displays it with word wrap turned on, but without inserting a newline. (This way it can be pasted into HTML textareas and email programs, among other places.)

尽管努力了,但网络搜索没有任何用处;我希望 StackOverflow 能在我的 Google-fu 失败的地方成功.

Web searches have yielded nothing of use, despite diligent effort; I hope StackOverflow can succeed where my Google-fu has failed.

推荐答案

要打开自动换行:

:set wrap
:set linebreak

复制&粘贴原始文本而不是任何填充适用于 gvim.但是,对于 xterm 中的 vim,它会复制 EOL 处的空格填充(尽管不是换行符).我认为这应该有效,但它没有:

To copy & paste the original text and not any padding works for gvim. For vim in an xterm though, it copies the space padding at EOL (though not the newline). I thought this should work but it doesn't:

:set mouse=a

这篇关于你如何让vim在不插入换行符的情况下显示换行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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