Custom Vim Highlighting (only works with specific file types)
I have this in my vimrc
:
"on will override defaults set. Enable will allow you to set defaults."
syntax enable
...
"attempting to highlight specific keywords so it is easy to see in code."
"see help e410 for more info."
syn keyword JakeKeywords Question TODO Answer JAKEHTTPS
highlight JakeKeywords cterm=bold term=bold ctermbg=black ctermfg=Blue
(Note: for the sake of readability I have finished all quotes)
I have tried inserting the JAKEHTTPS
keyword in:
-
.java
files- in comments
- in code
-
.xml
files- in comments
- in code
-
.jak
files (custom format that I created see below)
The only place that the keyword is highlighted is in the .jak
.
Question: Why are these keywords NOT being highlighted in java code or xml code (and probably other code as well?
~/.vim/ftdetect/jak.vim
:
syn region JakeSubtitle start=+==+ end=+==+
highlight JakeSubtitle ctermbg=black ctermfg=DarkMagenta
syn region JakeTitle start=+===+ end=+===+
highlight JakeTitle ctermbg=black ctermfg=yellow
Note: I created this thread but it has become too cluttered to be useful.
For standard filetypes the syntax tags are cleared before loading the filetype.vim syntax file
You can see the command,
syntax clearin the begining of java.vim and xml.vim syntax files
Just change the lines in vimrc as follows,
au bufread * syn keyword JakeKeywords Question TODO Answer JAKEHTTPS au bufread * highlight JakeKeywords cterm=bold term=bold ctermbg=black ctermfg=BlueThis should work fine...
It may be a matter of the keywords being contained within an overarching region or match area that handles all the highlighting. For example, if these keywords you want highlighted are within a comment region, then the associated syntax file is setting up highlight that applies to the entire comment line and isn't getting overridden by keyword highlighting within the comment. You know this already because comment lines are uniform color and regular keyword highlighting doesn't apply within comments.
To fix the problem above, if it or something like it is your problem, you need to search the java.vim
syntax file and make sure the keyword you're trying to highlight is in the 'Contains' clause of the comment region definitions (and/or all other overarching region definitions within which you want the keyword highlighted).
E.g., one comment region in my syntax file for Java (java.vim
) is this:
syn region javaComment start="/\*" end="\*/" contains=@javaCommentSpecial,javaTodo,@Spell
You would need to add your keyword JakeKeyWords
to the contains clause above if you want those keywords to be highlighted within comment regions. Or just add your new keywords to javaToDo
group, which is already set up to show up with special highlighting within comments.
Not sure what you're doing with the JakeSubTitle
and JakeTitle
regions you're trying to define. Same problem with contains may apply to them. Also, 'syntax match' command is what you want to use to highlight regions that can be matched by a single pattern, 'region' is necessary only for more complex areas (usually multi-line) that can't be matched by a single pattern.