mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2025-12-07 21:24:50 +08:00
docs: add context based behavior
This commit is contained in:
26
README.md
26
README.md
@@ -24,7 +24,6 @@ Vim syntax and indent plugin for `.vue` files. Mainly inspired by [mxw/vim-jsx][
|
||||
|
||||
Plugin works if `filetype` is set to `vue`. Please stay up to date. Feel free to open an issue or a pull request.
|
||||
|
||||
**Note**: `filetype` used to be set to `javascript.vue`, which caused `javascript`syntax to be loaded multiple times and a significant delay. Now it is `vue` and autocmds for `javascript` have to be manually added for `vue`.
|
||||
|
||||
## How it works
|
||||
|
||||
@@ -56,10 +55,35 @@ Ex:
|
||||
|
||||
\*: Vim may be slow if the feature is enabled. Find balance between syntax highlight and speed. By the way, custom syntax could be added in `~/.vim/syntax` or `$VIM/vimfiles/syntax`.
|
||||
|
||||
**Note**: `filetype` used to be set to `javascript.vue`, which caused `javascript`syntax to be loaded multiple times and a significant delay. Now it is `vue` so autocmds and other settings for `javascript` have to be manually enabled for `vue`.
|
||||
|
||||
## Screenshot
|
||||
|
||||

|
||||
|
||||
## Context based behavior
|
||||
|
||||
As there are more than one language in `.vue` file, different behavior like mapping or completion may be expected under different tag.
|
||||
|
||||
This plugin provides a Function to get the tag the cursor is in.
|
||||
|
||||
- `GetVueTag() => String` Return value is 'template', 'script' or 'style'.
|
||||
|
||||
### Example
|
||||
|
||||
```vim
|
||||
autocmd FileType vue inoremap <buffer><expr> : InsertColon()
|
||||
|
||||
function! InsertColon()
|
||||
let tag = GetVueTag()
|
||||
if tag == 'template'
|
||||
return ':'
|
||||
else
|
||||
return ': '
|
||||
endif
|
||||
endfunction
|
||||
```
|
||||
|
||||
## Acknowledgments & Refs
|
||||
|
||||
[mxw/vim-jsx][1]
|
||||
|
||||
Reference in New Issue
Block a user