从命令行启动时出现 MacVim 颜色问题
我对 Vim 比较陌生,到目前为止一直在使用它,没有出现任何问题。我要么从我的扩展坞启动 MacVim,要么从命令行使用 mvim
。到目前为止效果很好,但现在我遇到了一个问题。没有明显的原因,从命令行启动 MacVim 开始创建一个所有颜色都乱七八糟的 MacVim 窗口。当我从码头启动它时,一切都很好。
两个编辑器之间的颜色方案是相同的(日光化),所以我真的很困惑问题是。我的 MacVim 是使用 Homebrew 安装的,看起来扩展坞和命令行的可执行文件是相同的。我什至尝试直接启动 /Applications/MacVim.app/Contents/MacOS/MacVim
,它也打开白色。我正在使用 Janus,并且尝试破坏我的 .vim 并使用 rake 脚本重新创建它,但没有任何变化。
非常感谢任何帮助,预先感谢您。
编辑
我的 .vimrc
/.gvimrc
文件非常大,但它们是 Janus 附带的基本值。我的 .vimrc.local
/.gvimrc.local
是一样的,看起来像这样,
syntax enable
set background=dark
colorscheme solarized
map f gg=G
我还发现这似乎不是其他主题的问题就像 ir_black (Janus 默认的)。
编辑 2
I'm relatively new to Vim and have been using it without issues so far. I'd either launch MacVim from my dock or using mvim
from the command line. This worked great so far, but just now I've run into an issue. For no apparent reason, launching MacVim from the command line started to create a MacVim window that had all the colors screwed up. When I'd launch it from the dock, everything is fine.
The colorscheme is the same between both editors (solarized), so I'm really puzzled as to what the issue is. My MacVim is installed using Homebrew, and it looks like the executable is the same for the dock and the command line. I've even tried launching /Applications/MacVim.app/Contents/MacOS/MacVim
directly, it also opens up white. I'm using Janus, and I've tried nuking my .vim and recreating it with the rake script, but no change.
Any help greatly appreciated, thank you in advance.
Edit
My .vimrc
/.gvimrc
files are pretty large, but they're the basic values that come with Janus. My .vimrc.local
/.gvimrc.local
are the same and look like this,
syntax enable
set background=dark
colorscheme solarized
map f gg=G
I've also found that this doesn't seem to be a problem with other themes like ir_black (which Janus defaults to).
Edit 2
This seems to be a known issue with at least a few other people experiencing it. Will post a solution when one is found.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是由于
mvim
将终端环境导出到 MacVim 导致的。我已经 Solarized 检查它是否在 Terminal.app 中运行,如果是,则在 vim 中使用透明(无)背景以避免一些奇怪的颜色问题。不幸的是,我没有意识到 mvim 也将其终端环境导出到 MacVim。我之前要求 vim 检查 $TERM_PROGRAM 值,如果它是terminal.app 的字符串,那么我假设我在其中。我已将其更改为现在检查字符串并检查。
MacVim 应该抛弃终端环境吗?我不知道。我对此表示怀疑。因此,我建议在 vim 脚本中使用环境变量的情况下,最佳实践是检查是否有 gui_running(如果与检查相关)。
我已在 github 上的 Solarized 项目上提交 d5fcacea 时为此添加了修复程序,并在此处和与其他用户远程进行了测试。
This is caused by
mvim
exporting the terminal environment to MacVim.I have Solarized check if it's running in Terminal.app and, if so, use a transparent (NONE) background in vim to avoid some weird color issues. Unfortunately I didn't realize that mvim exports it's terminal environment to MacVim as well. I was previously asking vim to check the $TERM_PROGRAM value and if it was terminal.app's string then I assumed I was in it. I've changed this to now check the string and check.
Should MacVim throw the terminal environment away? I don't know. I doubt it. Thus I would recommend best practice in cases where one uses the envrionment variables in vim scripts would be to check for has gui_running as well, if relevant to the check.
I've added a fix for this as of commit d5fcacea on the solarized project on github and tested here and with one other user remotely.
问题不在于
macvim
,而是在于Terminal.app
。 Apple 的默认终端在颜色支持方面相当古老,仅支持 16 种颜色。如果使用终端 (cterm
),vim 的大多数颜色方案都定义为 256 种颜色;如果使用gui
,则定义为 1600 万种颜色。这就是搞砸你的颜色的原因。我建议使用
iTerm2
作为您的终端。它支持 256 种颜色,并具有许多其他功能(分割窗口是我的最爱!),并且通常比Terminal.app
更稳定。The issue is not with
macvim
, rather withTerminal.app
. Apple's default terminal is pretty ancient when it comes to support for colors and supports only 16 colors. Most of the color schemes for vim are defined for 256 colors if using terminals (cterm
) and 16 million if usinggui
. This is what is screwing up your colors.I would recommend using
iTerm2
as your terminal. It supports 256 colors, and has a host of other features (split windows is my fav!), and is in general more stable thanTerminal.app
.你能发布你的.vimrc吗?
这就是我的情况,我没有你所描述的问题:
请注意,人们总是因为我在 #vim 上以不同的方式做事而对我大喊大叫,但他们总是为我工作。换句话说,这可能不是最佳实践,但它确实有效。
Can you post your .vimrc?
This is what I have in mine and I don't have the problem that you are describing:
Note people always yell at me for doing things differently on #vim, but they always work for me. In other words, this may not be best practice, but it works.