Add note to FAQ about nerdcommenter, and add tests for it

This commit is contained in:
Adriaan Zonnenberg
2017-03-26 23:45:45 +02:00
parent e0c07d80c6
commit a9f7aedabf
3 changed files with 77 additions and 0 deletions

View File

@@ -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
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>

View File

@@ -4,6 +4,8 @@ set -e
repos=(
'junegunn/vader.vim'
# languages
'cakebaker/scss-syntax.vim'
'digitaltoad/vim-pug'
'groenewege/vim-less'
@@ -11,6 +13,9 @@ repos=(
'leafgarland/typescript-vim'
'slm-lang/vim-slm'
'wavded/vim-stylus'
# utility
'scrooloose/nerdcommenter'
)
cd "$(dirname "$0")/.."

View 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>