Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert text from inside a vimscript loop?

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?

like image 843
iago-lito Avatar asked Jan 09 '23 21:01

iago-lito


1 Answers

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.)

like image 81
Ingo Karkat Avatar answered Jan 14 '23 02:01

Ingo Karkat