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
<<Computing a sum of numbers in vim |
editing databases with Vim/Perl/DBI >>
Additional Notes
|