Bash – Open multiple files in Vim with a filelist

bashvim

I have a file 'filelist' that contains the following lines:

text1.txt
text2.txt
text3.txt 

I am looking for a command line invocation that opens the 3 files in vim. I tried the following:

$ cat filelist | vim - 

and

$ vim < cat filelist

but those do not yield the desired result.

Best Answer

If the file names don't contain spaces or other problematic characters, you can use

vim $(cat filelist)

For file names with spaces, using xargs is more robust (here using GNU xargs specific options):

xargs --delimiter '\n' --arg-file=filelist vim --
Related Question