leafOfTree / vim-vue-plugin

Vim syntax and indent plugin for .vue files
The Unlicense
177 stars 9 forks source link

commentstring in html section is /* */ #26

Closed CantGetRight82 closed 3 years ago

CantGetRight82 commented 3 years ago

This is the best vue syntax i've come across so far. Very nice work!

In between the template tags, I get a commentstring of /%s/ instead of I'm not sure if the plugin should manage the commentstring or if I have a misconfiguration somewhere.

Appreciate any help!

leafOfTree commented 3 years ago

Hi, thank you. It's very kind of you to say that. Since there are more than one language loaded in a .vue file, the local options like commentstring are overrided.

I've added an event when subtype(the language type) changes. You can update the plugin and then add a function to listen to it in your vimrc like below

" Set local options based on subtype
function! OnChangeVueSubtype(subtype)
  echom 'subtype is '.a:subtype
  if 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

Please let me know if you may have any question.

CantGetRight82 commented 3 years ago

Exactly what i needed! Thanks! Closing this issue now.

vittorio-c commented 3 years ago

Hello, thanks for youre reply. This seems to do the trick (comments and commentstring value are indeed changed upon filetype chnges), but I can't get it work with a plugin like NerdComment : I still have wrong comments tokens (/* */) when toggleling comments in html sections.

Would you have, by any chance, any idea what I could do for your code to work with NerdComment ?

Thanks for the pluggin ! It's the only one that fixed my issue with wrong indentation in html sections ! Keep up the good work

vittorio-c commented 3 years ago

Nevermind, I installed tpope / vim-commentary , which works fine when changing "comments" and "commentstring" values.

I guess NerdComment does not make use of those values.

Thanks !

leafOfTree commented 3 years ago

Hi, my pleasure. Glad you solved it.