Search code examples
vimmacvimvim-syntax-highlighting

Colorscheme in Vim not working on initial boot up


Let me preface by saying that I am entirely new to Vim and MacVim. I am trying to get my preferred colorscheme to work, and I have been partially successful. As it currently stands, the colorscheme will work if, once I edit into a file I type:

:syntax enable

However, on the intial load up, it does not work. I thought by putting syntax enable in my .vimrc file, that would activate it at load up, but this apparently is not working. So far, my .vimrc files looks like:

set nocompatible                                "We want the latest Vim settings/options

so ~/.vim/plugins.vim

filetype plugin indent on
syntax on
set backspace=indent,eol,start                  "Make backspace behave like every other editor.
let mapleader = ','                             "The default leader is \, but a comma is much better.
set number                                      "Activates line numbering.

"-----------Visuals------------"
colorscheme atom-dark                       "Sets colorscheme.
set t_CO=256                                "Use 256 colors.  This is useful for terminal Vim.
set guifont=Fira_Code:h13                   "Sets font and font height.
set linespace=15                            "Macvim-specific line height.

set guioptions-=l                       "Removes left hand scroll bar.
set guioptions-=L                       "Removes left hand scroll bar on vertically split screens.
set guioptions-=r                       "Removes right hand scroll bar.
set guioptions-=R                       "Removes right hand scroll bar on vertically split screens.

There is some more to it, but I don't believe it's relevant. Also, I have the colorscheme saved in my ~/.vim/colors folder, if that matters. And, finally, I am using MacVim for the most part.

What am I missing to get the colorscheme to work on the initial load? Or is it just required that I always manually enable syntax each time?

Thanks for the help in advance!

EDIT

My .gvimrc file:

 set nocompatible              " be iMproved, required
 filetype off                  " required
 set modelines=0              " sets modeline to 0 for security



 " Turn on line numbers
 set number

Solution

  • You should remove filetype off from your .gvimrc. First, see :help gvimrc:

    The gvimrc file is where GUI-specific startup commands should be placed. It is always sourced after the vimrc file. If you have one then the $MYGVIMRC environment variable has its name.

    Your .vimrc file sets filetype plugin indent on. But .gvimrc will be sourced after the .vimrc file, and it sets filetype off again. So any filetype detection will not be performed within your MacVim.

    Also I recommend you to make .gvimrc contain GUI-specific configurations only. This means you can remove

    set compatible
    filetype off
    set number
    

    from your .gvimrc. Also you can move set modelines=0 to .vimrc, but I don't think it's necessary, so you may remove it also.

    Additionally, you have options which will only work with GUI enabled Vim such as guifont, linespace and guioptions in your .vimrc. To make your .vimrc work on terminal Vim too, wrap that options with if has('gui_running'). So the .vimrc would be:

    set nocompatible                                "We want the latest Vim settings/options
    
    so ~/.vim/plugins.vim
    
    filetype plugin indent on
    syntax on
    set backspace=indent,eol,start                  "Make backspace behave like every other editor.
    let mapleader = ','                             "The default leader is \, but a comma is much better.
    set number                                      "Activates line numbering.
    
    "-----------Visuals------------"
    colorscheme atom-dark                       "Sets colorscheme.
    set t_Co=256                                "Use 256 colors.  This is useful for terminal Vim.
    
    if has('gui_running')
      set guifont=Fira_Code:h13               "Sets font and font height.
      set linespace=15                        "Macvim-specific line height.
    
      set guioptions-=l                       "Removes left hand scroll bar.
      set guioptions-=L                       "Removes left hand scroll bar on vertically split screens.
      set guioptions-=r                       "Removes right hand scroll bar.
      set guioptions-=R                       "Removes right hand scroll bar on vertically split screens.
    endif