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


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

$ cat filelist | vim - 


$ vim < cat filelist

but those do not yield the desired result.

  • Try vim $(cat filelist). – vonbrand Apr 12 '13 at 14:01

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 --
  • What a quick answer! Great :) I found another solution on this site using backticks (on the same key as the ~ sign). Here it is: unix.stackexchange.com/a/5882/37057 – user37057 Apr 12 '13 at 13:52
  • 1
    $(…) is the same as backticks, but a little more robust, since they can't be confused with single quotes or other similar looking characters and they can be nested. – Marco Apr 12 '13 at 13:54
  • The xargs one affects the stdin of vim. – Stéphane Chazelas Apr 12 '13 at 15:03

With zsh:

vim -- "${(f)$(<filelist)}"

With any Bourne-like shell (including zsh):

'; set -f; exec vim -- `cat filelist`)

With GNU xargs:

xargs -d '\n' --arg-file=filelist vim --
  • Why not just ➜ vim $(<filelist) in the first example? Is it wrapped into parameter expansion just because (f) will handle properly filenames with spaces? – branquito Jun 30 '18 at 23:45
  • 1
    @branquito, yes (f) splits on line feeds, $(<filelist) would split on any character of $IFS (by default SPC, TAB, LF and NUL) and in ksh (where that $(< operator comes from) and bash (but not zsh unless in sh/ksh/bash emulation), would also do globbing so characters like ?, *, [ would also be a problem. – Stéphane Chazelas Jul 1 '18 at 5:02

To open all index.php in the current working path

vim -p `find . -name index.php`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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