How to set default vim colorscheme

前端 未结 10 1203
南笙
南笙 2020-12-22 20:33

The latest upgrade of Ubuntu made my vim colorscheme unusable. I know how to set it manually (:colo evening, for example), but I want to set the default for all

10条回答
  •  北荒
    北荒 (楼主)
    2020-12-22 21:15

    What was asked for was to set:

    • the 'default', not some other color profile, and

    • 'for all vim sessions', not simply for the current user.

    The default colorscheme, "for all vim sessions", is not set simply by adding a line to your ~/.vimrc, as all of the other answers here say, nor is the default set without the word 'default' being there.

    So all of the other answers here, so far, get both of these wrong. (lol, how did that happen?)


    The correct answer is:

    Add a line to your system vim setup file in /etc/vim/ that says

    colorscheme default
    

    or using the abbreviation

    colo default
    

    but not capitalized as

    colo Default
    

    (I suggest using the full, un-abbreviated term 'colorscheme', so that when you look at this years later you'll be able to more easily figure out what that darn thing does. I would also put a comment above it like "Use default colors for vim".)


    To append that correctly, first look at your /etc/vim/vimrc file.

    At the bottom of mine, I see these lines which include /etc/vim/vimrc.local:

    " Source a global configuration file if available
    if filereadable("/etc/vim/vimrc.local")
      source /etc/vim/vimrc.local
    endif
    

    So you can append this line to either of these two files.

    I think the best solution is to append your line to /etc/vim/vimrc.local like this:

    colorscheme default


    You can easily do that in bash with this line:

    $ echo -e "\"Use default colors for vim:\ncolorscheme default"  \
       |  sudo tee -a /etc/vim/vimrc.local
    
    # 
    #     NOTE:  This doesn't work:
    #
    #       $ sudo echo 'colorscheme default'  >> /etc/vim/vimrc.local
    #
    #     It's the same general idea, and simpler, but because sudo doesn't
    #     know how to handle pipes, it fails with a `Permission denied` error.
    

    Also check that you have permission to globally read this file:

    sudo chmod 644 /etc/vim/vimrc.local
    

    With $ tail /etc/vim/vimrc.local you should now see these lines:

    "Use default colors for vim:
    colorscheme default
    

提交回复
热议问题