It appears from the :help while
documentation that :
NOTE: The ":append" and ":insert" commands don't work
properly inside a ":while" and ":for" loop.
And I can confirm they don't. But what should I use then to insert text from inside a loop?
The :insert
and :append
commands are mostly meant for interactive use. In a Vimscript, you can instead use the lower-level setline()
and append()
functions, which do work well in a loop. (They are also easier to use, because you can directly pass a List of lines to them.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With