1

Result of auto-indent in vim (filetype indent on)

main() {
    case $1 in  
        --ssh)
        echo "sshing into ${aws_ips[$1]}"
        ssh -i VPN_NODE_1.pem ${aws_ips[$1]}
    ;;  
    --scp)
        echo "scping $2 from ${aws_ips[$1]} to $3"
        scp -r -i VPN_NODE_1.pem ${aws_ips[$1]}:$2 $3  
        ;;  
    esac 

}

Expected:

main()
{
    case $1 in  
        --ssh)
            echo "sshing into ${aws_ips[$1]}"
            ssh -i VPN_NODE_1.pem ${aws_ips[$1]}
            ;;
        --scp)
            echo "scping $2 from ${aws_ips[$1]} to $3"
            scp -r -i VPN_NODE_1.pem ${aws_ips[$1]}:$2 $3
            ;;
    esac
} 

EDIT: My original post was incorrect. I was not using filetype indent on in my .vimrc, I was using it in the vim command prompt

3
  • 1
    Welcome on the Vim SE! I think your question is enough comprehensible now to remain open, typically questions with so few sentences are not. I suggest to later use more round sentences in your questions. Good luck on the site!
    – peterh
    Commented Oct 18, 2018 at 22:33
  • What does :set ft? autoindent? cindent? indentexpr? show?
    – B Layer
    Commented Oct 20, 2018 at 12:12
  • @BLayer filetype=sh autoindent nocindent indentexpr=
    – Code Wiget
    Commented Oct 23, 2018 at 16:09

1 Answer 1

1

I asked in comments for some of your settings and you replied with filetype=sh autoindent nocindent indentexpr=

If for indentexpr you instead had value GetShIndent() you'd have the indent scheme you want. You can manually set it up with :source $VIMRUNTIME/indent/sh.vim. But that's not what we want. With the proper configuration this should be picked up automatically when you open a shell file.

What's missing in your configuration? My best guess is that you need to add this to your vimrc:

filetype indent on

Check the current "indent" value (as well as a couple others, "plugin" and "detection" ) with plain :filetype. If you see indent:OFF then I'm on the right track and you should update your vimrc as suggested.

2
  • In the original post, I had been setting "filetype indent on" through the command prompt in vim... which wasnt working. When I put it in my .vimrc, it worked! Thanks!
    – Code Wiget
    Commented Oct 24, 2018 at 14:00
  • No problem. Note that it definitely wouldn't work with the command line if you didn't first reload the shell file you're editing (which will re-execute the file type detection logic). But after that it should be good.
    – B Layer
    Commented Oct 25, 2018 at 0:51

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.