1

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.

3
  • Can you check to see if :syn list chinoKeywords outputs anything. If it doesn't it means that your syn match isn't taking effect. Commented Apr 25, 2013 at 21:36
  • Yea it says that No such highlight group name: chinoKeywords. I have also tried syn keyword chinoKeywords ChinoView but that doesn't work either. Commented Apr 25, 2013 at 21:44
  • Can you try just adding syn match chinoKeywords "ChinoView" and hi def link chinoKeywords Function to s:DetectJS() instead of your syntax/chino.vim. (after the setfiletype javascript) Commented Apr 26, 2013 at 1:54

1 Answer 1

6

Your ftplugin/chino.vim sets the syntax to javascript, 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 (you may have to create this directory and file):

syn match chinoKeywords "ChinoView"
hi def link chinoKeywords Function

However, if you want to define a different chino filetype depending on the file's shebang line, you need to :setfiletype chino in your ftplugin/chino.vim, and then include the default javascript syntax in your syntax/chino.vim (after the initial checks, before you set b:current_syntax):

runtime! syntax/javascript.vim syntax/javascript/*.vim
Sign up to request clarification or add additional context in comments.

4 Comments

I am already using a plugin to extend my javascript highlighting. Is there anyway to add additional highlighting without editing that plugin's .vim file?
As I said, ~/.vim/after/syntax/javascript.vim is sourced after the original syntax script. Try putting your additions there.
Since I am using Janus all I had to do was make a syntax folder in my vim-chino folder and name is javascript.vim and just have the: syn match chinoKeywords "ChinoView" hi def link chinoKeywords Function in there. Thanks for the help!
I'm glad you've found a solution! Many people dislike distributions like Janus because of its added complexities.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.