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