Reputation: 305
I have tried highlighting specific words by adding them in .vimrc, colorscheme file and also in syntax.vim(I changed one at a time, not altogether).
syn match mygroupwords '\c\<\(-word1\|-word2\)'
hi def link mygroupwords colo_words12
hi colo_words12 guifg=red1 gui=bold guibg=white
But somehow it seems to be getting overwritten by default syntax highlighting
i need to highlight keywords irrespective of color-scheme or file-type which have following words- Ex; -word1 , -word2
Any suggestions?
Upvotes: 3
Views: 704
Reputation: 172510
A colorscheme just provides color definitions for predefined highlight groups; that's the wrong place for actual syntax matches! ~/.vimrc
is the first configuration that is read; if a filetype is detected and a corresponding syntax script is loaded, that will override your syntax definition.
If your desired highlightings are extensions to an existing syntax, you can place :syntax match
commands in a syntax script in the after directory. For example, to extend Python syntax, put it in ~/.vim/after/syntax/python.vim
. That may still fail if the original syntax obscures the match; sometimes, this can be solved via containedin=...
If your highlightings are independent of syntax and filetype, there's a different built-in mechanism: :match
(and :2match
, and additional variants via :call matchadd(...)
):
:match mygroupwords /\c\<\(-word1\|-word2\)/
This goes on top of (and is independent of) syntax highlighting. However, it is local to the current window. So, if you put this into your .vimrc
, it will only affect the first window (but any files viewed in there). To apply this globally to window splits and tab pages, you have to use :autocmds
. It's not trivial to get this totally right. If you need such a full solution, have a look at my Mark plugin; this supports multiple colors, allows presetting with :[N]Mark /{pattern}/
(similar to :match
), and highlights in all windows.
Upvotes: 3