I'm working on a plain text file. I'd like to highlight important words or lines so that they stand out. How can I change background color and/or text color for selected text or word under cursor?


By permanent I meant that the highlighting lasts and saved when closing the document. I'd like to highlight different words and lines one after another.


2 Answers 2


While it is possible to highlight arbitrary words temporary there is no builtin/easy way to make it permanent -- it is plain text. I mean, without injecting additional text/chars into your file.

If you are OK there might be some stuff inserted then try txtfmt plugin https://github.com/bpstahlman/txtfmt

  • And of course it would be marked as duplicate, right? :)
    – Maxim Kim
    Commented Nov 6, 2019 at 13:36

colorful, ephemeral or semi-permanent

Adding arbitrary highlights for text fragments can be done via :help :match (and :2match, :3match, generically with matchadd()). These built-in commands provide the basic functionality, but for a great user experience, more stuff is needed (like helpful mappings that mirror the build-in / and * commands, :autocmds that apply the highlightings not just in the current window, maybe persistence across settings. For that, a plugin is needed.

My Mark plugin is one of those. (The plugin page has links to alternative plugins.) The highlighting (patterns and colors) won't be part of the buffer; best you could do is storing these as annotations in a modeline-like comment.

really permanent

If you instead really want complete permanency:

  • For a few keywords, a syntax extension could work. Many syntaxes already have a common highlighting of TODO, FIXME, and similar keywords.
  • There are many "enriched text" formats; Markdown is very famous (and also used here on Stack Overflow); some languages already allow embedding inside comments or other blocks; for others this could be grafted on via my SyntaxRange plugin. You'd be limited to a few common formatting styles (like bold and italic), though, or have to insert big ugly markup (like <font> tags).

Your Answer

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

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