Answers:
其他答案显示了交互方式,以显示可用的颜色方案,但是没有人提到获取可在vimscript中使用的列表的方法。这是我对这个问题的回答的改编。
该解决方案使用该'runtimepath'
选项来获取所有可用的colorscheme目录,然后在这些目录中删除其扩展名的情况下获取vimscript文件的列表。这可能不是最安全的方法,因此欢迎进行改进:
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
然后,您可以在vimscript中使用此函数返回的列表。例如,您可以简单地回显每种颜色方案:
for c in GetColorschemes() | echo c | endfor
我不会在这里解释每个函数或命令的功能,但是这里是我使用过的所有帮助页面的列表:
: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()