mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2025-12-08 21:54:46 +08:00
feat: support css indent
This commit is contained in:
25
README.md
25
README.md
@@ -1,5 +1,26 @@
|
|||||||
# vim-vue
|
# vim-vue-plugin
|
||||||
|
|
||||||
Vim plugin for `.vue` file syntax and indent. Mainly inspired by [mxw/vim-jsx][1]
|
Vim plugin for `.vue` files syntax and indent. Mainly inspired by [mxw/vim-jsx][1].
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
- Use [VundleVim][2]
|
||||||
|
|
||||||
|
Plugin 'leafOfTree/vim-vue-plugin'
|
||||||
|
|
||||||
|
- Or manual: download 'vim-vue-plugin' and drop it in `Vim/vimfiles`.
|
||||||
|
|
||||||
|
Plugin works if filetype is set to `javascript.vue`.
|
||||||
|
|
||||||
|
## How it works
|
||||||
|
|
||||||
|
Since `.vue` is a combination of CSS, HTML and JavaScript, so is `vim-vue-plugin`. (Like XML and JavaScript for `.jsx`).
|
||||||
|
|
||||||
|
Support `.wpy` files too.
|
||||||
|
|
||||||
|
## Config
|
||||||
|
|
||||||
|
## Screenshot
|
||||||
|
|
||||||
[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
|
||||||
|
|||||||
@@ -1,27 +1,28 @@
|
|||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
" Vim ftplugin file
|
" Vim indent file
|
||||||
"
|
"
|
||||||
" Language: Vue (Wepy)
|
" Language: Vue (Wepy)
|
||||||
" Maintainer: leafOfTree <leafvocation@gmail.com>
|
" Maintainer: leafOfTree <leafvocation@gmail.com>
|
||||||
"
|
"
|
||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
|
|
||||||
|
if exists("b:did_vue_indent")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
se sw=2 ts=2
|
se sw=2 ts=2
|
||||||
|
|
||||||
" Save the current JavaScript indentexpr.
|
" Save the current JavaScript indentexpr.
|
||||||
let b:vue_js_indentexpr = &indentexpr
|
let b:vue_js_indentexpr = &indentexpr
|
||||||
|
|
||||||
" Prologue; load XML indentation.
|
unlet b:did_indent
|
||||||
if exists('b:did_indent')
|
|
||||||
let s:did_indent=b:did_indent
|
|
||||||
unlet b:did_indent
|
|
||||||
endif
|
|
||||||
|
|
||||||
runtime! indent/xml.vim
|
runtime! indent/xml.vim
|
||||||
|
|
||||||
if exists('s:did_indent')
|
unlet b:did_indent
|
||||||
let b:did_indent=s:did_indent
|
runtime! indent/css.vim
|
||||||
endif
|
|
||||||
|
let b:did_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
|
||||||
@@ -44,6 +45,11 @@ function! SynsHTMLish(syns)
|
|||||||
return last_syn =~? '\v^(html)'
|
return last_syn =~? '\v^(html)'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! SynsCSSish(syns)
|
||||||
|
let last_syn = get(a:syns, -1)
|
||||||
|
return last_syn =~? '\v^(css)|(less)|(sass)'
|
||||||
|
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)'
|
||||||
@@ -51,6 +57,7 @@ endfunction
|
|||||||
|
|
||||||
function! GetVueIndent()
|
function! GetVueIndent()
|
||||||
let curline = getline(v:lnum)
|
let curline = getline(v:lnum)
|
||||||
|
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)
|
||||||
|
|
||||||
@@ -61,21 +68,27 @@ function! GetVueIndent()
|
|||||||
if curline =~? s:end_tag
|
if curline =~? s:end_tag
|
||||||
let ind = ind - &sw
|
let ind = ind - &sw
|
||||||
endif
|
endif
|
||||||
|
elseif SynsCSSish(prevsyns)
|
||||||
|
let ind = GetCSSIndent()
|
||||||
else
|
else
|
||||||
if curline =~ s:vue_tag
|
if len(b:vue_js_indentexpr)
|
||||||
let ind = 0
|
let ind = eval(b:vue_js_indentexpr)
|
||||||
else
|
else
|
||||||
if len(b:vue_js_indentexpr)
|
let ind = cindent(v:lnum)
|
||||||
let ind = eval(b:vue_js_indentexpr)
|
|
||||||
else
|
|
||||||
let ind = cindent(v:lnum)
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if SynsVueScope(cursyns) && ind == 0
|
if curline =~? s:vue_tag
|
||||||
let ind = &sw
|
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
|
||||||
|
let ind = &sw
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
if prevline =~? s:vue_tag
|
||||||
|
let ind = 0
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return ind
|
return ind
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
" Vim syntax file
|
" Vim syntax file
|
||||||
"
|
"
|
||||||
" Language: Vue (JavaScript)
|
" Language: Vue (Wepy)
|
||||||
" Maintainer: leafOfTree <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.
|
||||||
@@ -20,7 +20,12 @@ let b:current_syntax='vue'
|
|||||||
" Find tag <script> / <style> and enable javascript / css syntax
|
" Find tag <script> / <style> and enable javascript / css syntax
|
||||||
syn region vueTemplate start=+<template\(\s.\{-}\)\?>+ end=+</template>+ keepend contains=@HTMLSyntax
|
syn region vueTemplate start=+<template\(\s.\{-}\)\?>+ end=+</template>+ keepend contains=@HTMLSyntax
|
||||||
syn region vueScript start=+<script\(\s.\{-}\)\?>+ end=+</script>+ keepend contains=@jsAll,jsImport,jsExport
|
syn region vueScript start=+<script\(\s.\{-}\)\?>+ end=+</script>+ keepend contains=@jsAll,jsImport,jsExport
|
||||||
syn region vueStyle start=+<style\(\s.\{-}\)\?>+ end=+</style>+ keepend contains=@CSSSyntax
|
syn region vueStyle start=+<style\(\s.\{-}\)\?>+ end=+</style>+ keepend contains=@CSSSyntax,@HTMLSyntax
|
||||||
|
|
||||||
|
hi def link vueTag htmlTagName
|
||||||
|
hi! link vueTemplate vueTag
|
||||||
|
hi! link vueScript vueTag
|
||||||
|
hi! link vueStyle vueTag
|
||||||
|
|
||||||
" 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