diff --git a/README.md b/README.md index 8cd49e8..78f481c 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ It has the following options - `lang="..."` on block tag decides the effective syntax - When no valid `lang="..."` is present, the first syntax in the list will be used. - By default, only syntax files from `['$VIMRUNTIME', '$VIM/vimfiles', '$HOME/.vim']` are loaded. If none is found, then **full** syntax files, including those from plugins, will be loaded + - Each key replaces the default of the same key, so `{'syntax': {'script': ['javascript', 'typescript']}}` keeps `template` as `['html']` and `style` as `['css']`. Set a key to `[]` to remove the block - **full_syntax**: *string list*. Syntax whose **full** syntax files will always be loaded - **initial_indent**: *string list*. Tag/syntax with initial one tab indent. The format can be `tag.syntax`, `tag`, or `syntax` diff --git a/autoload/vue.vim b/autoload/vue.vim index 0f08ba6..017cc65 100644 --- a/autoload/vue.vim +++ b/autoload/vue.vim @@ -28,10 +28,16 @@ function! s:MergeUserConfigIntoDefault(user) \'debug': 0, \} + " Each key of syntax replaces the default of the same key, so blocks not in + " user config keep their default syntax let user = a:user for key in keys(default) if has_key(user, key) - let default[key] = user[key] + if key ==# 'syntax' && type(user[key]) == v:t_dict + call extend(default[key], user[key]) + else + let default[key] = user[key] + endif endif endfor diff --git a/test/cases/no-css.vim b/test/cases/no-css.vim index 394b439..7889f02 100644 --- a/test/cases/no-css.vim +++ b/test/cases/no-css.vim @@ -1,5 +1,8 @@ -" Without css syntax, like only script in config -let g:vim_vue_plugin_config = {'syntax': {'script': ['javascript']}} +" Without css syntax, like only script in config, removing template and style +" by [] +let g:vim_vue_plugin_config = { + \'syntax': {'script': ['javascript'], 'template': [], 'style': []}, + \} let g:test_flatten = 1 function! Check() diff --git a/test/cases/syntax-merge.vim b/test/cases/syntax-merge.vim new file mode 100644 index 0000000..caee50c --- /dev/null +++ b/test/cases/syntax-merge.vim @@ -0,0 +1,10 @@ +" Each key of syntax replaces the default of the same key, so template and +" style keep html and css +let g:vim_vue_plugin_config = {'syntax': {'script': ['javascript', 'typescript']}} +let g:test_flatten = 1 + +function! Check() + call ExpectBlock('