Auto-indenting in vim may or may not be helpful depending on the file your editing and the conventions you like or have to follow. This will breifly show a few methods of turning this feature on/off and changing the way vim implements it.
:verbose set ai? cin? cink? cino? si? inde? indk?
If you are editing a particular file and you want to prevent auto indenting within that file, enter:
:setlocal noautoindent
:setlocal nocindent
:setlocal nosmartindent
:setlocal indentexpr=
The following is equivalent (it uses the abbreviated names in a single command):
:setl noai nocin nosi inde=
Here is a mapping so you can press F8 to disable auto indenting:
:nnoremap <F8> :setl noai nocin nosi inde=<CR>
This example toggles auto indenting on or off and displays the current status:
:setl ai! ai?
filetype indent plugin on
filetype indent on
set ai
set si
:%s/\t/ /g OR :set expandtab tabstop=2 shiftwidth=2 softtabstop=2
:retab!
Where
| :set expandatab | Enables using space characters instead of tab characters when the tab key is pressed. Note: with this option set you will have to press Ctrl-V<Tab> to enter a tab character |
| :set tabstop=N | Sets number of space characters (N) that will be inserted when the tab key is pressed |
| :set shiftwidth=N | Sets number of space characters (N) that will be used for identation |
| :retab | Replaces tab characters in file with new definition |