3

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
2
  • 1
    Short answer: vim’s indentation is not perfect, and some situations are harder than others – D. Ben Knoble Dec 13 '20 at 14:07
  • Yeah, but sometimes the hard stuff is worth doing, or at least asking about. – 4dummies Jan 8 at 22:34

Your Answer

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

Browse other questions tagged or ask your own question.