Reputation: 8109
I often make type errors and do a spell check to correct them.
I noted that often the first suggestion in the spell dictionary is the correct one so I created a map to insert the first spell check suggestion:
map <leader>q 1z=
This works fine. But I have to do this many many times in a buffer (for every spell check error once).
I would like to create a script what afterwards searches every type error; insert the first spell check suggestion with the above map, highlight them afterwards, in order to see what has been inserted by the script.
Creating a script and moving from one spell check error to the next one is not so difficult, using the ]s
command, but how do I highlight all changed typos?
Upvotes: 2
Views: 426
Reputation: 172540
When accepting a spell suggestion, you would need to record the (line, column) location, and from those build a regular expression (using /\%l
and /\%c
special atoms), either for use in a search (@/
), or custom highlighting via :match
.
But I would rather ask you to consider changing your requirements, as this highlighting of changes (though it is often used in IDEs), is foreign to Vim (and therefore quite cumbersome to implement!) A closer match would be the quickfix list, which is mainly used for compiler errors.
Incidentally, I have written a plugin, SpellCheck, that allows you to populate the quickfix list with all spelling errors found in a buffer to give you a nice overview of spelling errors. After creating that overview via :SpellCheck
, you could then accept the spell suggestions via your mapping, or even in bulk, and finally use :cnext
(or a quicker mapping) to visit all replacements.
Upvotes: 2