LambdaBeta
LambdaBeta

Reputation: 1505

Vim syntax not matching properly

I have a quick vim question. In a syntax file for a given type I have:

if exists("b:current_syntax")
    finish
endif

syntax keyword AssemblyInstruction ADD SUB MUL DIV
syntax keyword AssemblyInstruction LDR STR GET PUT

syntax match AssemblyComment /\v;.*$/
syntax match AssemblyRegister /\v[rR]\d+/

highlight def link AssemblyInstruction Function
highlight def link AssemblyComment Comment
highlight def link AssemblyRegister Type

let b:current_syntax="asm"

When I set syntax=asm it "correctly" highlights ADD SUB MUL and DIV (although it appears to be using the highlighting for preprocessors rather than functions) and it gets the comments correct. However when it comes to LDR STR GET PUT it doesn't highlight them at all. Registers don't highlight at all either.

What's wrong with my syntax file? (it is located in .vim/syntax but I also tried copying it to .vim/after/syntax to no avail)

Upvotes: 2

Views: 305

Answers (1)

ryuichiro
ryuichiro

Reputation: 3865

I think that

if exists("b:current_syntax")
    finish
endif

is saying that if varianle b:current_syntax exists, then finish, do nothing. So if this variable is already let, it will do nothing. It is possible that the original vim syntax file for asm is read from somewhere else. Try :verbose syntax to see what is already set with a syntax, and :set rtp? to list of directories which are searched for runtime files.

If you would like to "overwrite" the syntax with putting your file in .vim/after/syntax, you could remove the if statement.

Upvotes: 3

Related Questions