MacVim gets all settings from ~/.vimrc, but not the colors and I have to source it again
Solution 1
MacVim is sourcing its default gvimrc
after your ~/.vimrc
. It contains this snippet:
" Load the MacVim color scheme. This can be disabled by loading another color
" scheme with the :colorscheme command, or by adding the line
" let macvim_skip_colorscheme=1
" to ~/.vimrc.
if !exists("macvim_skip_colorscheme") && !exists("colors_name")
colorscheme macvim
endif
What happens is simple: MacVim's default colorscheme overrides your :hi
commands when you launch Vim and your :hi
commands override the default colorscheme when you source ~/.vimrc
.
The fix is simple too: turn your :hi
commands into a real colorscheme as per Ingo's answer.
Also, set background=light
is only useful in a colorscheme so move that line as well.
Solution 2
This isn't a direct answer, but you should extract all the :hi
commands from your ~/.vimrc
into a separate (private) colorscheme, e.g. ~/.vim/colors/mine.vim
. Prepend the following preamble:
hi clear
if exists("syntax_on")
syntax reset
endif
let g:colors_name = "mine"
Then choose that colorscheme via
:colorscheme mine
in your ~/.vimrc
.
Benefits
- Should fix your problem.
- Uses the proper abstractions provided by Vim.
- Reduces the size of your
.vimrc
, making it more manageable. - Allows you to switch colorschemes on the fly.
- Restores your colors when you temporarily turn
:syntax off
.
Solution 3
The MacVim is a gvim really, so you can have a .gvimrc that would be a mac specific colortheme config. Eg. I normally have a base .vimrc which I use on all unix systems where I normally disable all syntax colours but tint the comments. Like you said it won't work in MacVim so I have a .gvimrc which is perfect for setting colours for macvim, provided I never use gvim anywhere.
Alexander Farber
/me/likes: Java, С#, Perl, PHP, JavaScript, PostgreSQL, Linux, Azure /me/speaks: German, English, Russian /me/learns: https://github.com/afarber/android-questions https://github.com/afarber/unity-questions https://github.com/afarber/ios-questions
Updated on August 11, 2020Comments
-
Alexander Farber over 3 years
I am using the following ~/.vimrc with MacVim 7.4 on MacOS X Mavericks:
set guifont=Menlo:h14 set encoding=utf8 set mouse=a set expandtab set ts=8 set showcmd set nocompatible set backspace=2 set viminfo='20,\"50 set history=50 set ruler set si set hlsearch syntax on set bg=light hi Cursor term=inverse ctermfg=black guifg=black guibg=green hi Visual term=inverse ctermfg=yellow ctermbg=black guifg=yellow guibg=black hi Comment term=inverse ctermfg=grey ctermbg=black guifg=white guibg=black hi Identifier term=NONE ctermfg=black guifg=black hi Constant term=underline ctermfg=darkred guifg=red hi Statement term=bold ctermfg=blue guifg=blue hi PreProc term=NONE ctermfg=black guifg=black gui=underline hi Special term=NONE ctermfg=black guifg=black hi Type term=bold ctermfg=blue guifg=blue
and can see that the editor takes all the settings from that file (the font family and its size, the show ruler and tab settings, ...), but not the colors:
Only after I issue the command
:so ~/.vimrc
does it take my color settings too (red and blue with inverted comments):Does anybody please know, what is happening, why doesn't MacVim pick up the syntax colors too?
Below is the
:version
information:VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Aug 10 2013 18:40:52) MacOS X (unix) version Compiled by Douglas Drumond <[email protected]> Huge version with MacVim GUI. Features included (+) or not (-): +arabic +emacs_tags +localmap +postscript +textobjects +autocmd +eval -lua +printer +title +balloon_eval +ex_extra +menu +profile +toolbar +browse +extra_search +mksession +python +transparency ++builtin_terms +farsi +modify_fname -python3 +user_commands +byte_offset +file_in_path +mouse +quickfix +vertsplit +cindent +find_in_path +mouseshape +reltime +virtualedit +clientserver +float +mouse_dec +rightleft +visual +clipboard +folding -mouse_gpm +ruby +visualextra +cmdline_compl -footer -mouse_jsbterm +scrollbind +viminfo +cmdline_hist +fork() +mouse_netterm +signs +vreplace +cmdline_info +fullscreen +mouse_sgr +smartindent +wildignore +comments -gettext -mouse_sysmouse -sniff +wildmenu +conceal -hangul_input +mouse_urxvt +startuptime +windows +cryptv +iconv +mouse_xterm +statusline +writebackup +cscope +insert_expand +multi_byte -sun_workshop -X11 +cursorbind +jumplist +multi_lang +syntax -xfontset +cursorshape +keymap -mzscheme +tag_binary +xim +dialog_con_gui +langmap +netbeans_intg +tag_old_static -xsmp +diff +libcall +odbeditor -tag_any_white -xterm_clipboard +digraphs +linebreak +path_extra -tcl -xterm_save +dnd +lispindent +perl +terminfo -ebcdic +listcmds +persistent_undo +termresponse system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" 2nd user vimrc file: "~/.vim/vimrc" user exrc file: "$HOME/.exrc" system gvimrc file: "$VIM/gvimrc" user gvimrc file: "$HOME/.gvimrc" 2nd user gvimrc file: "~/.vim/gvimrc" system menu file: "$VIMRUNTIME/menu.vim" fall-back for $VIM: "/Applications/MacVim.app/Contents/Resources/vim" Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-p ragmas -pipe -DMACOS_X_UNIX -no-cpp-precomp -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE =1 Linking: clang -L. -L. -L/usr/local/lib -o Vim -framework Cocoa -framework Carb on -lncurses -liconv -framework Cocoa -fstack-protector -L/usr/local/lib -L/Sy stem/Library/Perl/5.12/darwin-thread-multi-2level/CORE -lperl -lm -lutil -lc -framework Python -framework Ruby
-
benjifisher over 10 yearsAnother fix is to do what the quoted comments suggest: add
:let macvim_skip_colorscheme=1
to your vimrc file. -
Joe.b about 5 yearsAnother thing I did was to create a .gvimrc and add the below sole line
source ~/.vim/colors-overriders
.