Reputation: 8418
I am using molokai in vim to code in python/html/css/javascript. When I edit python files (or javascript) parenthesis are not colored. This is not true for simple scripts (like molokai.vim itself) where parenthesis are colored gray.
I edited molokai.vim
and added
hi parens guifg=#999999
and then I edited .vimrc
and added:
syn match parens /[(){}]/
but parenthesis and brackets remain white.
What am I doing wrong?
Upvotes: 2
Views: 1362
Reputation: 53604
:syn
to highlight all filetypes, there is matchadd()
for this. Using :syn
can easily break highlighting, matchadd()
is an overlay.Syntax highlighting is being overridden when Syntax
event fires. More, it has effect only on the current buffer. So just syn
in vimrc will never work, you have to use autocommands
autocmd! Syntax python :syntax match Parens /[(){}]/
(for python it is safe as parenthesis and figure brackets are not matched by any other syntax element).
In javascript parenthesis (()
) are already matched by javaScriptParens
highlighting group. Thus you have to use
hi def link javaScriptParens Parens
(in colorscheme). Braces are matched by javaScriptBraces
and require similar command.
To determine what highlighting is used for specific symbol I place cursor on this symbol and launch
echo 'Normal '.join(map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")'))
, the last displayed word is normally what you need. If only Normal
is displayed then symbol is not highlighted and you have to go 2., otherwise you have to go 3.
For universal solution disregarding currently used highlighting you may use matchadd()
as I already said. But it is local to window so if you are working with multiple windows/tabs you can’t go without autocmd:
autocmd! WinEnter * :if !exists('w:parens_match_id') | let w:parens_match_id=matchadd('Parens', '[(){}]') | endif
All autocommands are to be surrounded with
augroup HighlightParens
autocmd! …
augroup END
Upvotes: 3