mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2025-12-09 14:14:46 +08:00
feat: support sass/scss
This commit is contained in:
@@ -26,13 +26,17 @@ let b:vue_js_indentexpr = &indentexpr
|
|||||||
unlet! b:did_indent
|
unlet! b:did_indent
|
||||||
runtime! indent/xml.vim
|
runtime! indent/xml.vim
|
||||||
|
|
||||||
|
" load css indent method
|
||||||
|
unlet! b:did_indent
|
||||||
|
runtime! indent/css.vim
|
||||||
|
|
||||||
" load pug indent method
|
" load pug indent method
|
||||||
unlet! b:did_indent
|
unlet! b:did_indent
|
||||||
runtime! indent/pug.vim
|
runtime! indent/pug.vim
|
||||||
|
|
||||||
" load css indent method
|
" load sass indent method
|
||||||
unlet! b:did_indent
|
unlet! b:did_indent
|
||||||
runtime! indent/css.vim
|
runtime! indent/sass.vim
|
||||||
|
|
||||||
let b:did_indent = 1
|
let b:did_indent = 1
|
||||||
let b:did_vue_indent = 1
|
let b:did_vue_indent = 1
|
||||||
@@ -65,6 +69,11 @@ function! SynsCSS(syns)
|
|||||||
return first_syn =~? '\v^(vueStyle)'
|
return first_syn =~? '\v^(vueStyle)'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! SynsSASS(syns)
|
||||||
|
let first_syn = get(a:syns, 0)
|
||||||
|
return first_syn =~? '\v^(vueStyleSASS)'
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! SynsVueScope(syns)
|
function! SynsVueScope(syns)
|
||||||
let first_syn = get(a:syns, 0)
|
let first_syn = get(a:syns, 0)
|
||||||
return first_syn =~? '\v^(vueStyle)|(vueScript)'
|
return first_syn =~? '\v^(vueStyle)|(vueScript)'
|
||||||
@@ -96,6 +105,9 @@ function! GetVueIndent()
|
|||||||
elseif SynsCSS(prevsyns)
|
elseif SynsCSS(prevsyns)
|
||||||
call s:LogMsg('syntax: css')
|
call s:LogMsg('syntax: css')
|
||||||
let ind = GetCSSIndent()
|
let ind = GetCSSIndent()
|
||||||
|
elseif SynsSASS(prevsyns)
|
||||||
|
call s:LogMsg('syntax: sass')
|
||||||
|
let ind = GetSassIndent()
|
||||||
else
|
else
|
||||||
call s:LogMsg('syntax: javascript')
|
call s:LogMsg('syntax: javascript')
|
||||||
if len(b:vue_js_indentexpr)
|
if len(b:vue_js_indentexpr)
|
||||||
@@ -109,12 +121,12 @@ function! GetVueIndent()
|
|||||||
call s:LogMsg('current is vue tag')
|
call s:LogMsg('current is vue tag')
|
||||||
let ind = 0
|
let ind = 0
|
||||||
elseif (exists("g:vim_vue_plugin_has_init_indent")
|
elseif (exists("g:vim_vue_plugin_has_init_indent")
|
||||||
\ && g:vim_vue_plugin_has_init_indent != 0)
|
\ && g:vim_vue_plugin_has_init_indent == 1)
|
||||||
if SynsVueScope(cursyns) && ind == 0
|
if SynsVueScope(cursyns) && ind == 0
|
||||||
call s:LogMsg('add initial indent')
|
call s:LogMsg('add initial indent')
|
||||||
let ind = &sw
|
let ind = &sw
|
||||||
endif
|
endif
|
||||||
elseif prevline =~? s:vue_end_tag
|
elseif prevline =~? s:vue_tag || prevline =~? s:vue_end_tag
|
||||||
call s:LogMsg('prev is vue tag')
|
call s:LogMsg('prev is vue tag')
|
||||||
let ind = 0
|
let ind = 0
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
" CREDITS: Inspired by mxw/vim-jsx.
|
" CREDITS: Inspired by mxw/vim-jsx.
|
||||||
"
|
"
|
||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
|
if exists("b:current_syntax") && b:current_syntax == 'vue'
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
function! s:LoadDefaultSyntax(group, type)
|
function! s:LoadDefaultSyntax(group, type)
|
||||||
unlet! b:current_syntax
|
unlet! b:current_syntax
|
||||||
exec 'syn include '.a:group.' $VIMRUNTIME/syntax/'.a:type.'.vim'
|
exec 'syn include '.a:group.' $VIMRUNTIME/syntax/'.a:type.'.vim'
|
||||||
@@ -45,19 +49,27 @@ if exists("g:vim_vue_plugin_use_pug")
|
|||||||
call s:LoadFullSyntax('@PugSyntax', 'pug')
|
call s:LoadFullSyntax('@PugSyntax', 'pug')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" If less is enabled, load vim-pug syntax
|
" If less is enabled, load less syntax
|
||||||
if exists("g:vim_vue_plugin_use_less")
|
if exists("g:vim_vue_plugin_use_less")
|
||||||
\ && g:vim_vue_plugin_use_less == 1
|
\ && g:vim_vue_plugin_use_less == 1
|
||||||
call s:LoadFullSyntax('@LessSyntax', 'less')
|
call s:LoadFullSyntax('@LessSyntax', 'less')
|
||||||
syn clear cssDefinition
|
syn clear cssDefinition
|
||||||
syn region lessDefinition
|
syn region lessDefinition matchgroup=cssBraces contains=@LessSyntax
|
||||||
\ matchgroup=cssBraces
|
|
||||||
\ contains=@LessSyntax
|
|
||||||
\ start="{"
|
\ start="{"
|
||||||
\ end="}"
|
\ end="}"
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" If sass is enabled, load sass syntax
|
||||||
|
if exists("g:vim_vue_plugin_use_sass")
|
||||||
|
\ && g:vim_vue_plugin_use_sass == 1
|
||||||
|
call s:LoadFullSyntax('@SassSyntax', 'sass')
|
||||||
|
syn clear cssDefinition
|
||||||
|
syn region sassDefinition matchgroup=cssBraces contains=@SassSyntax
|
||||||
|
\ start="{"
|
||||||
|
\ end="}"
|
||||||
|
endif
|
||||||
|
|
||||||
let b:current_syntax = 'vue'
|
let b:current_syntax = 'vue'
|
||||||
|
|
||||||
" Find tag <template> / <script> / <style> and enable currespond syntax
|
" Find tag <template> / <script> / <style> and enable currespond syntax
|
||||||
@@ -83,6 +95,14 @@ syn region vueStyleLESS
|
|||||||
\ start=+<style lang="less"\(\s.\{-}\)\?>+
|
\ start=+<style lang="less"\(\s.\{-}\)\?>+
|
||||||
\ end=+</style>+
|
\ end=+</style>+
|
||||||
\ keepend contains=@LessSyntax,vueTag
|
\ keepend contains=@LessSyntax,vueTag
|
||||||
|
syn region vueStyleSASS
|
||||||
|
\ start=+<style lang="sass"\(\s.\{-}\)\?>+
|
||||||
|
\ end=+</style>+
|
||||||
|
\ keepend contains=@SassSyntax,vueTag
|
||||||
|
syn region vueStyleSCSS
|
||||||
|
\ start=+<style lang="scss"\(\s.\{-}\)\?>+
|
||||||
|
\ end=+</style>+
|
||||||
|
\ keepend contains=@SassSyntax,vueTag
|
||||||
|
|
||||||
syn region vueTag contained start=+<[^/]+ end=+>+ contains=htmlTagN,htmlString,htmlArg
|
syn region vueTag contained start=+<[^/]+ end=+>+ contains=htmlTagN,htmlString,htmlArg
|
||||||
syn region vueTag contained start=+</+ end=+>+ contains=htmlTagN,htmlString,htmlArg
|
syn region vueTag contained start=+</+ end=+>+ contains=htmlTagN,htmlString,htmlArg
|
||||||
|
|||||||
Reference in New Issue
Block a user