I would like to create a document template in Vim.
Upon creating files of extension .bananão the template should activate itself and become the current buffer.
The template will contain something like this:
Names of attorneys:
- DEFATTORNEY
- BANANATTORNEY
Plaintiff:
- BANANAPLAINTIFF
Defendant:
- BANANADEFENDANT
...
.. moves the court for the entry of an Order directing BANANAPLAINTIFF
to produce to BANANADEFENDANT ...
... etc.
I would like for vim to watch for changes as they are made to this document template and trigger an action when a particular event is detected.
The changes I would like to monitor are:
- Edits of any keyword belonging to the set COCONUTSET: { DEFATTORNEY, BANANATTORNEY, BANANAPLAINTIFF, BANANADEFENDANT }
The triggered composite action I would like to configure is:
-
Upon completing the command that edited one of the words in COCONUTSET, say COCONUTWORD, read the first word that was put in place of the placehold word COCONUTWORD and replace all other occurrences of the placeholder word COCONUTWORD with this replacement word just substituted to it.
-
Remove COCONUTWORD from COCONUTSET.
-
If COCONUTSET is empty, stop monitoring changes.
Which functions/approach would you recommend for this?
With your silly example, it’s hard to judge how good it applies, but I have written a plugin for me that offers a
gccommand that works just like built-inc, and after leaving insert mode applies the local substitution to all other occurrences in the current line (in case of a small character change) or, when entire line(s) were changed, to the rest of the buffer. I plan to publish this soon, but essentially you just need to hook into theInsertLeaveevent, see what has been edited (register".), and then perform a substitution.