mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2025-12-07 13:14:34 +08:00
feat: support pug syntax and indent
This commit is contained in:
@@ -16,7 +16,8 @@ Plugin works if filetype is set to `javascript.vue`.
|
|||||||
|
|
||||||
Since `.vue` is a combination of CSS, HTML and JavaScript, so is `vim-vue-plugin`. (Like XML and JavaScript for `.jsx`).
|
Since `.vue` is a combination of CSS, HTML and JavaScript, so is `vim-vue-plugin`. (Like XML and JavaScript for `.jsx`).
|
||||||
|
|
||||||
Support `.wpy` files from [WePY](https://tencent.github.io/wepy) too.
|
- Support Pug(`<template lang="pug"`) with [vim-pug][4].
|
||||||
|
- Support `.wpy` files from [WePY](https://tencent.github.io/wepy)
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
@@ -43,3 +44,4 @@ Set global variable to `1` to enable or `0` to disable.
|
|||||||
[1]: https://github.com/mxw/vim-jsx "mxw: vim-jsx"
|
[1]: https://github.com/mxw/vim-jsx "mxw: vim-jsx"
|
||||||
[2]: https://github.com/VundleVim/Vundle.vim
|
[2]: https://github.com/VundleVim/Vundle.vim
|
||||||
[3]: https://vuejs.org/v2/guide/single-file-components.html
|
[3]: https://vuejs.org/v2/guide/single-file-components.html
|
||||||
|
[4]: https://github.com/digitaltoad/vim-pug
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ let b:vue_js_indentexpr = &indentexpr
|
|||||||
unlet b:did_indent
|
unlet b:did_indent
|
||||||
runtime! indent/xml.vim
|
runtime! indent/xml.vim
|
||||||
|
|
||||||
|
" load pug indent method
|
||||||
|
unlet b:did_indent
|
||||||
|
runtime! indent/pug.vim
|
||||||
|
|
||||||
" load css indent method
|
" load css indent method
|
||||||
unlet b:did_indent
|
unlet b:did_indent
|
||||||
runtime! indent/css.vim
|
runtime! indent/css.vim
|
||||||
@@ -45,6 +49,11 @@ function! SynsHTMLish(syns)
|
|||||||
return first_syn =~? '\v^(vueTemplate)'
|
return first_syn =~? '\v^(vueTemplate)'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! SynsPugish(syns)
|
||||||
|
let second_syn = get(a:syns, 1)
|
||||||
|
return second_syn =~? '\v^(vueTemplatePug)'
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! SynsCSSish(syns)
|
function! SynsCSSish(syns)
|
||||||
let first_syn = get(a:syns, 1)
|
let first_syn = get(a:syns, 1)
|
||||||
return first_syn =~? '\v^(vueStyle)'
|
return first_syn =~? '\v^(vueStyle)'
|
||||||
@@ -61,7 +70,10 @@ function! GetVueIndent()
|
|||||||
let cursyns = SynsEOL(v:lnum)
|
let cursyns = SynsEOL(v:lnum)
|
||||||
let prevsyns = SynsEOL(v:lnum - 1)
|
let prevsyns = SynsEOL(v:lnum - 1)
|
||||||
|
|
||||||
if SynsHTMLish(prevsyns)
|
if SynsPugish(prevsyns)
|
||||||
|
call LogMsg('type: pug')
|
||||||
|
let ind = GetPugIndent()
|
||||||
|
elseif SynsHTMLish(prevsyns)
|
||||||
call LogMsg('type: html')
|
call LogMsg('type: html')
|
||||||
let ind = XmlIndentGet(v:lnum, 0)
|
let ind = XmlIndentGet(v:lnum, 0)
|
||||||
|
|
||||||
|
|||||||
@@ -8,22 +8,26 @@
|
|||||||
" CREDITS: Inspired by mxw/vim-jsx.
|
" CREDITS: Inspired by mxw/vim-jsx.
|
||||||
"
|
"
|
||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
|
" Load syntax/*.vim to syntax group
|
||||||
unlet b:current_syntax
|
unlet b:current_syntax
|
||||||
" runtime! syntax/html.vim
|
|
||||||
syn include @HTMLSyntax syntax/html.vim
|
syn include @HTMLSyntax syntax/html.vim
|
||||||
|
|
||||||
|
unlet b:current_syntax
|
||||||
|
syn include @PugSyntax syntax/pug.vim
|
||||||
|
|
||||||
unlet! b:current_syntax
|
unlet! b:current_syntax
|
||||||
syn include @CSSSyntax syntax/css.vim
|
syn include @CSSSyntax syntax/css.vim
|
||||||
|
|
||||||
let b:current_syntax='vue'
|
let b:current_syntax='vue'
|
||||||
|
|
||||||
" Find tag <script> / <style> and enable javascript / css syntax
|
" Find tag <template> / <script> / <style> and enable currespond syntax
|
||||||
syn region vueTemplate start=+<template\(\s.\{-}\)\?>+ end=+</template>+ keepend contains=@HTMLSyntax,vueTag
|
syn region vueTemplate start=+<template\(\s.\{-}\)\?>+ end=+</template>+ keepend contains=vueTemplatePug,@HTMLSyntax,vueTag
|
||||||
|
syn region vueTemplatePug start=+<template lang="pug"\(\s.\{-}\)\?>+ end=+</template>+ contained contains=@PugSyntax,vueTag
|
||||||
syn region vueScript start=+<script\(\s.\{-}\)\?>+ end=+</script>+ keepend contains=@jsAll,jsImport,jsExport,vueTag
|
syn region vueScript start=+<script\(\s.\{-}\)\?>+ end=+</script>+ keepend contains=@jsAll,jsImport,jsExport,vueTag
|
||||||
syn region vueStyle start=+<style\(\s.\{-}\)\?>+ end=+</style>+ keepend contains=@CSSSyntax,@HTMLSyntax,vueTag
|
syn region vueStyle start=+<style\(\s.\{-}\)\?>+ end=+</style>+ keepend contains=@CSSSyntax,@HTMLSyntax,vueTag
|
||||||
|
|
||||||
hi def link vueTag htmlTagName
|
hi def link vueTag htmlTagName
|
||||||
syn match vueTag /\v(tempalte|script|style)/
|
syn match vueTag contained /\v(template|script|style)/
|
||||||
|
|
||||||
" Officially, vim-jsx depends on the pangloss/vim-javascript syntax package
|
" Officially, vim-jsx depends on the pangloss/vim-javascript syntax package
|
||||||
" (and is tested against it exclusively). However, in practice, we make some
|
" (and is tested against it exclusively). However, in practice, we make some
|
||||||
|
|||||||
Reference in New Issue
Block a user