I have a custom syntax plugin for a file format that can contain embedded HLSL or GLSL code. At the moment, I've manually included a bunch of syntax keyword and syntax match commands in my syntax file to cover the basics of HLSL or GLSL source. I'd prefer to simply reference an existing HLSL syntax plugin via syntax include, but there is no built-in HLSL or GLSL syntax support in vim, so I cannot expect that a syntax include will succeed.I'd like to attempt to execute syntax include, and if it fails (or would fail), fall back to my half-hearted custom version. How can I accomplish this?I've looked at try/endtry, but they didn't seem to allow me to avoid an error if the desired syntax file wasn't present, and in any case only work on vim 7.0 or greater, and if possible I'd like to use a version-agnostic solution.
How can I conditionally include a syntax file from another syntax file?
syntax highlighting
From :help :runtimeWhen 'verbose' is one or higher, there is a message when no file could be found.This uses :echomsg to print the error, which you can capture like:redir => error    verbose silent runtime syntax/cx.vimredir ENDI've found that using :redir in startup scripts is sometimes problematic though, sometimes Vim mixes up which redir belongs to which variable, so alternatively you can just use a loop to scan each entry in the runtimepath:let found = 0for path in split(&runtimepath, ',')    if file_readable(path . '/fname.vim')        execute 'source ' . path . '/fname.vim'        let found = 1        break    endifendfor