pythontabsneovim

Auto detect tabs or spaces for Python projects


I'm aware of the setting set expandtab and set noexpandtab which can trigger to use spaces or tabs accordingly.

The problem I'm facing is that I'm working on different Python projects that are sometimes using spaces and sometimes tabs. I don't want to reformat all the code when I start working on a project so I'd like to auto-detect what type of indentation the project is using and apply either spaces or tabs automatically when pressing the tab key.

Is there a way to configure it wither with .vimrc or with a neovim plugin potentially?


Solution

  • With Neovim, you can use GuessIndent plugin (https://github.com/NMAC427/guess-indent.nvim) to detect automatically the indentation style (spaces or Tabs) used by your code.

    I am using it with issues with C/C++, Python, Go and Rust projects.