First, you are running Vim, not Vi, because the latter does not offer the retab
command.
Assuming the file should be modified (that is what x
does below), you can pipe the commands to Ex improved mode this way:
printf '%s\n' 'retab' '%s/ /, /' 'x' | vim -E file1.txt
Now, bear in mind that Ex will skip your .vimrc
, so retab
will not take
tabstop
and expandtab
values from that file. Of course, you can just manually supply them, for example,
printf '%s\n' 'set expandtab' 'retab' '%s/ /, /' 'x' | vim -E file1.txt
To operate on various files (matching file[digit].txt
), just wrap it in a shell loop,
for file in file[0-9].txt; do
printf '%s\n' 'set expandtab' 'retab' '%s/ /, /' 'x' | vim -E "$file"
done