Arthur Maltson
Arthur Maltson

Reputation: 6120

MacVim color issues when launching from command line

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.

enter image description here

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.

Upvotes: 3

Views: 3593

Answers (3)

altercation
altercation

Reputation: 2137

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.

Upvotes: 2

abcd
abcd

Reputation: 42235

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.

Upvotes: 2

Bradford
Bradford

Reputation: 4193

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.

Upvotes: 0

Related Questions