mirror of
https://github.com/posva/vim-vue.git
synced 2026-02-22 00:18:25 +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
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user