13

I just found out about the :colorscheme command. Is there a way that I can get a list of valid color schemes from Vim? I'd like to be able to do this from within Vim, not from a list somewhere on the Internet.

17

The easiest way is to use :help c_Ctrl-d after :colorscheme.

So, :colorschemeCtrl-d will output the colorschemes you have available to you.

8

Another way to show the list is by set wildmenu. With this, after :colorscheme + space + tab, a list of completion is displayed and also selectable with arrow key or Ctrl-N and Ctrl-P. This is not only work on colorscheme, but also on other cmdline completion. The behavior is affected by wildmode and better set to the default value full.

2

If you want to do this in Vimscript, you can get a List of color schemes by using the getcompletion() function:

let c = getcompletion('', 'color')
echo c

This is a bit simpler than the existing Vimscript answer, which scans the filesystem.

See :help getcompletion() for more details.

1

The other answers show the interactive way of showing what colorschemes are available, but no one has mentioned a way of getting a list that can be used in vimscript. This is an adaptation of my answer for this question.

This solution uses the 'runtimepath' option to get all available colorscheme directories, and then fetches a list of the vimscript files in those directories with their extensions removed. This may not be the safest way to do it, so improvements are welcome:

function! GetColorschemes()
    " Get a list of all the runtime directories by taking the value of that
    " option and splitting it using a comma as the separator.
    let rtps = split(&runtimepath, ",")
    " This will be the list of colorschemes that the function returns
    let colorschemes = []

    " Loop through each individual item in the list of runtime paths
    for rtp in rtps
        let colors_dir = rtp . "/colors"
        " Check to see if there is a colorscheme directory in this runtimepath.
        if (isdirectory(colors_dir))
            " Loop through each vimscript file in the colorscheme directory
            for color_scheme in split(glob(colors_dir . "/*.vim"), "\n")
                " Add this file to the colorscheme list with its everything
                " except its name removed.
                call add(colorschemes, fnamemodify(color_scheme, ":t:r"))
            endfor
        endif
    endfor

    " This removes any duplicates and returns the resulting list.
    return uniq(sort(colorschemes))
endfunction

You can then use thie list returned by this function in vimscript. For instance, you could simply echo each colorscheme:

for c in GetColorschemes() | echo c | endfor

I won't explain what each individual function or command does here, but here is a list of the help pages for all of the ones I used:

  • :help 'runtimepath'
  • :help :let
  • :help :let-&
  • :help split()
  • :help :for
  • :help expr-.
  • :help :if
  • :help isdirectory()
  • :help glob()
  • :help fnamemodify()
  • :help add()
  • :help uniq()
  • :help sort()
-1

You can try this

:colorscheme, Then hit the space key and then the tab key.

  • 3
    Note that is it depends in your wildmenu and wildchar settings and that this answer is basically the same as tivn's one – statox Mar 1 '18 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.