0

When I open vim, the ~ representing no lines are highlighted according to SpecialComment. So too are the characters in 'listchars' (e.g, :set list lcs=tab:\|\).

How can I insert text that is highlighted as SpecialComment on my own?

I want to make plugin that puts "special comments": for example, create a box comment in any language:

-----------------
|print('hello') |
-----------------

or

----------------------
|printf("hello word")|
----------------------

But I would like the highlighting to use SpecialComment

SpecialComment colors only appear in vim. Is it possible to insert special comment text with the keyboard?

4
  • Try open vim with vim -Nu NONE. Does SpecialComment appear? Now try open vim as usual vim. Does SpecialComment appear?
    – Sunny Pun
    Commented Nov 18, 2017 at 10:10
  • You question is not really clear: could you please specify exactly what appears on your screen and what is your actual problem? SpecialComment is a syntax group name, are you asking what should be highlighted with this group? I feel lijke your question is a duplicate of this one but I'm not sure what you are looking for.
    – statox
    Commented Nov 18, 2017 at 12:58
  • i know how highlighted, hi SpecialComment ctermfg=242, but how insert SpecialComment whit a keyboard? the SpecialComment only appear in vim
    – ramses_ATK
    Commented Nov 18, 2017 at 17:29
  • @ramses_ATK I've edited your question—as it was, the spelling (whit -> with, etc.) made it harder to read. Hope that helps!
    – D. Ben Knoble
    Commented Oct 17, 2019 at 21:11

1 Answer 1

2

Background (added 10/2019): when I originally saw this I considered two possible interpretations of your (OP's) request. First, I thought you might be under the impression that syntax highlighting works in a similar fashion as Bash text coloring, i.e. escape codes or equivalent are inserted in plain text and they dictate coloring and formatting for displayed text (escape codes are hidden in display contexts). This is not how Vim works. No directives or meta text exist. It's a (regex) pattern driven system.

My alternate interpretation was that you want to deliberately type text that will be displayed with a particular highlighting (such as SpecialComment). That's what the original answer covers...

It depends. Highlighting is applied based on the current set of syntax highlighting rules. The current rules are dictated (usually) by the type of file we're editing. You can't open a random file and just know how to enter text "with keyboard" that will get highlighted with SpecialComment coloring. You must be familiar with the rules for the current file type.

For example, if I open a file with extension .java I know one way to see SpecialComment highlighting is to enter the first line of text in a javadoc comment:

/**
 * This text is highlighted as a SpecialComment
 *
 * This text is not.
 */
public void foo() {
...

The rules are stored in files under $VIMRUNTIME/syntax. For the example above it would be java.vim where you'll find:

hi def link javaCommentTitle        SpecialComment

syn region  javaCommentTitle    contained matchgroup=javaDocComment start="/\*\*"   matchgroup=javaCommentTitle keepend end="\.$" end="\.[ \t\r<&]"me=e-1 end="[^{]@"me=s-2,he=s-1 end="\*/"me=s-1,he=s-1 contains=@javaHtml,javaCommentStar,javaTodo,@Spell,javaDocTags,javaDocSeeTag
2
  • 1
    Indeed, after an attempt to clean up the question, I think OP is interested in the former, which is not going to happen
    – D. Ben Knoble
    Commented Oct 17, 2019 at 21:12
  • @D.BenKnoble Yeah. That's where I'd put my money so I'm not sure why I didn't bother mentioning it two years ago...glad it caught my eye this time. As for OP's actual thinking that, alas, may forever remain a mystery...1 rep point and almost a year since last visit.
    – B Layer
    Commented Oct 17, 2019 at 23:41

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.