How to tell which colorscheme a Vim session currently uses

后端 未结 3 977
隐瞒了意图╮
隐瞒了意图╮ 2021-01-30 08:16

You can set the Vim color scheme by issuing

:colorscheme SCHEME_NAME

but, oddly enough, you can\'t get the currently used scheme by is

3条回答
  •  走了就别回头了
    2021-01-30 08:20

    There's no guaranteed way (as a colour scheme is essentially a load of vim commands that are sourced). However, by convention there should be a variable g:colors_name that is set to the name of the colour scheme.

    Therefore, try this:

    echo g:colors_name
    

    If you get E121, it's either a poorly made colour scheme or it's the default one.

    A shinier way of doing this is (for recent versions of vim):

    function! ShowColourSchemeName()
        try
            echo g:colors_name
        catch /^Vim:E121/
            echo "default"
        endtry
    endfunction
    

    Then do:

    :call ShowColourSchemeName()
    

    If it says "default", do :colorscheme default and see if the colours change. If they do, you're using a malformed colour scheme and there's not a lot you can do about it other than manually switching themes until you recognise it.

    The variable g:colors_name is documented here:

    :help colorscheme
    

提交回复
热议问题