How to turn off a vim highlight group named // - vim

The two characters that introduce comments, namely //, get highlighted in yellow. I don't want this. It happens in files of all types: C, js, html, pl.
When I consult the vim help, it says to do this
:so $VIMRUNTIME/syntax/hitest.vim
to see the highlight groups. (I can also do this with :hi).
I do see a // highlight group. The documentation reads to me as if I could do the following to turn the highlighting off
:hi // NONE
but it doesn't work for me. (Gives me Invalid character in group name.) Mac OS, vim version 8.0

Are you certain that the highlight group in question you're after is named //? I know that's not the name of the highlight group for JavaScript syntax.
You can look at the highlight group definitions in the vim syntax files on Github:
" Define the default highlighting.
" Only when an item doesn't have highlighting yet
hi def link javaScriptComment Comment
hi def link javaScriptLineComment Comment
hi def link javaScriptCommentTodo Todo
hi def link javaScriptSpecial Special
hi def link javaScriptStringS String
hi def link javaScriptStringD String
hi def link javaScriptStringT String
hi def link javaScriptCharacter Character
So :hi javaScriptComment NONE should unhighlight just JavaScript comments. And :hi Comment NONE would unhlighlight comments of all types.

Related

Vim custom syntax, excluding previous match highlighting in a region

I'm writing a vim syntax highlighting script for a file that uses * to denote the start of a comment, except when surrounded by {}. i.e.
* This is a comment, bellow is math
{ x_variable * y_variable + 10.0 }
I would like to highlight only the brackets, and ignore the comment highlighting inside, while still maintaining highlighting for numbers.
So far I have:
syn match mathSym "[{}]"
syn region mathRegion start=+{+ send=+}+ contains=numberHi
syn match commentHi "\*.*$" display contains=#Spell
hi link commentHi Comment
hi link mathSym Statement
hi link mathRegion Normal
I'm not sure if this is the right way to do it. It seem to ignore the * as a comment, and provide number highlighting, but no highlighting for the brackets.
I tried
region mathRegion start=+{+ send=+}+ contains=numberHi, mathSym
but this ends up setting all highlighting in the file to Normal
Your question is missing the numberHi stuff, but this should do the trick:
syn region mathRegion matchgroup=mathSym start=+{+ end=+}+ contains=numberHi,mathSym
syn match commentHi "\*.*$" display contains=#Spell
hi link commentHi Comment
hi link mathSym Statement
Instead of a separate match for mathSym, you can use the matchgroup=mathSym to highlight the start and end.
Also, you don't need to link mathRegion to Normal; just use it for structure.
The x * y won't match inside mathRegion, because it isn't contained in here. I don't see any problem with it.
PS: Do you know the SyntaxAttr.vim - Show syntax highlighting attributes of character under cursor plugin? It's a great help when writing syntaxes.

Custom Vim syntax highlighting only works for some keywords

I'm writing a custom syntax highlighting file for a proprietary language I have to use a lot. I have written a full file but it seems to only use 3 colors. All punctuation is one color, some of the keywords I have specified are another color, and everything else is a third color.
The odd thing is, I removed every match and every redefinition (hi def link) from the file and the highlighting doesn't seem to have changed at all. In fact, I tried adding some other keyword mappings to try to see where it's breaking, but it seems only certain lines are being evaluated for the highlighting. For instance, this line ends up highlighting the proper text:
syn keyword clangImport IMPORT
However, this line (below) doesn't and is a different color despite not even providing any specific highlighting instructions:
syn keyword clangGroupAttributes ?? GN GA GV GL GP GR PV PN SI CN
Why would it only evaluate certain lines of the syn keyword mapping?
Additionally, none of my regex matching worked at all despite using something as simple as "\d\+".

vim - how to match linked sequences in syntax file

I want to create a syntax file in vim for a custom file type I have. Part of the syntax is this line
entry: 1,02:15:00,03:15:00,56,Some String
I would like to match every part separately to assign different colors. entry should be a part, 1 should be a part, 02:15:00 should be a part, 03:15:00 should be a different part, 56 yet another part, Some String a different part, and all ,s as a part. Each of these should be named differently so I can color them with different colors as needed.
I was able to match them with contains, but similar values (first time and second time) get the same name. I also tried using nextgroup to chain them one after another, but this left me with , having many names I need to color separately (and there are many commas in the original file not like the simple example I shown here).
Is there a way to do such syntax highlighting in a proper way?
You can link all comma names to one with
" Adjust the below to make commas have another color.
" It is common that instead of defining colors directly you link
" new highlighting groups to some standard one.
hi def link MySyntaxComma Delimiter
hi def link MySyntaxCommaAfterNumber MySyntaxComma
hi def link MySyntaxCommaAfterFirstTime MySyntaxComma
hi def link MySyntaxCommaAfterSecondTime MySyntaxComma
hi def link MySyntaxCommaAfterSecondNumber MySyntaxComma
You can also use a loop with :execute to hide the repeating rules:
syntax match MySyntaxEntryStart /^entry:\s*/ nextgroup=MySyntaxNumber1
let s:rules=[['Number1', '\d\+'], ['Time1', '\d\d:\d\d:\d\d'], ['Time2', '\d\d:\d\d:\d\d'], ['Number2', '\d\+'], ['String', '.*']]
while !empty(s:rules)
let [s:name, s:reg]=remove(s:rules, 0)
let s:cmd='syntax match MySyntax'.s:name.' /'.s:reg.'/ contained'
if !empty(s:rules)
let s:cmd.=' nextgroup=MySyntaxCommaAfter'.s:name
execute 'syntax match MySyntaxCommaAfter'.s:name.' /,/ contained nextgroup=MySyntax'.s:rules[0][0]
execute 'hi def link MySyntaxCommaAfter'.s:name.' MySyntaxComma'
endif
execute s:cmd
endwhile
unlet s:rules s:cmd s:name s:reg

Vim syntax highlighting

Alright, this is probably a stupid question, but....
I've got a file of source code in a proprietary language. I want to edit said file with VIM, instead of their crummy editor. I'd like basic syntax highlighting of the language, but I don't want to spend a bunch of time rolling my own syntax file.
Therefore, does VIM have a basic source highlighting module? It doesn't need to be perfect, I just want it to cover simple things. Currently, my only choices are no syntax highlighting, pick a random language, or roll my own.
EDIT: Source code sample below
{
function letter do
gposition 0, 0
if gender = "M" do
if language = "SPA" OR state = "PR" do
%male spanish letter
gposition .26, .75
pdfimage "MALE SPANISH.pdf", 1, .93
setcolor truewhite
setfillmode 1
%whitebox
gposition 5.25, 1.25
rectangle 2.5, .5
Could this be the correct language?
http://www.iml.ece.mcgill.ca/~stephan/node/17
Rolling your own syntax highlighting is not difficult at all and it would take a few minutes.
For example, I wrote a DSL (called Konira) that uses Python for the most part, but it fails at highlighting my custom DSL statements. This is how the "extra" highlighting looks:
function! KoniraSyntax() abort
let b:current_syntax = 'konira'
syn match KoniraIt '\v^\s+it\s+'
syn match KoniraSkipIf '\v^\s+skip\s+if'
syn match KoniraDescribe '\v^describe\s+'
syn match KoniraRaises '\v^\s+raises\s+'
syn match KoniraBeforeAll '\v^\s+before\s+all'
syn match KoniraBeforeEach '\v^\s+before\s+each'
syn match KoniraAfterEach '\v^\s+after\s+each'
syn match KoniraAfterAll '\v^\s+after\s+all'
hi def link KoniraSkipIf Statement
hi def link KoniraIt Statement
hi def link KoniraDescribe Statement
hi def link KoniraRaises Identifier
hi def link KoniraBeforeAll Statement
hi def link KoniraBeforeEach Statement
hi def link KoniraAfterAll Statement
hi def link KoniraAfterEach Statement
endfunction
As you can see above, I set the current syntax, then I match via regular expression those
statements that I want, and the I apply the type of highlighting that I need on that match.
And you can call it as a regular function when you know (or if you able to detect) that you are editing such a source file:
call KoniraSyntax()

Vim: C++ symbols' color

VIM: Is it possible to change the color of these symbols:
~!%^&*()-+=[]{},.<>?:/;
like Visual Studio does?
The C/C++ syntaxes are defined in syntax/c.vim and syntax/cpp.vim. If you're using Linux, the main syntax directory is in /usr/share/vimXX/, where XX is the version (e.g. mine are in vim72). I don't know about installation directories on other OSes, but I'm sure you can find it. I'd suggest making a copy of these and placing them in your user vim directory (for example, in Linux, $HOME/.vim/syntax/c.vim and so on). You can then add whatever you like.
The C++ syntax sources the C syntax, so any symbols you want highlighted in both should go in c.vim, and anything for C++ only should be in cpp.vim.
To get syntax highlighting for specific symbols, you'll need to use a syntax match statement, something like:
syn match cUserSpecialCharacter display "[~!%^&*()-+=[\]{},.<>?:;]"
syn match cUserSpecialCharacter display "/[^*/]"me=e-1
syn match cUserSpecialCharacter display "/$"
I called it cUserSpecialCharacter since cCharacter and cSpecialCharacter are already used. The second and third matches are a bit of a kludge to highlight '/' without it matching comment prefixes, which would then override the comment highlighting and break everything. The "display" option tells Vim that it doesn't need to look for this match if it's not going to be displayed - see :help syn-display for an explanation if you like!
Once you've defined a syntax match, you can link it to a highlight group, for example:
hi def link cUserSpecialCharacter cCharacter
This will put it in with the already defined cCharacter group, so it'll get whatever highlighting that gets - in this case, Character. You can see a nice list of highlight groups at the bottom of c.vim for examples. If you really want, you can also hardcode a highlight by doing something like:
hi cUserSpecialCharacter term=reverse ctermfg=15 ctermbg=1 guifg=#ffffff guibg=#800000
(Arbitrary example - my current highlighting for the Error group.) See :help hi for more information on this, or simply :hi to see the list of defined highlighting - plenty of examples. I'd recommend against doing this, though, since it won't change with color schemes.
Yes, you need to edit the C color theme in vimfiles/colors/c.vim I don't know all the theme options one can use, but I'm sure they are documented on http://vim.org/

Resources