whizbanginfosec
whizbanginfosec

Reputation: 23

Vim autoindents 8 spaces for/if/case blocks when writing bash code

Whenever I input a statement such as:

if [[ x -eq $something ]]

Or any "if", "for", or whatever statement, bash indents 8 spaces instead of 4 after I press enter.
So where I want my code to look like this:

for $i in {1..5}
    *do stuff*
    *do more stuff*
end

Vim autoindents it like this

for $i in {1..5}
        *do stuff*
        *more stuff*
end

How can I change vim's behavior? It seems like bash scripts are the only thing that indent like this.

Upvotes: 0

Views: 274

Answers (1)

Hi computer
Hi computer

Reputation: 1123

I have these indent-related configurations in my .vimrc, can you test each one separately?

I'm very sure the last command with autocmd will assist you with various indents for various languages.

filetype plugin indent on
filetype indent on

syntax enable
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
autocmd FileType javascript set tabstop=2|set shiftwidth=2|set expandtab
autocmd FileType sh set tabstop=4|set shiftwidth=4|set expandtab

Upvotes: 1

Related Questions