MacVim color issues when launching from command line

旧城冷巷雨未停 提交于 2019-12-23 18:32:02

问题


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.


回答1:


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.




回答2:


The issue is not with macvim, rather with Terminal.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 using gui. 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 than Terminal.app.




回答3:


Can you post your .vimrc?

This is what I have in mine and I don't have the problem that you are describing:

if has("gui_running")
    augroup RCVisual
        autocmd!
        autocmd GUIEnter *  colorscheme mycolo
    augroup END
else    
    colo desert
endif

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.



来源:https://stackoverflow.com/questions/5602079/macvim-color-issues-when-launching-from-command-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!