I have a project I'm working on currently where the coding standard is to use 2 space indentation. On other projects, however, I use 4 space indentation.
Is there an easy way to tell vim that all files within a certain directory should have a tabstop of 2 spaces?
Push 'Edit' and select the tab 'Indention' in the appeared Profile window. Under the group 'Tab policy' select 'Spaces only' in the drop down menu. Set 'Indentation size' to 4. Set 'Tab size' to 4.
To convert tabs to spaces in the currently opened file in Vim, enter the Normal mode by pressing Esc key. Now use the retab command by pressing the ':' (colon) character and Vim will convert the existing tabs to spaces.
Use an autocmd
that matches the directory and sets whatever options you need:
au BufRead,BufNewFile,BufEnter /path/to/dir/* setlocal ts=2 sts=2 sw=2
This will apply to files in subdirectories as well.
As Ingo Karkat points out, such commands should use setlocal
instead of set
so as to be specific to buffers.
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