If the highlighting is for certain filetypes (e.g. Java) only, and you want it all the time, I'd extend the original syntax with :syn match ...
definitions placed in ~/.vim/after/syntax/java.vim
.
For spontaneous highlighting, use :match
(or :2match
), as dwalter has shown.
If you're gonna write a more elaborate mapping, maybe with toggling on/off logic, use matchadd()
/ matchdelete()
.
Finally, if you need highlighting for arbitrary words / strings, like marking up a document with a text marker, I'd suggest the comfort of a plugin like Mark (which I have taken over maintaining).