leafOfTree/vim-svelte-plugin

Support syntax regions

Closed this issue · 3 comments

jceb commented

Plugins like tcomment are able to select the right comment string based on the syntax region the cursor is in. I noticed that tcomment works great with the standard html syntax definition - the right comment string is chosen when I'm editing within the script tag (// comment) or outside (< !--comment -->).
It would be great if the svelte plugin would support syntax regions as well.

Hi, thanks for your feedback. It reminds me of another issue about commentstring in different tags of Vue. leafOfTree/vim-vue-plugin#26.

I've added the same feature for this plugin. There will be an event if the subtype(the language type) under the cursor changes. It's kind of like syntax region change.
With the latest plugin version, you can add a function like below in your vimrc to listen to the event

" Set local options based on subtype
function! OnChangeSvelteSubtype(subtype)
  echom 'Subtype is '.a:subtype
  if empty(a:subtype) || a:subtype == 'html'
    setlocal commentstring=<!--%s-->
    setlocal comments=s:<!--,m:\ \ \ \ ,e:-->
  elseif a:subtype =~ 'css'
    setlocal comments=s1:/*,mb:*,ex:*/ commentstring&
  else
    setlocal commentstring=//%s
    setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
  endif
endfunction

Then the tcomment should work within different tags as expected. If not, or if there may be any problems, please let me know.

jceb commented

Awesome, this feature works great!

So glad to hear that!