In an account with just an emtpy .vimrc, under Xubuntu 20.04 and vim 8.1, I get strange indentaion after my here document if I reindent with gg=G
I've boiled down an example from some pretty tangled code; never mind what it does, this is about what it looks like. I added a modeline so you know the basics of how things are set up.
Original code indented as I think correct:
#!/usr/bin/env bash
# vim:et:ai:sr:nosi:ts=2:sts=2:sw=2:filetype=bash
if true ; then
#show 3 words
for word in one two three
do
if true ; then
cat <<EOF
$word
EOF
text="You should see 3 lines above"
echo $text
fi
done
fi
After doing gg=G
it looks like this. The two lines after the here document are shifted to the left margin; in the original this went on for many lines.
#!/usr/bin/env bash
# vim:et:ai:sr:nosi:ts=2:sts=2:sw=2:filetype=bash
if true ; then
#show 3 words
for word in one two three
do
if true ; then
cat <<EOF
$word
EOF
text="You should see 3 lines above"
echo $text
fi
done
fi