I'm working on several projects, each of which uses different indentation style (for various filetypes). For example 1 tab per indentation level, 2 or 4 spaces etc. How can I automate switching between these different styles? I normaly prefer indenting with tabs, but I'm tired of having to type :set expandtabs all the time when working with space-indented code. Possible solutions would include loading a piece of vim configuration based on file path or some configuration in the project root. Is there a plugin to solve this for me in an elegant way?
To indent the current line, or a visual block: ctrl-t, ctrl-d - indent current line forward, backwards (insert mode) visual > or < - indent block by sw (repeat with . ) then try hitting the F5 key while in insert mode (or just :set paste ).
Start in the top of a file (to get there, press gg anywhere in the file.). Then press =G , and Vim will fix the indentation in the whole file. If you don't start in the beginning of the file, it will fix indentation from current line to the bottom of file.
cinoptions
option and softtabstop
option (and expandtab
, but you know that).In your '~/.vimrc', define buffer entry auto-commands for each directory where you keep sources of some project like:
augroup ProjectSetup au BufRead,BufEnter /path/to/project1/* set et sts=2 cindent cinoptions=... au BufRead,BufEnter /path/to/project2/* set noet sts=4 cindent cinoptions=... augroup END
If the project has mixture of languages and needs different settings for then, you can also add extensions like:
au BufRead,BufEnter /path/to/project1/*.{c,h} set noet sts=0 cindent cinoptions=... au BufRead,BufEnter /path/to/project1/*.py set et sts=4
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