I need to process text line by line in one buffer and append the processed text to another buffer in Vimscript.

I can do this by using buffer switching ex commands, but I suspect it will cause epilepsy-inducing screen flashing when the script runs and it is probably really inefficient to be rendering and re-rendering the buffer on the screen thousands and thousands of times.

Is there a way to append text to another buffer (other than the active buffer) without actually making the destination buffer active?

1 Answer 1


You can use appendbufline() like:

call appendbufline("other.txt", "$", "Appended Line")

or if you want to work with buffer numbers:

call appendbufline(3, "$", "Appended Line")

See :help appendbufline() for details.

  • 4
    Ralf.. pro tip: if don't like your efforts to be ignored don't answer questions from the OP. They've stated that they will not accept an answer unless the person who answered upvotes the question. (!!) Their last 18 asked & answered questions => 0 accepts.
    – B Layer
    Commented Mar 8, 2019 at 2:59
  • there is also setbufline() (available since 8.0.1039, while appendbufline() is available since 8.1.37). So it needs a relative recent Vim. Commented Mar 8, 2019 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.