如何在 Vim 中显示垂直线以包裹线? [英] How to show vertical line to wrap the line in Vim?
问题描述
我有兴趣在 Vim(不是 GVim)中找到一种在第 80 列显示垂直线的方法.
I'm interested in finding a way to show a vertical line at column 80 in Vim (not GVim).
我使用了 set wrap
,但我只想显示一条垂直线,这样我就可以自己将长线包裹起来.
I've used set wrap
, but I just want to show a vertical line so I can wrap the long line myself.
推荐答案
对于 Vim >=7.3,请参阅答案下面.
For Vim >=7.3 see answer below.
不幸的是,vim 没有按照您的意愿在列后显示垂直线的机制(与 TextMate 不同).但是,您可以使用其他视觉指示器来显示一行太长.
Unfortunately vim has no mechanism to display a vertical line after a column like you want (unlike, say, TextMate). However, there are alternative visual indicators that you can use to show that a line is too long.
这是我使用的(你可以把它放在你的 .vimrc
中):
Here's what I use (you can put this in your .vimrc
):
nnoremap <Leader>H :call<SID>LongLineHLToggle()<cr>
hi OverLength ctermbg=none cterm=none
match OverLength /\%>80v/
fun! s:LongLineHLToggle()
if !exists('w:longlinehl')
let w:longlinehl = matchadd('ErrorMsg', '.\%>80v', 0)
echo "Long lines highlighted"
else
call matchdelete(w:longlinehl)
unl w:longlinehl
echo "Long lines unhighlighted"
endif
endfunction
因此,您可以使用
来切换超过 80 个突出显示的列.
So then you can use <Leader>H
to toggle columns over 80 being highlighted.
这篇关于如何在 Vim 中显示垂直线以包裹线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!