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.
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityThe :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.