Loren
Loren

Reputation: 14836

How do I set indent to 2 spaces in js2-mode?

I have this at the end of my .emacs:

(setq-default indent-tabs-mode nil)

(setq tab-stop-list (number-sequence 2 120 2))

It works fine in other modes – whenever I tab, it adds two spaces. But in js2-mode, it adds 4.

Upvotes: 34

Views: 12042

Answers (3)

Thomas Fankhauser
Thomas Fankhauser

Reputation: 5059

For me js2-basic-offset is an alias to js-indent-level, so I had to change the latter to make it work.

Upvotes: 13

ntalbs
ntalbs

Reputation: 29438

You can set js2-basic-offset to 2.

  1. M-x customize-variable
  2. Enter js2-basic-offset
  3. Set the value to 2

Then Apply and Save button in the customize option buffer. This will add an item to set the variable into .emacs or init.el file.

Upvotes: 44

Rigotti
Rigotti

Reputation: 2862

Little late here, but if you're like me and keep configurations for major modes in separate files, you can add the following line and it works as well.

(add-hook 'js2-mode-hook (lambda () (setq js2-basic-offset 2)))

Upvotes: 15

Related Questions