0

The assigned character for comments is " for vimscript. But i want to change it to some other character (like * or # for example).

Based on this post, it seems like the string setlocal commentstring=\"%s in the file vim.vim (which is usually in /usr/local/share/vim/vimversion_number_here) is only to add appropriate comment tags around Vim fold markers (thanks to @BLayer in the comment for pointing this out).

But if possible, i would want to have a third character for comment (since # work for vimscript9 for comment, though i don't know where it's defined).

How could i do this?

9
  • read my updated post, found a way on how to do it :P @BLayer Commented Sep 18, 2020 at 1:54
  • 1
    Really? Damn. That's awful surprising. It's not allowed in most languages I'm aware of.
    – B Layer
    Commented Sep 18, 2020 at 1:54
  • To answer the other part of your comment above, the same method i found apply for the other filetype (.c, .py, etc) since they have their own comment character assigned, in the ftplugin directory, as i described in my post. Thing is, i don't know how to set more than three different character for comment, as the same time (since the # char already work + " for vimscript) @BLayer Commented Sep 18, 2020 at 1:56
  • 1
    What I've read says this is only to add appropriate comment tags around Vim fold markers....i.e. dynamic and depending on current filetype...when, for instance, you add a fold with zf. Example: Comment out characters for zf I've never encountered this setting before, TBH.
    – B Layer
    Commented Sep 18, 2020 at 2:04
  • 1
    Interesting...I guess I'll edit my post to reflect this then :) thanks for looking it up! @BLayer Commented Sep 18, 2020 at 2:05

1 Answer 1

1

It seems you're under the impression that the 'commentstring' option can be used to set which character or format is recognized as a comment in Vimscript... But that's not at all what it is about!

It's about telling Vim which format is recognized as a comment in the current language (as in, the current filetype), so that if Vim needs to insert a comment somewhere, it can use this option as a template.

See :help 'commentstring':

A template for a comment. The %s in the value is replaced with the comment text. Currently only used to add markers for folding, see fold-marker.

Even though it looks like Vim itself doesn't make much use of this option, it's also used by plug-ins that manage comments, for example vim-commentary leverages the option for its own configuration.

So, in short, same as you can't really change what a comment in C or Python or Java is, you can't really change what a comment in Vimscript is... It's part of the language, it's baked in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.