2

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?

UPDATE

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.

Maxim Kim
  • 13,376
  • 2
  • 18
  • 46
Salahuddin Ahmed
  • 441
  • 3
  • 14

2 Answers2

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

Maxim Kim
  • 13,376
  • 2
  • 18
  • 46
0

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).
Ingo Karkat
  • 17,819
  • 1
  • 45
  • 61