Setting tab size in Emacs
Asked Answered
I

2

6

I'm using Emacs as an editor. I want to set the tab size to four spaces. In my .emacs file I have the following:

(setq default-tab-width 4)

I've also tried:

(set-default tab-width 4)

Either way, when I open emacs and try to tab, it inserts two spaces. Am I doing something wrong? It almost seems like its not seeing my .emacs file.

Any suggestions would be great! Thanks!

Isabel answered 25/3, 2010 at 16:9 Comment(0)
F
14

The tab-width variable doesn't determine the amount of indenting per level, and the TAB key doesn't insert a tab: it indents the current line to the correct indentation level in most language modes.

If you're programming in C, C++ or Java (and a few more, based on cc-mode), try setting c-basic-offset to 4. Or hit C-c . and select another indentation style; there might be one that matches your taste.

Fertilize answered 25/3, 2010 at 16:12 Comment(0)
L
2

The tab-width variable controls the tab stops, not the indentation offset which is padded with spaces as needed if the tab stop does not match (assuming you have emacs set to insert physical tabs).

  • In bash mode, the variable is sh-basic-offset.
  • In python mode, the variable is python-indent-offset.
  • In c mode, the variable is c-basic-offset.

If you know of any more, please comment or edit this post.

Lalo answered 31/5, 2022 at 17:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.