Add vue support, closes #160

This commit is contained in:
Adam Stankiewicz 2017-02-02 21:49:51 +01:00
parent 39036a553f
commit cc868aee51
No known key found for this signature in database
GPG Key ID: A62480DCEAC884DF
7 changed files with 185 additions and 0 deletions

View File

@ -117,6 +117,7 @@ If you need full functionality of any plugin, please use it directly with your p
- [vala](https://github.com/tkztmk/vim-vala) (syntax, indent, ftdetect)
- [vbnet](https://github.com/vim-scripts/vbnet.vim) (syntax)
- [vcl](https://github.com/smerrill/vcl-vim-plugin) (syntax, ftdetect)
- [vue](https://github.com/posva/vim-vue) (syntax, indent, ftplugin, ftdetect)
- [vm](https://github.com/lepture/vim-velocity) (syntax, indent, ftdetect)
- [xls](https://github.com/vim-scripts/XSLT-syntax) (syntax)
- [yaml](https://github.com/stephpy/vim-yaml) (syntax, ftplugin)

5
after/ftplugin/vue.vim Normal file
View File

@ -0,0 +1,5 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vue') == -1
setlocal suffixesadd+=.vue
endif

1
build
View File

@ -190,6 +190,7 @@ PACKS="
vala:tkztmk/vim-vala
vbnet:vim-scripts/vbnet.vim
vcl:smerrill/vcl-vim-plugin
vue:posva/vim-vue
vm:lepture/vim-velocity
xls:vim-scripts/XSLT-syntax
yaml:stephpy/vim-yaml

View File

@ -1000,4 +1000,11 @@ au BufRead,BufNewFile *.vm set ft=velocity syntax=velocity
endif
" ftdetect/vue.vim
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vue') == -1
au BufNewFile,BufRead *.vue setf vue.html.javascript.css
endif
augroup END

14
ftplugin/vue.vim Normal file
View File

@ -0,0 +1,14 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vue') == -1
" Vim filetype plugin
" Language: Vue.js
" Maintainer: Eduardo San Martin Morote
" Author: Adriaan Zonnenberg
if exists("b:did_ftplugin")
finish
endif
runtime! ftplugin/html.vim
endif

45
indent/vue.vim Normal file
View File

@ -0,0 +1,45 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vue') == -1
" Vim indent file
" Language: Vue.js
" Maintainer: Eduardo San Martin Morote
" Author: Adriaan Zonnenberg
if exists("b:did_indent")
finish
endif
" Load indent files for required languages
for language in ['stylus', 'pug', 'css', 'javascript', 'html', 'coffee']
unlet! b:did_indent
exe "runtime! indent/".language.".vim"
exe "let s:".language."indent = &indentexpr"
endfor
let b:did_indent = 1
setlocal indentexpr=GetVueIndent()
if exists("*GetVueIndent")
finish
endif
function! GetVueIndent()
if searchpair('<template lang="pug"', '', '</template>', 'bWr')
exe "let indent = ".s:pugindent
elseif searchpair('<style lang="stylus"', '', '</style>', 'bWr')
exe "let indent = ".s:stylusindent
elseif searchpair('<style', '', '</style>', 'bWr')
exe "let indent = ".s:cssindent
elseif searchpair('<script lang="coffee"', '', '</script>', 'bWr')
exe "let indent = ".s:coffeeindent
elseif searchpair('<script', '', '</script>', 'bWr')
exe "let indent = ".s:javascriptindent
else
exe "let indent = ".s:htmlindent
endif
return indent > -1 ? indent : s:htmlindent
endfunction
endif

112
syntax/vue.vim Normal file
View File

@ -0,0 +1,112 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vue') == -1
" Vim syntax file
" Language: Vue.js
" Maintainer: Eduardo San Martin Morote
if exists("b:current_syntax")
finish
endif
if !exists("s:syntaxes")
" Search available syntax files.
function s:search_syntaxes(...)
let syntaxes = {}
let names = a:000
for name in names
let syntaxes[name] = 0
endfor
for path in split(&runtimepath, ',')
if isdirectory(path . '/syntax')
for name in names
let syntaxes[name] = syntaxes[name] || filereadable(path . '/syntax/' . name . '.vim')
endfor
endif
endfor
return syntaxes
endfunction
let s:syntaxes = s:search_syntaxes('pug', 'slm', 'coffee', 'stylus', 'sass', 'scss', 'less')
endif
syntax include @HTML syntax/html.vim
if exists("b:current_syntax")
unlet b:current_syntax
endif
syntax region html keepend start=/^<template>/ end=/^<\/template>/ contains=@HTML fold
if s:syntaxes.pug
syntax include @PUG syntax/pug.vim
if exists("b:current_syntax")
unlet b:current_syntax
endif
syntax region pug keepend start=/<template lang=\("\|'\)[^\1]*pug[^\1]*\1>/ end="</template>" contains=@PUG fold
syntax region pug keepend start=/<template lang=\("\|'\)[^\1]*jade[^\1]*\1>/ end="</template>" contains=@PUG fold
endif
if s:syntaxes.slm
syntax include @SLM syntax/slm.vim
if exists("b:current_syntax")
unlet b:current_syntax
endif
syntax region slm keepend start=/<template lang=\("\|'\)[^\1]*slm[^\1]*\1>/ end="</template>" contains=@SLM fold
endif
syntax include @JS syntax/javascript.vim
if exists("b:current_syntax")
unlet b:current_syntax
endif
syntax region javascript keepend matchgroup=Delimiter start=/<script\( lang="babel"\)\?\( type="text\/babel"\)\?>/ end="</script>" contains=@JS fold
if s:syntaxes.coffee
syntax include @COFFEE syntax/coffee.vim
if exists("b:current_syntax")
unlet b:current_syntax
endif
" Matchgroup seems to be necessary for coffee
syntax region coffee keepend matchgroup=Delimiter start="<script lang=\"coffee\">" end="</script>" contains=@COFFEE fold
endif
syntax include @CSS syntax/css.vim
if exists("b:current_syntax")
unlet b:current_syntax
endif
syntax region css keepend start=/<style\( \+scoped\)\?>/ end="</style>" contains=@CSS fold
if s:syntaxes.stylus
syntax include @stylus syntax/stylus.vim
if exists("b:current_syntax")
unlet b:current_syntax
endif
syntax region stylus keepend start=/<style lang=\("\|'\)[^\1]*stylus[^\1]*\1\( \+scoped\)\?>/ end="</style>" contains=@stylus fold
endif
if s:syntaxes.sass
syntax include @sass syntax/sass.vim
if exists("b:current_syntax")
unlet b:current_syntax
endif
syntax region sass keepend start=/<style\( \+scoped\)\? lang=\("\|'\)[^\1]*sass[^\1]*\1\( \+scoped\)\?>/ end="</style>" contains=@sass fold
endif
if s:syntaxes.scss
syntax include @scss syntax/scss.vim
if exists("b:current_syntax")
unlet b:current_syntax
endif
syntax region scss keepend start=/<style\( \+scoped\)\? lang=\("\|'\)[^\1]*scss[^\1]*\1\( \+scoped\)\?>/ end="</style>" contains=@scss fold
endif
if s:syntaxes.less
syntax include @less syntax/less.vim
if exists("b:current_syntax")
unlet b:current_syntax
endif
syntax region less keepend matchgroup=PreProc start=/<style\%( \+scoped\)\? lang=\("\|'\)[^\1]*less[^\1]*\1\%( \+scoped\)\?>/ end="</style>" contains=@less fold
endif
let b:current_syntax = "vue"
endif