sponsor Vim development Vim logo Vim Book Ad

intermediate Tip #206: Highlight doubled word errors in text

 tip karma   Rating 10/10, Viewed by 1088 

created:   January 31, 2002 4:32      complexity:   intermediate
author:   Ajit Thakkar      as of Vim:   6.0

An error I sometimes make while working on a LaTeX file is the repetition of a
word as in "the the". Most often, such doubled words come about through a
careless edit. Doubled words are hard to spot when the first word of the
doubled pair is the last word on one line, and the second word of the pair is the
the first word on the next line. There is an example of such an error in the last
sentence. Vim's syntax mechanism can be used to highlight doubled words as an error.

To obtain this highlighting for TeX and LaTeX files, place the following two lines:

       syn match texDoubleWord "\c\<\(\a\+\)\_s\+\1\>"
       hi def link texDoubleWord Error

in a file called tex.vim in the directory that shows up last in your
runtimepath (:set runtimepath? to check). This will often be
either ~/.vim/after/syntax/tex.vim or $VIM/vimfiles/after/syntax/tex.vim

The same effect can be obtained for files of a different filetype, say html,
by putting the same lines in a file called html.vim in the same location.

For more on the runtimepath, :he runtimepath.
For more on syntax highlighting, :he syntax

 rate this tip  Life Changing Helpful Unfulfilling 

<<Computing a sum of numbers in vim | editing databases with Vim/Perl/DBI >>

Additional Notes

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge Logo