Automatically applying change commands in multiple windows in Vim

Viewed 150

Can Vim automatically apply change/insert commands such as dd, O, and u to all open windows? I am composing a LaTeX document in one window and would like to use a second window for my margin notes, TODOs, etc. (similar to Cornell notes). My Vim tab looks like

|1 \documentclass{article}       |1 
|2 \begin{document}              |2 
|3 Lorem ipsum dolor sit amet,   |3 TODO: reword this.
|  …consectetur adipisicing elit.|  
|4 Ut enim ad minim veniam, quis |4 Could use some more examples.
|  …nostrud exercitation ullamco.|  
|5                               |5 Put bibliography here.
|6 \end{document}                |6 

I need to keep wrap (and preferably showbreak) toggled as my sentences are often fairly long.

So far I am successfully using scrollbind and cursorbind to navigate the two files in parallel. When I insert or delete lines in one file, though, the alignment breaks. For example, I might insert a line (using o) in the lefthand window to load a package, producing

|1 \documentclass{article}       |1 
|2 \usepackage{hyperref}         |2 
|3 \begin{document}              |3 TODO: reword this. 
|4 Lorem ipsum dolor sit amet,   |4 Could use some more examples.
|  …consectetur adipisicing elit.|  
|5 Ut enim ad minim veniam, quis |5 Put bibliography here.
|  …nostrud exercitation ullamco.|  
|6                               |6
|7 \end{document}                |~ 

Now all the comments in the righthand window are on the wrong lines. If my edit in the lefthand window also inserted a new line after line 1 in the righthand window, the alignment would be preserved. I have had some success using the windo command (e.g. windo normal dd to delete a line in both files); should I map dd to window normal dd and similarly for every command I might use? How would this work for commands like o that leave you in insert mode?

To complicate the problem, I would ideally like any action that created or deleted a newline character to be replicated in both files. For example, carriage returns in insert mode should be caught and repeated in the other window.

Is there some better way of doing this (I will stick to Vim but would be interested in hearing about other editors that have this functionality), or should I just keep my comments inside the document file?

2 Answers
Related