mirror of
https://github.com/posva/vim-vue.git
synced 2025-12-08 10:24:45 +08:00
Add note to FAQ about nerdcommenter, and add tests for it
This commit is contained in:
32
readme.md
32
readme.md
@@ -92,3 +92,35 @@ autocmd BufRead,BufNewFile *.vue setlocal filetype=vue.html.javascript.css
|
|||||||
|
|
||||||
:warning: This may cause problems, because some plugins will then treat the
|
:warning: This may cause problems, because some plugins will then treat the
|
||||||
whole buffer as html/javascript/css instead of only the part inside the tags.
|
whole buffer as html/javascript/css instead of only the part inside the tags.
|
||||||
|
|
||||||
|
### How can I use NERDCommenter in Vue files?
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>
|
||||||
|
To use NERDCommenter with Vue files, you can use its "hooks" feature to
|
||||||
|
temporarily change the filetype. Click for an example.
|
||||||
|
</summary>
|
||||||
|
|
||||||
|
```vim
|
||||||
|
let g:ft = ''
|
||||||
|
function! NERDCommenter_before()
|
||||||
|
if &ft == 'vue'
|
||||||
|
let g:ft = 'vue'
|
||||||
|
let stack = synstack(line('.'), col('.'))
|
||||||
|
if len(stack) > 0
|
||||||
|
let syn = synIDattr((stack)[0], 'name')
|
||||||
|
if len(syn) > 0
|
||||||
|
exe 'setf ' . substitute(tolower(syn), '^vue_', '', '')
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
function! NERDCommenter_after()
|
||||||
|
if g:ft == 'vue'
|
||||||
|
setf vue
|
||||||
|
let g:ft = ''
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ set -e
|
|||||||
|
|
||||||
repos=(
|
repos=(
|
||||||
'junegunn/vader.vim'
|
'junegunn/vader.vim'
|
||||||
|
|
||||||
|
# languages
|
||||||
'cakebaker/scss-syntax.vim'
|
'cakebaker/scss-syntax.vim'
|
||||||
'digitaltoad/vim-pug'
|
'digitaltoad/vim-pug'
|
||||||
'groenewege/vim-less'
|
'groenewege/vim-less'
|
||||||
@@ -11,6 +13,9 @@ repos=(
|
|||||||
'leafgarland/typescript-vim'
|
'leafgarland/typescript-vim'
|
||||||
'slm-lang/vim-slm'
|
'slm-lang/vim-slm'
|
||||||
'wavded/vim-stylus'
|
'wavded/vim-stylus'
|
||||||
|
|
||||||
|
# utility
|
||||||
|
'scrooloose/nerdcommenter'
|
||||||
)
|
)
|
||||||
|
|
||||||
cd "$(dirname "$0")/.."
|
cd "$(dirname "$0")/.."
|
||||||
|
|||||||
40
test/test_nerdcommenter.vader
Normal file
40
test/test_nerdcommenter.vader
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
Execute (Configure NERDCommenter to support Vue files):
|
||||||
|
let g:ft = ''
|
||||||
|
function! NERDCommenter_before()
|
||||||
|
if &ft == 'vue'
|
||||||
|
let g:ft = 'vue'
|
||||||
|
let stack = synstack(line('.'), col('.'))
|
||||||
|
if len(stack) > 0
|
||||||
|
let syn = synIDattr((stack)[0], 'name')
|
||||||
|
if len(syn) > 0
|
||||||
|
exe 'setf ' . substitute(tolower(syn), '^vue_', '', '')
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
function! NERDCommenter_after()
|
||||||
|
if g:ft == 'vue'
|
||||||
|
setf vue
|
||||||
|
let g:ft = ''
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
Given vue:
|
||||||
|
<template>
|
||||||
|
<div></div>
|
||||||
|
</template>
|
||||||
|
<style>
|
||||||
|
.glitters { color: gold }
|
||||||
|
<style>
|
||||||
|
|
||||||
|
Do:
|
||||||
|
j\cc
|
||||||
|
3j\cc
|
||||||
|
|
||||||
|
Expect:
|
||||||
|
<template>
|
||||||
|
<!--<div></div>-->
|
||||||
|
</template>
|
||||||
|
<style>
|
||||||
|
/*.glitters { color: gold }*/
|
||||||
|
<style>
|
||||||
Reference in New Issue
Block a user