I'm working on a large codebase, where each file has different indentation conventions: tabs, 4 spaces, 3 spaces, etc.
I currently default on tabs and do set shiftwidth=N expandtab smarttab
when I come across a spaces-indented file, but that's annoying.
Is there any functionality in Vim, or a plugin, which can recognize that, for instance, the current buffer uses an indentation with three spaces per shift?
Use spaces for indenting vimrc' file. The first line enables expandtab option in Vim. This option makes sure that spaces are used for indenting lines, even when you press the 'Tab' key. The second option tabstop takes a numerical value.
Four spaces should be used as the unit of indentation. The exact construction of the indentation (spaces vs. tabs) is unspecified. Tabs must be set exactly every 8 spaces (not 4).
In normal mode, press Tab or Shift-Tab to adjust the indent on the current line and position the cursor on the first nonblank character; in insert mode, press Shift-Tab to unindent; in visual mode, press Tab or Shift-Tab to adjust the indent on selected lines.
Various plugins exist that attempt to handle that situation. Here are a few I found by search for detect indent
at vim.org
Good question,I'm facing the same problem too, and recently I wrote such a vim plugin for myself:https://github.com/luochen1990/indent-detector.vim
it has the following features:
- detect mixed indent and echo warnning on bufEnter and bufWrite automatically.
- switch setting about indenting to fit the current indenting style automatically.
- detecting time is limited, so you don't need to worry about opening huge files.
I think it is well designed, and need to be known, post an issue on github if you have any suggestion :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With