I have several file paths saved in a register. I would like to open them all into the same new buffer. (as if I ran cat * files | vim - from command line.

As this is part of a plugin, I would like to do this all with vim script.

1 Answer 1


The :read command reads a file into the current buffer; although it only works for one file. You'll need to add a new command which calls :read in a loop:

command! -nargs=+ -complete=file Read
        \  for f in [<f-args>]
        \|    exe ':$read ' f 
        \| endfor

You need the $ range in read to tell it to append the file to the end of the buffer; by default the cursor stays in place, so the files will get intermixed.

You can also call glob() if you want to accept things such as *.vim; I added support for this in my little globedit.vim plugin.


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.