I would like to extend my JS syntax highlighting with highlight certain functions that will be commonly used in my program. I am using janus to keep all my plugins in order. Right now I have a file in there called vim-chino
and then in there I have a syntax
folder and a ftdetect
folder. In both I have a chino.vim
file. This is my syntax/chino.vim
file:
if !exists("main_syntax")
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
let main_syntax = 'javascript'
endif
syn match chinoKeywords "ChinoView"
hi def link chinoKeywords Function
let b:current_syntax = "javascript"
if main_syntax == 'javascript'
unlet main_syntax
endif
and in my ftdetect/chino.vim
I have:
function! s:DetectJS()
if getline(1) =~# '^#!.*/bin/env\s\+node\>'
setfiletype javascript
endif
endfunction
autocmd BufNewFile,BufRead * call s:DetectJS()
I would like it to highlight ChinoView
in any javascript file. I feel like the syntax highlighting for JS is either overriding it or it this is not being read.
EDIT: If I had to guess where something was happening was that when it looks at b:current_syntax
it already has a syntax so it quits.
Your
ftplugin/chino.vim
sets the syntax tojavascript
, but the extra highlighting you've defined is for the new chino syntax. That doesn't fit together.If you just want an extra keyword highlighted in all Javascript, you can just let the default Vim detection happen and add those lines to
after/syntax/javascript.vim
:However, if you want to define a different chino filetype depending on the file's shebang line, you need to
:setfiletype chino
in yourftplugin/chino.vim
, and then include the default javascript syntax in yoursyntax/chino.vim
(after the initial checks, before you setb:current_syntax
):