Search code examples
macosvimclipboardmacos-sierravim-syntax-highlighting

Using custom vimrc on mac causes syntax highlighting to be lost


I am using Vim 8.0 (in the Terminal), compiled by Homebrew, on Mac OS 10.12.6. I am trying to enable copy to clipboard (and paste from clipboard) using the usual yank/put commands. I've actually succeeded in doing this (following various online guides) by creating a .vimrc file in my home directory and adding the single line set clipboard=unnamed. However, this has had the undesired side effect of preventing the nice extension-specific syntax highlighting (that was enabled by default with the installation) from being loaded when vim opens (for example, when I open a .py file the text is now all white). Is there some way of enabling copy to clipboard without destroying the syntax highlighting?


Solution

  • If you have no vimrc, vim loads a defaults.vim file, but once you add a custom vimrc, vim stops loading that file. This was introduced in Vim 8.0, and you can get more info by typing :h defaults.vim within vim, but here are your options to fix the issue:

    SOLUTION 1:

    Source the defaults.vim file into your .vimrc (this is the method mentioned in the vim help files - see :help defaults.vim). Just add these lines to the top of your .vimrc:

    unlet! skip_defaults_vim    
    source $VIMRUNTIME/defaults.vim
    

    SOLUTION 2:

    Copy the stuff you like from defaults.vim into your own config. This involves a few steps:

    1. Figure out what $VIMRUNTIME is set to by typing :echo $VIMRUNTIME inside of vim and hitting enter.
    2. Navigate to the directory it returns (for me this was /usr/local/share/vim/vim80/) and find the defaults.vim file.
    3. Copy and paste any of the settings that you want into your own .vimrc.

    Hope this helps!