1

I would like an object method call to be syntax highlighted in Vim. For instance, in an expression that contains person.getName(), I would like to match getName and give it some syntax highlighting.

I have tried quite a number of patterns and at the moment, this is what I have in my experimental syntax file;

" :set iskeyword+=.
syntax match myMatch "\v\.\zs\w+\ze\(" 
highlight link myMatch Function

It is not highlighting unless I comment in the first line above or issue :set iskeyword+=. manually and then try editing the file.

How can I make the highlighting successful without having to set . as part of iskeyword??

UPDATE: I have Pathogen and I have the file with the contents above in ~/.vim/bundle/vim-javascript-syn/syntax/javascript.vim

  • Please extend you question and name the language/filetype you work with. – Ralf Mar 17 at 12:23
  • @Ralf, please check some updated details in the question. – John Mutuma Mar 17 at 12:29
  • 1) The file is javascript.vim, not javascript.js, or? 2) put the two lines in the file ~/.vim/after/syntax/javascript.vim and test again. (see :help after-directory) – Ralf Mar 17 at 12:47
  • It's actually .vim. My mistake. It's not .js. Updated question. @Ralf – John Mutuma Mar 17 at 15:20
1

Have you tried to do it on an empty noname buffer with vim -u NONE

I have copied (only changed function to title hl group) your lines and executed them, as you can see on a screenshot, it works without . in iskeyword:

enter image description here

PS:

To execute those commands type/copy them to :.

I use my own plugin to eval vimscript :)

1

I can't reproduce your problem. But here is what I would do:

Create the file ~/.vim/after/syntax/javascript.vim and add you configuration to it:

syntax match myMatch "\v\.\zs\w+\ze\("
highlight link myMatch Function

This syntax file it then an extension to the default javascript syntax file of Vim.

Vim first loads the default syntax file syntax/javascript.vim from the runtimepath. After that it looks for after/syntax/javascript.vim (also via runtimepath). If found, this is loaded also.

See :help mysyntaxfile-add, :help after-directory and :help runtimepath.

To display you current runtimepath execute:

set runtimepath?

PS: If you really want to do that via Pathogen, you also could create the file as ~/.vim/bundle/vim-javascript-syn/after/syntax/javascript.vim.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.