Macos – How to use a pipe to edit a file with vi

command linemacosshellvivim

Lets say I have a file called file.txt. In it is a name of a file that I want to edit with vi. I want to do something like this so that I can edit the file:

cat file.txt | vi

However, that doesn't work. How can it be done?

To clarify things:

Here are the contents of file.txt:

textfile

So I want to somehow send the contents of file.txt to vi so that the same thing will happen as when typing vi textfile.

The contents of file.txt can change. I want vi to edit whatever file is listed in file.txt.

Best Answer

you might try this:

% vi `cat file.txt`

or, to avoid the useles use of cat:

% vi `< file.txt`

you are telling vi(m) just a bunch of arbitrary things. if you want vi(m) to do something like 'hey, open that file' you have to feed it the same commands you would use in vi(m), eg. something like :e foo.txt. but thats just more complicated than doing what i proposed.

Related Question