My plugin creates new buffer, sets buffer type to nofile and fills it with text via job_start with out_io=buffer. Simplified code:

setl bt=nofile
call job_start(cmd, {'out_io': 'buffer', 'out_buf': bufnr('%')})

Works fine, but when I switch to new buffer, and then return back, created buffer is empty. So, looks like vim doesn't keep contents of nofile buffers. Is there any way to keep nofile buffer contents for vim session?

1 Answer 1


You also need setl bufhidden=hide to prevent the buffer from getting unloaded when you switch to another buffer.

See also :help special-buffers, in particular the entry for "scratch" buffers.

  • 1
    Excellent! That's what I needed, thank you! Dec 11, 2020 at 16:06

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.