问题
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?
回答1:
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.)
来源:https://stackoverflow.com/questions/28511027/how-to-insert-text-from-inside-a-vimscript-loop