When I pipe text to vim I discovered that by using:
cat somefile | vim -
it works properly, whereas:
cat somefile | vim
makes a mess of the code. For example, type:
cat test.pl | vim
where test.pl is:
#!/bin/bash
while true
do
# i like comments
say "This line, and the next one, should not be comments"
done
and you end up with:
le true
do
# i like comments
# say "This line, and the next one, should not be comments"
# done
#
It's as if without the hyphen the text appears as if it's being typed, switching modes and extending comments when you press enter etc, whereas with the hyphen it's treated as if a filename containing the piped text was passed to vim. I cannot locate the relevant help on this. I'm pretty sure it's not a shell feature (I'm using Bash on a Red Hat box).