0

If I indent the following script with gg=G:

#!/usr/bin/env bash

while true; do
    case "${1}" in
        -h) usage; exit 0;;
        -b) branch="${2}"; shift 2;;
        -t) build="${2}"; shift 2;;
        -w) write=true; shift 1;;
        --) shift; break;;
    esac
done

it gets differently indented on two different machines. On machine 1, the indentation is as above, on machine 2, all the different cases (starting from -b) gets indented to the left. Both machines have exactly the same .vimrc, where I use aindent only. On machine 1, vim is version 8.0, on machine 2, it's 7.4. Surely the version should not have such an effect? What else could lead to a different indentation?

Here are a few settings that I use on machine 1:

filetype detection:ON plugin:ON indent:ON
  softtabstop=0                                                                               
  tabstop=4                                                                                   
        Last set from ~/.vimrc                                                                
  shiftwidth=4                                                                                
        Last set from ~/.vimrc                                                                
nocindent                                                                                     
  indentexpr=                                                                                 
  autoindent                                                                                  
        Last set from ~/.vimrc                                                                
nosmartindent                  

And indeed there is one difference on machine 2:

  indentexpr=GetShIndent()
    Last set from /usr/share/vim/vim74/indent/sh.vim

Removing it does not improve the situation, though. So after all, it might be due to a difference in the version of vim. Is there a good setting of indenting that works for both versions?

  • Check the output of :filetype. Also, Vim 8 comes with better indent script for shell scripts. Also interesting to know: :verbose set sts? ts? sw? cindent? indentexpr? autoindent? smartindent? – Christian Brabandt Aug 23 '17 at 17:17
  • @ChristianBrabandt Edited my question. Thanks for the help! – pfnuesel Aug 23 '17 at 17:27
  • You can probably use the indent script from machine 2 for machine 1 as well. Is the indent script not working correctly? – Christian Brabandt Aug 24 '17 at 5:00
  • @ChristianBrabandt But the problem is on machine 2, so changing the settings on machine 1 does not seem to be the way to go. – pfnuesel Aug 24 '17 at 8:17
  • well, then do not set indentexpr on machine2. Also you did not show the output of :filetype for both systems. I suppose, that one includes indent: ON while the other does not. So that :filetype correctly should fix it for you. BTW, if the indent script does not work correctly for the case statement above, you might want to create a new issue on github.com/chrisbra/vim-sh-indent – Christian Brabandt Aug 24 '17 at 8:20

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.