Usually, one uses gg=G
in vim to automatically tab C/C++/Java code or in fact any sort of code.
However, I changed my tabstop
variable to be tabstop=2
in my default settings for vim, so that whenever I tab I get the equivalent of 2 spaces instead of the default 8.
Now whenever I use gg=G
, I get 4 tabs instead of 1 for indentation so that the spacing looks equivalent to before when I had tabstop=8. I just want 1 tab though. Is there a way to do this?
(I am using hard tabs only for indentation, no spaces).
What you are looking is shiftwidth
. set sw=2
for proper indentation for your case. :help sw
At the same time, instead of changing tabstop=2
, it is better to set softtabstop=2
. Details at :help ts
.
and for source code, usually it is good to expand tab
as it is not preferred for source code.
You can set following settings in your vimrc
set softtabstop=2
set shiftwidth=2
set expandtab
I personally prefer indentation of 4
. With 2
, it will be hard to notice the indent sometimes :)
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