How to change the indentation width in emacs javascript mode

mksuth picture mksuth · Nov 14, 2010 · Viewed 43.2k times · Source

I'd like to use 2 spaces for my indents instead of 4. I can change the default behavior of C mode using:

(setq c-basic-offset 2)

How do I change this in javascript mode?

Answer

Willi Ballenthin picture Willi Ballenthin · Nov 14, 2010

js-indent-level can be used in the default javascript-mode, which is included by default starting in emacs 23.2.

(setq js-indent-level 2)

should do what you're looking for. If you're using an older version of emacs, you may be in java-mode. I think this mode responds to c-basic-offset, however I may be wrong.