如何增加 vim 中行号边距的间距?
I have a problem with my colorscheme in vim:
(source: tinygrab.com)
The line numbers are too close to the code. How I can increase the width of the line numbers' right margin?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这也困扰着我;我讨厌将文本挤在纯色块上。这让我产生幽闭恐惧症。
这是我作为解决方法所做的(在 MacVim 中,但我希望相同的技术在其他地方也适用):
在您首选的颜色方案中,将行号列的背景颜色设置为与普通文本的背景颜色相同,然后将行号前景色设置为低对比度且不显眼的颜色(因此它看起来不像普通文本的一部分)。我对普通文本使用黑底白字,对行号使用黑底深灰:
诚然,这并不能解决问题,只是隐藏它,但它对我来说效果很好。
This bothered me, too; I hate having text crammed up against a block of solid color. It makes me claustrophobic.
Here's what I did as a workaround (in MacVim, but I expect the same technique will work elsewhere):
In your preferred colorscheme, set the background color of the line-number column to be the same as the background color for normal text, and the line-number foreground color to something low-contrast and unobtrusive (so it doesn't look like it's part of your normal text). I use white-on-black for normal text, and dark-grey-on-black for the line numbers:
Admittedly, this doesn't fix the problem so much as hide it, but it's worked well for me.
https://github.com/vim/vim/blob/master /src/screen.c#L2220
看看代码,这是不可能的(显然,不修补 vim):vim 总是格式化行号以占据整个可用宽度,只留下一个空格之后(代码中的“%*ld”格式说明符可以确保这一点)。
https://github.com/vim/vim/blob/master/src/screen.c#L2220
Looking at the code, it turns to be impossible (without patching the vim, obviously): vim always formats the line numbers to take up the whole available width, leaving just a single space afterwards (the "%*ld " format specifier in the code makes sure of that).
您可以在“~/.vimrc”中添加以下行:
set nuw=6
其中“6”指定以字符数表示的列宽度。根据需要替换为较小或较大的数字。我认为,仅适用于更新的(>=7?)版本的 Vim。
You can add the following line in your "~/.vimrc":
set nuw=6
Where "6" specfies the width of the column in terms of number of characters. Replace with a smaller or large number as needed. Only works with more recent (>=7?) versions of Vim, I think.
%左5
在 vim 终端中(
%
整个文档,left
到 linenrs 的距离代码,0-infinity
等宽字体的距离(= 列数))%left 5
in the vim terminal (
%
whole document,left
distance code to linenrs,0-infinity
distance in monospace (= number of columns))将以下行添加到 init.vim 文件中。
Add the following line to you init.vim file.
这是解决方案2(参考如何更改左边距gvim)
解决方案 1(如
%left 5
)只是将“空格”添加到代码区域。我猜它的作用与线程启动器所做的相同......但它并没有回答原来的问题。解决方案 2:
foldcolumn
可以解决问题(foldcolumn 是行号左边的列)在执行模式下
:set Foldcolumn=12
如果您也想更改颜色(如参考中所示)
hi FoldColumn guibg=#003f3f
(在参考文献中是FoldColumns
,那是错误的)。Here is solution 2 (ref to how to change the left margin in gvim)
Solution 1 (like
%left 5
)just adds 'spaces' into the code area. I guess it does the same done by the threadstarter ...but it does not the answer the original question.Solution 2:
foldcolumn
does the trick (foldcolumn is the column left from the linenumbers)In exec mode
:set foldcolumn=12
If you want to change the color too (like in the ref)
hi FoldColumn guibg=#003f3f
(in the ref itsFoldColumns
, thats wrong).