Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Emacs tabs to spaces in every new file?

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.

like image 622
Peter Avatar asked Jun 18 '09 14:06

Peter


People also ask

How do I convert tabs to spaces in Emacs?

Thankfully, Emacs has facilities in place that make it possible to easily convert between tabs and spaces. The commands tabify and untabify do just that; they convert the region to tabs or whitespaces.

How many spaces is a tab in Emacs?

This is because standard tabs are set to eight spaces. Tabs are special characters.

How do you add tabs in Emacs?

To manually insert a tab in Emacs, use ctrl-Q TAB. control-Q causes the next key to be inserted rather than interpreted as a possible command.


2 Answers

add this in your .emacs:

(setq-default indent-tabs-mode nil) 

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

like image 168
dfa Avatar answered Sep 21 '22 19:09

dfa


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 
like image 25
Trey Jackson Avatar answered Sep 23 '22 19:09

Trey Jackson