I have bash script which Vim detects as a sh according to :set filetype?. In addition, Vim-script for auto-indention support for shell-scripts(/usr/share/vim/vim74/indent/sh.vim) is also present. However, for example following while loop:

while read -ra line"$line_id"_fields; do
done < "$1"

..is auto intended(gg=G) to this:

  while read -ra line"$line_id"_fields; do
  done < "$1"

What might cause this?

  • Works for me on Vim 7.4.2143; which version are you using? Sep 6, 2016 at 21:14
  • 3
    Make sure, you have :filetype plugin indent on in your .vimrc. Then in your shell script check that :verbose set indentexpr? returns something like this: indentexpr=GetShIndent() Zuletzt gesetzt von /usr/share/vim/vim74/indent/sh.vim Sep 6, 2016 at 21:47
  • @Carpetsmoker I'm using Vim version 7.4.576. @Christian Brabandt Thanks! filetype indent on was missing. Once I added this to my .vimrc file, auto-indention feature works fine. I actually tried that before, but for some reason filetype indent on works only if I set this in my .vimrc file. If I have the bash script open and type filetype indent on(and I can confirm that it is on with filetype command), then auto-indent does not work.
    – Martin
    Sep 12, 2016 at 6:46

1 Answer 1


As @Christian Brabandt mentioned in his comment, filetype indent on was missing from my .vimrc file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.