如何增加 vim 中行号边距的间距?

发布于 2024-08-27 00:58:07 字数 307 浏览 14 评论 0原文

我在 vim 中的颜色方案有问题:

替代文字
(来源:tinygrab.com

行号太接近代码。如何增加行号右边距的宽度?

I have a problem with my colorscheme in vim:

alt text
(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

忆沫 2024-09-03 00:58:07

这也困扰着我;我讨厌将文本挤在纯色块上。这让我产生幽闭恐惧症。

这是我作为解决方法所做的(在 MacVim 中,但我希望相同的技术在其他地方也适用):

在您首选的颜色方案中,将行号列的背景颜色设置为与普通文本的背景颜色相同,然后将行号前景色设置为低对比度且不显眼的颜色(因此它看起来不像普通文本的一部分)。我对普通文本使用黑底白字,对行号使用黑底深灰:

hi LineNr  guifg=#505050   guibg=Black
hi Normal  guifg=White     guibg=Black

诚然,这并不能解决问题,只是隐藏它,但它对我来说效果很好。

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:

hi LineNr  guifg=#505050   guibg=Black
hi Normal  guifg=White     guibg=Black

Admittedly, this doesn't fix the problem so much as hide it, but it's worked well for me.

不及他 2024-09-03 00:58:07

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).

沩ん囻菔务 2024-09-03 00:58:07

您可以在“~/.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.

疏忽 2024-09-03 00:58:07

%左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))

错爱 2024-09-03 00:58:07

将以下行添加到 init.vim 文件中。

autocmd VimEnter * :%left 5

Add the following line to you init.vim file.

autocmd VimEnter * :%left 5
北方的巷 2024-09-03 00:58:07

这是解决方案2(参考如何更改左边距gvim

解决方案 1(如 %left 5 )只是将“空格”添加到代码区域。我猜它的作用与线程启动器所做的相同......但它并没有回答原来的问题。

解决方案 2foldcolumn 可以解决问题(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 its FoldColumns, thats wrong).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文