Created
October 15, 2019 03:22
-
-
Save knopki/d05e76c40c2c06a09ffe2ef4f76365f4 to your computer and use it in GitHub Desktop.
NERDCommenter hooks for html, vue and svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" ------------------------------------- | |
" 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
context_filetype
is context_filetype.vim