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.
I just found out about the
The easiest way is to use
:help c_Ctrl-d after
:colorschemeCtrl-d will output the colorschemes you have available to you.
Make sure there is a space after
Another way to show the list is by
set wildmenu. With this, after
tab, a list of completion is displayed and also selectable with arrow key or
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
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.
:help getcompletion() for more details.
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: