我只是看这篇文章描述了如何在vim中包装整个单词.接受的解决方案是:
:set formatoptions=l
:set lbr
Run Code Online (Sandbox Code Playgroud)
采用此文本(标签显示为\ 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 |
| |
|---------------------------------------|
Run Code Online (Sandbox Code Playgroud)
这样就完成了这样的行为(标签显示为\ t):
*Inside of window *Outside of window
|---------------------------------------|
|\t\tthis is a like of text that will |
|wrap here |
|\t\tcan you see the wrap |
| |
|---------------------------------------|
Run Code Online (Sandbox Code Playgroud)
但是我想重新定义这个功能.我希望被包裹的行在它前面有相同数量的标签,上面的行加一.即:
*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 |
| |
|---------------------------------------|
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
Jos*_*uaD 24
当问题最初被问到时,这不起作用,但截至2014年6月25日,这将起作用.(假设您将vim更新为比该日期更新的版本)
添加到.vimrc:
" Indents word-wrapped lines as much as the 'parent' line
set breakindent
" Ensures word-wrap does not split words
set formatoptions=l
set lbr
Run Code Online (Sandbox Code Playgroud)
就是这样!
-
有些人(包括我自己)在多台计算机上共享一个.vimrc.在这种情况下,让这条线变得健壮是很重要的(以避免恼人的错误消息).这好一点:
if has("patch-7.4.354")
" Indents word-wrapped lines as much as the 'parent' line
set breakindent
" Ensures word-wrap does not split words
set formatoptions=l
set lbr
endif
Run Code Online (Sandbox Code Playgroud)
这样,如果您使用的是早期版本的vim,则不会收到错误消息.
小智 18
该breakindent补丁有你在找什么.我使用此主题中的说明成功应用了它:
具体来说,echristopherson的Homebrew公式.
我知道这个帖子已经老了,但它在谷歌上很受欢迎,我在尝试寻找解决方案时多次遇到它.
编辑:此补丁现在包含在vim中作为补丁7.4.338.请参阅: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
Run Code Online (Sandbox Code Playgroud)
我同意“表演突破”是最佳选择的答案。Showbreak 通常不允许您将非打印字符(例如,空格或制表符)放入 showbreak 字符串中,因此通常使用时,它只会在左边距中提供一个指示符,即没有真正的缩进。这不太好,因为我认为OP的主要目标是给换行线一个缩进,防止它们混乱左边距区域并看起来像自己的线。
因此,使用 showbreak 添加(丑陋的)缩进的一种方法是仅使用大量字符,例如“:set showbreak=>---------------->”。这会产生如下所示的结果:
*Inside of window *Outside of window
|---------------------------------------|
|\t\tthis is a like of text that will |
|>--------------->wrap here |
|\t\tcan you see the wrap |
| |
|---------------------------------------|
Run Code Online (Sandbox Code Playgroud)
更好的替代方案可能是使用不间断空格字符(假设您的 Vim 实例启用了 unicode),每个字符都可以使用 ctrl-v,160 键序列输入到 showbreak 字符串中。这样您就可以输入左侧空白的显示中断字符串,并且看起来是真正的缩进。例如,“:set showbreak=. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . >>" 其中每个 '.' 命令中实际上是按 ctrl-V,160 输入的不间断空格字符。这样你最终会得到一个缩进良好的包装,如下所示:
*Inside of window *Outside of window
|---------------------------------------|
|\t\tthis is a like of text that will |
| >>wrap here |
|\t\tcan you see the wrap |
| |
|---------------------------------------|
Run Code Online (Sandbox Code Playgroud)
您仍然无法根据前一行的缩进来改变缩进级别,但至少您可以得到干净的换行缩进,而不会在窗口左边缘出现大量视觉混乱。如果换行的缩进小于实际行开头的缩进,仍然可能会造成混乱,但这也许可以通过使 showbreak“缩进”相当大(即大于代码中常见的任何缩进)来避免。 )但仍然足够小,可以为文本的清晰换行提供足够的空间。对于许多用途,我认为 40 或 50 个空格的显示中断缩进可以很好地做到这一点。
| 归档时间: |
|
| 查看次数: |
10713 次 |
| 最近记录: |