Vim 中的自动换行(保留缩进) [英] Word Wrap in Vim (preserving indentation)

查看:96
本文介绍了Vim 中的自动换行(保留缩进)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在看这篇文章,它描述了如何在 vim 中包装整个单词.接受的解决方案是这样的:

:set formatoptions=l:设置磅

采用此文本(制表符显示为 \t):

 *窗内*窗外|---------------------------------------||\t\t这是一个类似的文本,将 | 包裹在这里|\t\t你能看到包装||||---------------------------------------|

这完成了这样的行为(选项卡显示为 \t):

 *窗内*窗外|---------------------------------------||\t\t这是一个类似的文本,将 ||在这里换行 ||\t\t你能看到包装||||---------------------------------------|

不过我想重新定义这个函数.我希望被包裹的行在它前面有相同数量的标签,上面的行加上一.即:

 *窗内*窗外|---------------------------------------||\t\t这是一个类似的文本,将 ||\t\t\twrap 到这里 ||\t\t你能看到包装||||---------------------------------------|

有什么想法吗?

解决方案

breakindent 补丁有什么您正在寻找.我使用此线程中的说明成功应用了它:

在带有 Homebrew 的 OS X 上使用 breakindent 补丁修补 Vim

特别是 echristopherson 的 Homebrew 配方.

我知道这个帖子很旧,但它在 google 上很流行,我在试图找到解决方案时多次遇到它.

这个补丁现在作为补丁 7.4.338 包含在 vim 中.请参阅:https://retracile.net/blog/2014/07/18/18.00

在 Yosemite (Mac OS X) 上,我在 hombrew 中使用了 snowbound 的命令:

brew install macvim --with-features=huge --override-system-vim --HEAD

I was just looking at this post which describes how to wrap entire words in vim. The accepted solution was this:

:set formatoptions=l
:set lbr

Which takes this text (tabs are shown as \t):

 *Inside of window                        *Outside of window
|---------------------------------------|    
|\t\tthis is a like of text that will wr|ap here                            
|\t\tcan you see the wrap               |
|                                       |
|---------------------------------------|

This accomplishes a behavior like this (tabs are shown as \t):

 *Inside of window                        *Outside of window
|---------------------------------------|    
|\t\tthis is a like of text that will   |
|wrap here                              |
|\t\tcan you see the wrap               |
|                                       |
|---------------------------------------|

I would however like to redefine this function. I would like the wrapped line to have the same number of tabs in front of it that the line above has plus one. Ie:

 *Inside of window                        *Outside of window
|---------------------------------------|    
|\t\tthis is a like of text that will   |
|\t\t\twrap here                        |
|\t\tcan you see the wrap               |
|                                       |
|---------------------------------------|

Any ideas?

解决方案

The breakindent patch has what you're looking for. I successfully applied it using instructions found in this thread:

Patch Vim with the breakindent patch on OS X with Homebrew

Specifically, echristopherson's Homebrew formula.

I know this thread is old but it's popular on google and I came across it multiple times when trying to find a solution.

EDIT: This patch is now included with vim as patch 7.4.338. See: https://retracile.net/blog/2014/07/18/18.00

On Yosemite (Mac OS X), I used snowbound's command with hombrew:

brew install macvim --with-features=huge --override-system-vim --HEAD 

这篇关于Vim 中的自动换行(保留缩进)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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