Skip to content

Allow granular control over loading pre-processor syntax files #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,14 @@ endfunction
</details>

### _Vim slows down when using this plugin_ How can I fix that?
When checking for pre-processor languages, multiple syntax highlighting checks are done, which can slow down vim. You can trim down which pre-processors to use by setting `g:vue_pre_processors` to a whitelist of languages to support:

Add `let g:vue_disable_pre_processors=1` in your .vimrc to disable checking for prepocessors. When checking for preprocessor languages, multiple syntax highlighting checks are done, which can slow down vim. This variable prevents vim-vue from supporting **every** pre-processor language highlighting.
```vim
let g:vue_pre_processors = ['pug', 'scss']
```

Or alternatively, disable pre-processor languages altogether:

```vim
let g:vue_disable_pre_processors = 1
```
38 changes: 28 additions & 10 deletions syntax/vue.vim
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,35 @@ function! s:register_language(language, tag, ...)
endif
endfunction

let s:language_config = [
\ {'lang': 'less', 'args': ['less', 'style']},
\ {'lang': 'pug', 'args': ['pug', 'template', s:attr('lang', '\%(pug\|jade\)')]},
\ {'lang': 'slm', 'args': ['slm', 'template']},
\ {'lang': 'handlebars', 'args': ['handlebars', 'template']},
\ {'lang': 'haml', 'args': ['haml', 'template']},
\ {'lang': 'typescript', 'args': ['typescript', 'script', '\%(lang=\("\|''\)[^\1]*\(ts\|typescript\)[^\1]*\1\|ts\)']},
\ {'lang': 'coffee', 'args': ['coffee', 'script']},
\ {'lang': 'stylus', 'args': ['stylus', 'style']},
\ {'lang': 'sass', 'args': ['sass', 'style']},
\ {'lang': 'scss', 'args': ['scss', 'style']},
\ ]
let s:language_dict = {}
for item in s:language_config
let s:language_dict[item.lang] = item.args
endfor

if !exists("g:vue_disable_pre_processors") || !g:vue_disable_pre_processors
call s:register_language('less', 'style')
call s:register_language('pug', 'template', s:attr('lang', '\%(pug\|jade\)'))
call s:register_language('slm', 'template')
call s:register_language('handlebars', 'template')
call s:register_language('haml', 'template')
call s:register_language('typescript', 'script', '\%(lang=\("\|''\)[^\1]*\(ts\|typescript\)[^\1]*\1\|ts\)')
call s:register_language('coffee', 'script')
call s:register_language('stylus', 'style')
call s:register_language('sass', 'style')
call s:register_language('scss', 'style')
if exists("g:vue_pre_processors")
let pre_processors = g:vue_pre_processors
else
let pre_processors = map(copy(s:language_config), {k, v -> v.lang})
endif

for language in pre_processors
if has_key(s:language_dict, language)
call call("s:register_language", get(s:language_dict, language))
endif
endfor
endif

syn region vueSurroundingTag contained start=+<\(script\|style\|template\)+ end=+>+ fold contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent
Expand Down