I added lines from this website
https://www.emacswiki.org/emacs/IndentationBasics
to my ~/.emacs
file:
(setq-default indent-tabs-mode nil)
(setq tab-width 4)
(defvaralias 'c-basic-offset 'tab-width)
And it made my tabs in .h
files and .cpp
files 8 spaces long (before they were 2 spaces long).
How to make them 4 spaces long?
Both tab-width
and c-basic-offset
variables are buffer-local, which means it is effective only in the buffer you set it. Emacs only evaluates ~/.emacs
at start up, and it is only effective in that file.
To set a default value for all buffers, you need
(setq-default tab-width 4)