mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2025-12-07 21:24:50 +08:00
fix: use unix fileformat for .vim files
This commit is contained in:
32
filetype.vim
32
filetype.vim
@@ -1,16 +1,16 @@
|
||||
au BufNewFile,BufRead *.vue,*.wpy call s:setFileType()
|
||||
|
||||
function! s:setFileType()
|
||||
" enable javascript autocmds first
|
||||
let &filetype = 'javascript'
|
||||
|
||||
" then set filetype
|
||||
let &filetype = 'javascript.vue'
|
||||
endfunction
|
||||
|
||||
if !exists("g:vim_vue_plugin_has_init_indent")
|
||||
let ext = expand("%:e")
|
||||
if ext == 'wpy'
|
||||
let g:vim_vue_plugin_has_init_indent = 1
|
||||
endif
|
||||
endif
|
||||
au BufNewFile,BufRead *.vue,*.wpy call s:setFileType()
|
||||
|
||||
function! s:setFileType()
|
||||
" enable javascript autocmds first
|
||||
let &filetype = 'javascript'
|
||||
|
||||
" then set filetype
|
||||
let &filetype = 'javascript.vue'
|
||||
endfunction
|
||||
|
||||
if !exists("g:vim_vue_plugin_has_init_indent")
|
||||
let ext = expand("%:e")
|
||||
if ext == 'wpy'
|
||||
let g:vim_vue_plugin_has_init_indent = 1
|
||||
endif
|
||||
endif
|
||||
|
||||
250
indent/vue.vim
250
indent/vue.vim
@@ -1,125 +1,125 @@
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" Vim indent file
|
||||
"
|
||||
" Language: Vue (Wepy)
|
||||
" Maintainer: leafOfTree <leafvocation@gmail.com>
|
||||
"
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
se sw=2 ts=2
|
||||
|
||||
let s:name = 'vim-vue-plugin'
|
||||
|
||||
" Save the current JavaScript indentexpr.
|
||||
let b:vue_js_indentexpr = &indentexpr
|
||||
|
||||
" load xml indent method
|
||||
unlet b:did_indent
|
||||
runtime! indent/xml.vim
|
||||
|
||||
" load pug indent method
|
||||
unlet b:did_indent
|
||||
runtime! indent/pug.vim
|
||||
|
||||
" load css indent method
|
||||
unlet b:did_indent
|
||||
runtime! indent/css.vim
|
||||
|
||||
let b:did_indent = 1
|
||||
let b:did_vue_indent = 1
|
||||
|
||||
" JavaScript indentkeys
|
||||
setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e
|
||||
" XML indentkeys
|
||||
setlocal indentkeys+=*<Return>,<>>,<<>,/
|
||||
|
||||
let s:vue_tag = '\v\<\/?(template|script|style)'
|
||||
let s:vue_tag_no_indent = '\v\<\/?(script|style)'
|
||||
let s:end_tag = '^\s*\/\?>\s*'
|
||||
|
||||
setlocal indentexpr=GetVueIndent()
|
||||
|
||||
function! SynsEOL(lnum)
|
||||
let lnum = prevnonblank(a:lnum)
|
||||
let col = strlen(getline(lnum))
|
||||
return map(synstack(lnum, col), 'synIDattr(v:val, "name")')
|
||||
endfunction
|
||||
|
||||
function! SynsHTMLish(syns)
|
||||
let first_syn = get(a:syns, 0)
|
||||
return first_syn =~? '\v^(vueTemplate)'
|
||||
endfunction
|
||||
|
||||
function! SynsPugish(syns)
|
||||
let second_syn = get(a:syns, 1)
|
||||
return second_syn =~? '\v^(vueTemplatePug)'
|
||||
endfunction
|
||||
|
||||
function! SynsCSSish(syns)
|
||||
let first_syn = get(a:syns, 0)
|
||||
return first_syn =~? '\v^(vueStyle)'
|
||||
endfunction
|
||||
|
||||
function! SynsVueScope(syns)
|
||||
let first_syn = get(a:syns, 0)
|
||||
return first_syn =~? '\v^(vueStyle)|(vueTemplate)|(vueScript)'
|
||||
endfunction
|
||||
|
||||
function! GetVueIndent()
|
||||
let curline = getline(v:lnum)
|
||||
let prevline = getline(v:lnum - 1)
|
||||
let cursyns = SynsEOL(v:lnum)
|
||||
let prevsyns = SynsEOL(v:lnum - 1)
|
||||
|
||||
if SynsPugish(prevsyns)
|
||||
call LogMsg('type: pug')
|
||||
let ind = GetPugIndent()
|
||||
elseif SynsHTMLish(prevsyns)
|
||||
call LogMsg('type: html')
|
||||
let ind = XmlIndentGet(v:lnum, 0)
|
||||
|
||||
" Align '/>' and '>' with '<' for multiline tags.
|
||||
if curline =~? s:end_tag
|
||||
let ind = ind - &sw
|
||||
endif
|
||||
" Then correct the indentation of any element following '/>' or '>'.
|
||||
if prevline =~? s:end_tag
|
||||
let ind = ind + &sw
|
||||
endif
|
||||
|
||||
elseif SynsCSSish(prevsyns)
|
||||
call LogMsg('type: css')
|
||||
let ind = GetCSSIndent()
|
||||
else
|
||||
call LogMsg('type: javascript')
|
||||
if len(b:vue_js_indentexpr)
|
||||
let ind = eval(b:vue_js_indentexpr)
|
||||
else
|
||||
let ind = cindent(v:lnum)
|
||||
endif
|
||||
endif
|
||||
|
||||
if curline =~? s:vue_tag
|
||||
call LogMsg('cur vue tag')
|
||||
let ind = 0
|
||||
elseif (exists("g:vim_vue_plugin_has_init_indent")
|
||||
\ && g:vim_vue_plugin_has_init_indent != 0)
|
||||
if SynsVueScope(cursyns) && ind == 0
|
||||
call LogMsg('add init')
|
||||
let ind = &sw
|
||||
endif
|
||||
else
|
||||
if prevline =~? s:vue_tag_no_indent
|
||||
call LogMsg('prev vue tag')
|
||||
let ind = 0
|
||||
endif
|
||||
endif
|
||||
call LogMsg('result ind: '.ind)
|
||||
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
function! LogMsg(msg)
|
||||
if g:vim_vue_plugin_debug
|
||||
echom '['.s:name.'] '. a:msg
|
||||
endif
|
||||
endfunction
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" Vim indent file
|
||||
"
|
||||
" Language: Vue (Wepy)
|
||||
" Maintainer: leafOfTree <leafvocation@gmail.com>
|
||||
"
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
se sw=2 ts=2
|
||||
|
||||
let s:name = 'vim-vue-plugin'
|
||||
|
||||
" Save the current JavaScript indentexpr.
|
||||
let b:vue_js_indentexpr = &indentexpr
|
||||
|
||||
" load xml indent method
|
||||
unlet b:did_indent
|
||||
runtime! indent/xml.vim
|
||||
|
||||
" load pug indent method
|
||||
unlet b:did_indent
|
||||
runtime! indent/pug.vim
|
||||
|
||||
" load css indent method
|
||||
unlet b:did_indent
|
||||
runtime! indent/css.vim
|
||||
|
||||
let b:did_indent = 1
|
||||
let b:did_vue_indent = 1
|
||||
|
||||
" JavaScript indentkeys
|
||||
setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e
|
||||
" XML indentkeys
|
||||
setlocal indentkeys+=*<Return>,<>>,<<>,/
|
||||
|
||||
let s:vue_tag = '\v\<\/?(template|script|style)'
|
||||
let s:vue_tag_no_indent = '\v\<\/?(script|style)'
|
||||
let s:end_tag = '^\s*\/\?>\s*'
|
||||
|
||||
setlocal indentexpr=GetVueIndent()
|
||||
|
||||
function! SynsEOL(lnum)
|
||||
let lnum = prevnonblank(a:lnum)
|
||||
let col = strlen(getline(lnum))
|
||||
return map(synstack(lnum, col), 'synIDattr(v:val, "name")')
|
||||
endfunction
|
||||
|
||||
function! SynsHTMLish(syns)
|
||||
let first_syn = get(a:syns, 0)
|
||||
return first_syn =~? '\v^(vueTemplate)'
|
||||
endfunction
|
||||
|
||||
function! SynsPugish(syns)
|
||||
let second_syn = get(a:syns, 1)
|
||||
return second_syn =~? '\v^(vueTemplatePug)'
|
||||
endfunction
|
||||
|
||||
function! SynsCSSish(syns)
|
||||
let first_syn = get(a:syns, 0)
|
||||
return first_syn =~? '\v^(vueStyle)'
|
||||
endfunction
|
||||
|
||||
function! SynsVueScope(syns)
|
||||
let first_syn = get(a:syns, 0)
|
||||
return first_syn =~? '\v^(vueStyle)|(vueTemplate)|(vueScript)'
|
||||
endfunction
|
||||
|
||||
function! GetVueIndent()
|
||||
let curline = getline(v:lnum)
|
||||
let prevline = getline(v:lnum - 1)
|
||||
let cursyns = SynsEOL(v:lnum)
|
||||
let prevsyns = SynsEOL(v:lnum - 1)
|
||||
|
||||
if SynsPugish(prevsyns)
|
||||
call LogMsg('type: pug')
|
||||
let ind = GetPugIndent()
|
||||
elseif SynsHTMLish(prevsyns)
|
||||
call LogMsg('type: html')
|
||||
let ind = XmlIndentGet(v:lnum, 0)
|
||||
|
||||
" Align '/>' and '>' with '<' for multiline tags.
|
||||
if curline =~? s:end_tag
|
||||
let ind = ind - &sw
|
||||
endif
|
||||
" Then correct the indentation of any element following '/>' or '>'.
|
||||
if prevline =~? s:end_tag
|
||||
let ind = ind + &sw
|
||||
endif
|
||||
|
||||
elseif SynsCSSish(prevsyns)
|
||||
call LogMsg('type: css')
|
||||
let ind = GetCSSIndent()
|
||||
else
|
||||
call LogMsg('type: javascript')
|
||||
if len(b:vue_js_indentexpr)
|
||||
let ind = eval(b:vue_js_indentexpr)
|
||||
else
|
||||
let ind = cindent(v:lnum)
|
||||
endif
|
||||
endif
|
||||
|
||||
if curline =~? s:vue_tag
|
||||
call LogMsg('cur vue tag')
|
||||
let ind = 0
|
||||
elseif (exists("g:vim_vue_plugin_has_init_indent")
|
||||
\ && g:vim_vue_plugin_has_init_indent != 0)
|
||||
if SynsVueScope(cursyns) && ind == 0
|
||||
call LogMsg('add init')
|
||||
let ind = &sw
|
||||
endif
|
||||
else
|
||||
if prevline =~? s:vue_tag_no_indent
|
||||
call LogMsg('prev vue tag')
|
||||
let ind = 0
|
||||
endif
|
||||
endif
|
||||
call LogMsg('result ind: '.ind)
|
||||
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
function! LogMsg(msg)
|
||||
if g:vim_vue_plugin_debug
|
||||
echom '['.s:name.'] '. a:msg
|
||||
endif
|
||||
endfunction
|
||||
|
||||
118
syntax/vue.vim
118
syntax/vue.vim
@@ -1,59 +1,59 @@
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" Vim syntax file
|
||||
"
|
||||
" Language: Vue (Wepy)
|
||||
" Maintainer: leaf <leafvocation@gmail.com>
|
||||
" Depends: pangloss/vim-javascript
|
||||
"
|
||||
" CREDITS: Inspired by mxw/vim-jsx.
|
||||
"
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" Load syntax/*.vim to syntax group
|
||||
if exists("g:vim_vue_plugin_load_full_syntax")
|
||||
\ && g:vim_vue_plugin_load_full_syntax == 1
|
||||
unlet b:current_syntax
|
||||
syn include @HTMLSyntax syntax/html.vim
|
||||
|
||||
unlet! b:current_syntax
|
||||
syn include @CSSSyntax syntax/css.vim
|
||||
else
|
||||
unlet b:current_syntax
|
||||
syn include @HTMLSyntax $vimruntime/syntax/html.vim
|
||||
silent! syn include @HTMLSyntax $vimruntime/../vimfiles/syntax/html.vim
|
||||
|
||||
unlet! b:current_syntax
|
||||
syn include @CSSSyntax $vimruntime/syntax/css.vim
|
||||
silent! syn include @HTMLSyntax $vimruntime/../vimfiles/syntax/css.vim
|
||||
endif
|
||||
|
||||
if exists("g:vim_vue_plugin_use_pug")
|
||||
\ && g:vim_vue_plugin_use_pug == 1
|
||||
unlet b:current_syntax
|
||||
syn include @PugSyntax syntax/pug.vim
|
||||
endif
|
||||
|
||||
let b:current_syntax='vue'
|
||||
|
||||
" Find tag <template> / <script> / <style> and enable currespond syntax
|
||||
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 vueStyle start=+<style\(\s.\{-}\)\?>+ end=+</style>+ keepend contains=@CSSSyntax,@HTMLSyntax,vueTag
|
||||
|
||||
hi def link vueTag htmlTagName
|
||||
syn match vueTag contained /\v(template|script|style)/
|
||||
|
||||
" Officially, vim-jsx depends on the pangloss/vim-javascript syntax package
|
||||
" (and is tested against it exclusively). However, in practice, we make some
|
||||
" effort towards compatibility with other packages.
|
||||
"
|
||||
" These are the plugin-to-syntax-element correspondences:
|
||||
"
|
||||
" - pangloss/vim-javascript: jsBlock, jsExpression
|
||||
" - jelera/vim-javascript-syntax: javascriptBlock
|
||||
" - othree/yajs.vim: javascriptNoReserved
|
||||
|
||||
|
||||
" Vue attributes should color as JS. Note the trivial end pattern; we let
|
||||
" jsBlock take care of ending the region.
|
||||
syn region xmlString contained start=+{+ end=++ contains=jsBlock,javascriptBlock
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" Vim syntax file
|
||||
"
|
||||
" Language: Vue (Wepy)
|
||||
" Maintainer: leaf <leafvocation@gmail.com>
|
||||
" Depends: pangloss/vim-javascript
|
||||
"
|
||||
" CREDITS: Inspired by mxw/vim-jsx.
|
||||
"
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" Load syntax/*.vim to syntax group
|
||||
if exists("g:vim_vue_plugin_load_full_syntax")
|
||||
\ && g:vim_vue_plugin_load_full_syntax == 1
|
||||
unlet b:current_syntax
|
||||
syn include @HTMLSyntax syntax/html.vim
|
||||
|
||||
unlet! b:current_syntax
|
||||
syn include @CSSSyntax syntax/css.vim
|
||||
else
|
||||
unlet b:current_syntax
|
||||
syn include @HTMLSyntax $vimruntime/syntax/html.vim
|
||||
silent! syn include @HTMLSyntax $vimruntime/../vimfiles/syntax/html.vim
|
||||
|
||||
unlet! b:current_syntax
|
||||
syn include @CSSSyntax $vimruntime/syntax/css.vim
|
||||
silent! syn include @HTMLSyntax $vimruntime/../vimfiles/syntax/css.vim
|
||||
endif
|
||||
|
||||
if exists("g:vim_vue_plugin_use_pug")
|
||||
\ && g:vim_vue_plugin_use_pug == 1
|
||||
unlet b:current_syntax
|
||||
syn include @PugSyntax syntax/pug.vim
|
||||
endif
|
||||
|
||||
let b:current_syntax='vue'
|
||||
|
||||
" Find tag <template> / <script> / <style> and enable currespond syntax
|
||||
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 vueStyle start=+<style\(\s.\{-}\)\?>+ end=+</style>+ keepend contains=@CSSSyntax,@HTMLSyntax,vueTag
|
||||
|
||||
hi def link vueTag htmlTagName
|
||||
syn match vueTag contained /\v(template|script|style)/
|
||||
|
||||
" Officially, vim-jsx depends on the pangloss/vim-javascript syntax package
|
||||
" (and is tested against it exclusively). However, in practice, we make some
|
||||
" effort towards compatibility with other packages.
|
||||
"
|
||||
" These are the plugin-to-syntax-element correspondences:
|
||||
"
|
||||
" - pangloss/vim-javascript: jsBlock, jsExpression
|
||||
" - jelera/vim-javascript-syntax: javascriptBlock
|
||||
" - othree/yajs.vim: javascriptNoReserved
|
||||
|
||||
|
||||
" Vue attributes should color as JS. Note the trivial end pattern; we let
|
||||
" jsBlock take care of ending the region.
|
||||
syn region xmlString contained start=+{+ end=++ contains=jsBlock,javascriptBlock
|
||||
|
||||
Reference in New Issue
Block a user