Highlight Bad Words In Vim

Written by | 3 minutes read | Tags padrino, vim | Comments

This article is part of an ongoing series about my exploration of the Padrino web framework. If you want to read more about it please check out padrinobook.com. You sniff around in the sources of the book under GitHub.

I’m currently writing, reviewing, and deleting a lot of words for my padrinobook. Words like easy, however, so, or just are growing in some parts of the book like a disease. The term for bad words is clutter, which I learned after reading On Writing Well by William Zinsser.

Clutter is not everywhere in the documents. It usually occurs when you are writing on a late evening or you are just thinking in technical terms.

After finishing a section it would be nice to browse through the text on the screen and scan for bad words. See them and get rid of them. It helps you to be more precise and you stay focus on what you want to write.

Clutter Highlighting Function in Vim

The idea is to have a list of bad words and then give them a red background. To highlight the words vims ctermbg and ctermfg can be used in combination with the highlight function. After that we can use the match function in combination of the predefined color highlighting.

highlight TechWordsToAvoid ctermbg=red ctermfg=white

function MatchTechWordsToAvoid()
  match TechWordsToAvoid /\c\<\(obviously\|basically\|simply\|of\scourse\|clearly\|just\|everyone\sknows\|however\|so\|easy\)\>/

Since I’m writing my book with the help of markdown I only want to highlight words the words if I’m on those files. Let’s use the autocmd with the FileType option for markdown:

autocmd FileType markdown call MatchTechWordsToAvoid()

Now a file with many bad words will look like the following:

Highlight Bad Words in Vim

Highlight Bad Words in Vim