0

I am using gVim 8.2 from Cygwin. The synax highlighting recognizes code lines starting with "%%" at columns 1 and 2 show the text black characters on orange background. It is not compatible with my color scheme, and my use of cursorline. I wanted to disable this one part of syntax highlighting.

I tried to find the responsible file anyway to see if I could hack it. I found /usr/share/vim/vim82/syntax/matlab.vim. I searched for the possibly responsible line by searching for %% and found:

syn match matlabCellComment     "^%%.*$"
   <...snip...>
hi def link matlabCellComment          Todo

I then browsed the :syn-* help pages and found that it is an entire language. The following seems to turn off the "reverse video" without losing most of the synatx highlighting for Matlab:

" ~/.vim/syntax/matlab.vim
"-------------------------
hi! def link matlabCellComment NONE

However, any lines matching starting with %% at columns 1 and 2 now have no syntax highlighting.

How can I get lines matching ^%% to show up the same way that all comments do?

I suspect that undoing the syn match matlabCellComment "^%%.*$" command might do the trick, but having perused the syn-match page, it's not clear to me how to do this.

2
  • Re: update—from a meta perspective, asking more than one question in a post is not how we do things (unless the case can be made for such tight coupling, which i font see here), and generally adding more questions after an answer is accepted is also not too good. You can always ask a new question. From a vim perspective, this is exactly the purpose of the after directory.
    – D. Ben Knoble
    Feb 7, 2021 at 15:03
  • Hmm, I thought it seemed tightly coupled, since I was asking specifically about syntax highlighting rather than in the context of general commands like one might find in vimrc. From your answer, however, I can see in retrospect that it is the same thing. I've erased the update. I appreciate the clarification on the after folder. Feb 7, 2021 at 16:06

1 Answer 1

2

Try this:

" ~/.vim/after/syntax/matlab.vim
highlight link matlabCellComment SpecialComment

You can also use plain Comment

7
  • Thanks, that worked. Out of curiosity, however, do you know if there is a way to undo a syn match command? Feb 6, 2021 at 17:56
  • @user2153235 outside of something nuclear like syntax clear? Not sure
    – D. Ben Knoble
    Feb 6, 2021 at 18:03
  • Hmm, I don't want syn clear by itself, since that turns off all colouring. From the help, I tried syn clear matlabCellComment, but that didn't have any effect. Feb 6, 2021 at 18:33
  • :syn clear matlabCellComment should work @user2153235 Feb 7, 2021 at 0:18
  • @Martin Tournoij: Thanks for checking! I said that it didn't, but I neglected to say that I tried it in the ~/.vim/syntax/matlab.vim. I updated my question with the details, but am still hoping there is a way to make it work in the user-specific matlab.vim file. Feb 7, 2021 at 1:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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