In Emacs, how can I change tab sizes?
To change the tab size in Emacs, add the following line
(setq default-tab-width #)
# with the number of spaces at
which you would like to set your tabs. This will only affect the way
your files look in Emacs; if you look at your files with another
command or program (like the
commands), the tabs will contain eight spaces. For instance, if you
have tabs set to four spaces in Emacs, and write a C program
using tabs, it would look like this in Emacs:
But if you use the
cat command or the
command to look at it, it would look like this:
This is because standard tabs are set to eight spaces.
Tabs are special characters. If you use a tab, it does
not insert as many characters as it takes to get to
the 8th, 16th, or so on space. If you replace tabs with the
appropriate number of spaces (with the
untabify command in
the file you are working with will look the same when viewed with
more, or vi commands,
another Emacs configuration, etc. You can make the tabs convert to
spaces before saving a document with
M-x untabify, and
the spacing will then look acceptable when you use the
cat commands or when you print the document.
If you want to change the default indentation level when editing source code in Emacs, you should modify the c-basic-offset variable. For example, to cause Emacs C mode to indent four spaces, you would enter:M-x set-variable RET c-basic-offset RET 4 RET
Note: If you aren't sure how to enter these commands in Emacs, see In Emacs, how are keystrokes denoted?
At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?
Last modified on August 22, 2008.