I just started at a new company where apparently there is no standardization on tab/space setting at all. Everything goes.

That culture is not going to change. What I want to do is make Vim matches the spacing used in the file open, so that at least we have consistency.

Ex: open a file, looks like all lines use softtab with shiftwidth=2, so automatically set tab to 2 spaces.

What option could achieve this?

If I set autoindent, enter key works for new line. But tab key would still use the global Vim setting.

  • If it's "everything goes" just use what works best for you and reformat any file you touch. Any serious VCS or diff tool can ignore whitespace changes. And they probably won't even notice :)
    – Friedrich
    Commented Apr 2, 2023 at 18:27
  • Do you still have something open in your question or does the answer address the question? Is so maybe could you accept the answer using the v button next to the arrow voting buttons. It allow the question to rest :-) Commented Apr 8, 2023 at 7:20

1 Answer 1


My suggestion would be to install vim-sleuth that guess the indentation settings of the file and adapt the Vim configuration accordingly.

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.