mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2025-12-08 13:44:46 +08:00
Update doc
This commit is contained in:
36
README.md
36
README.md
@@ -86,24 +86,38 @@ let g:vim_vue_plugin_load_full_syntax = 1
|
|||||||
|
|
||||||
## Context based behavior
|
## Context based behavior
|
||||||
|
|
||||||
As there are more than one language in `.vue` file, the different behaviors like mapping or completion may be expected under different tags.
|
As there are more than one language in `.vue` file, the different behaviors like mapping or completion and local options, may be required under different tags or subtypes(current language type).
|
||||||
|
|
||||||
This plugin provides a function to get the tag where the cursor is in.
|
This plugin provides functions to get the tag/subtype where the cursor is in.
|
||||||
|
|
||||||
- `GetVueTag() => String` Return value is `'template'`, `'script'` or `'style'`.
|
- `GetVueTag() => String` Return value is `'template'`, `'script'` or `'style'`.
|
||||||
|
|
||||||
### Example
|
```vim
|
||||||
|
" Example
|
||||||
|
autocmd FileType vue inoremap <buffer><expr> : InsertColon()
|
||||||
|
|
||||||
|
function! InsertColon()
|
||||||
|
let tag = GetVueTag()
|
||||||
|
return tag == 'template' ? ':' : ': '
|
||||||
|
endfunction
|
||||||
|
```
|
||||||
|
|
||||||
|
- `GetVueSubtype() => String` Return value is one of `'html', 'javascript', 'css', 'scss', ...`
|
||||||
|
|
||||||
|
You can also define an event listener function `OnChangeVueSubtype(subtype)` in your `vimrc` to get the subtype and set its local options whenever it changes.
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
autocmd FileType vue inoremap <buffer><expr> : InsertColon()
|
" Set local options based on subtype
|
||||||
|
function! OnChangeVueSubtype(subtype)
|
||||||
function! InsertColon()
|
" echom 'subtype is '.a:subtype
|
||||||
let tag = GetVueTag()
|
if a:subtype == 'html'
|
||||||
|
setlocal commentstring=<!--%s-->
|
||||||
if tag == 'template'
|
setlocal comments=s:<!--,m:\ \ \ \ ,e:-->
|
||||||
return ':'
|
elseif a:subtype =~ 'css'
|
||||||
|
setlocal comments=s1:/*,mb:*,ex:*/ commentstring&
|
||||||
else
|
else
|
||||||
return ': '
|
setlocal commentstring=//%s
|
||||||
|
setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user