Consistent indentation

1 Point

Florian Beer Florian Beer

10 years ago

Prevent mixed tabs and spaces in files you are editing. Expands tab presses to 2 spaces and converts all remaining tabs to spaces on save.

set tabstop=2
set softtabstop=2
set shiftwidth=2
set smarttab
set expandtab
if has("autocmd")
  au BufReadPost * if &modifiable | retab | endif
endif

Chris Penner

Chris Penner 10 years ago

This is handy, but I'd sooner make a function for the retabbing instead of an autocmd and then map it. Some specific files depend on actual tabs (some makefiles) so it's not always ideal to automatically retab everything.

Florian Beer

Florian Beer 10 years ago

Thanks, good point. I shall iterate and improve!

yang-ling

yang-ling 10 years ago

Maybe you can check filetype in au BufReadPost * if &modifiable | retab | endif