Skip to content

Instantly share code, notes, and snippets.

@knopki
Created October 15, 2019 03:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knopki/d05e76c40c2c06a09ffe2ef4f76365f4 to your computer and use it in GitHub Desktop.
Save knopki/d05e76c40c2c06a09ffe2ef4f76365f4 to your computer and use it in GitHub Desktop.
NERDCommenter hooks for html, vue and svelte
" -------------------------------------
" Context filetypes for NERDCommenter and more
" -------------------------------------
if !exists('g:context_filetype#same_filetypes')
let g:context_filetype#filetypes = {}
endif
let g:context_filetype#filetypes.svelte =
\ [
\ {'filetype' : 'javascript', 'start' : '<script>', 'end' : '</script>'},
\ {
\ 'filetype': 'typescript',
\ 'start': '<script\%( [^>]*\)\? \%(ts\|lang="\%(ts\|typescript\)"\)\%( [^>]*\)\?>',
\ 'end': '</script>',
\ },
\ {'filetype' : 'css', 'start' : '<style \?.*>', 'end' : '</style>'},
\ ]
" -------------------------------------
" NERDCommenter
" -------------------------------------
let g:ft = ''
fu! NERDCommenter_before()
if (&ft == 'html') || (&ft == 'svelte') || (&ft == 'vue')
let g:ft = &ft
let cfts = context_filetype#get_filetypes()
if len(cfts) > 0
if cfts[0] == 'svelte'
let cft = 'html'
elseif cfts[0] == 'scss'
let cft = 'css'
else
let cft = cfts[0]
endif
exe 'setf ' . cft
endif
endif
endfu
fu! NERDCommenter_after()
if (g:ft == 'html') || (g:ft == 'svelte') || (g:ft == 'vue')
exec 'setf ' . g:ft
let g:ft = ''
endif
endfu
@knopki
Copy link
Author

knopki commented Oct 15, 2019

context_filetype is context_filetype.vim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment