38

I would like to have an .emacs setting so that tabs are always formed by consecutive spaces. Preferably in each possible mode. In other editors it never seemed a problem, but in .emacs I'm a bit stuck with the tabs I'm afraid.

Damian Yerrick
  • 4,602
  • 2
  • 26
  • 64
Peter
  • 47,963
  • 46
  • 132
  • 181

2 Answers2

57

add this in your .emacs:

(setq-default indent-tabs-mode nil)

or you can define a before-save-hook that eliminate hard tabs

dfa
  • 114,442
  • 31
  • 189
  • 228
  • I don't know who voted you down, it works fine for me, at least in textmode, other modes I haven't tried. Tx. – Peter Jun 18 '09 at 14:21
  • It would be great to have the exact syntax for the `before-save-hook`, please & thanks – Reb.Cabin Feb 14 '18 at 17:59
39

Also of use, M-x untabify, which will convert all the tabs into spaces in the current region. You can use this to get rid of the existing tabs in files you've edited before you had the indent-tabs-mode set properly.

C-x h                   (M-x mark-whole-buffer)
M-x untabify
Trey Jackson
  • 73,529
  • 11
  • 197
  • 229