Linux 设置 Vim 背景颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1117526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 17:31:16  来源:igfitidea点击:

Setting the Vim background colors

linuxbackgroundvimvi

提问by Maksim Vi.

When I try to change the background colors in .vimrcor directly in Vim using the command:

当我尝试.vimrc使用以下命令在 Vim中或直接在 Vim 中更改背景颜色时:

set background=dark

... it doesn't affect my background at all. Neither does the lightoption. However, it looks okay when I run gvim.

...它根本不影响我的背景。light选项也不行。但是,当我运行 gvim 时,它看起来没问题。

Is there a way to change the background in Vim without changing my Konsole settings?

有没有办法在不改变我的 Konsole 设置的情况下改变 Vim 中的背景?

EDITOkay, there is a difference between guifg/guibg and ctermfg/ctermbg. While the GUI accepts lots of different color combinations, cterm allows only few standard ones.

编辑好的,guifg/guibg 和 ctermfg/ctermbg 之间是有区别的。虽然 GUI 接受许多不同的颜色组合,但 cterm 只允许少数标准组合。

采纳答案by Alex Martelli

As vim's own help on set backgroundsays, "Setting this option does not change the background color, it tells Vim what the background color looks like. For changing the background color, see |:hi-normal|."

正如 vim 自己的帮助set background所说,“设置这个选项不会改变背景颜色,它告诉 Vim 背景颜色是什么样的。关于改变背景颜色,请参阅 |:hi-normal|。”

For example

例如

:highlight Normal ctermfg=grey ctermbg=darkblue

will write in white on blue on your color terminal.

将在您的彩色终端上以白底蓝字书写。

回答by Michael Kristofik

Using set bg=darkwith a white background can produce nearly unreadable text in some syntax highlighting schemes. Instead, you can change the overall colorscheme to something that looks good in your terminal. The colorscheme file should set the background attribute for you appropriately. Also, for more information see:

set bg=dark在某些语法突出显示方案中,使用白色背景可能会产生几乎不可读的文本。相反,您可以将整体配色方案更改为在终端中看起来不错的颜色。颜色方案文件应该为您适当地设置背景属性。此外,有关更多信息,请参阅:

:h color

回答by AA.

In a terminal emulator like konsole or gnome-terminal, you should to set a 256 color setting for vim.

在像 konsole 或 gnome-terminal 这样的终端模拟器中,您应该为 vim 设置 256 色设置。

:set  t_Co=256

After that you can to change your background.

之后,您可以更改背景。

回答by Luke

Try adding

尝试添加

set background=dark

to your .gvimrctoo. This work well for me.

也给你.gvimrc。这对我来说效果很好。