: Learning GNU Emacs, 3rd Edition

7.1.1 How Emacs 21 Handles Tabs by Default

7.1.1 How Emacs 21 Handles Tabs by Default

If you open a new file in text mode, tabs are set every eight spaces by default. (Programming modes have their own indentation behavior; see Chapter 9 for details.)

Press Tab.


Pressing Tab in text mode or fundamental mode inserts a tab character that moves the cursor forward eight columns by default.

Watch what happens when we type a sentence. The default tab stops change automatically.

Type: It was the best of times Enter Tab Tab


Pressing Tab twice moves the cursor under the word was, clearly less than eight columns.

Every time you press Tab, Emacs moves the cursor under the next word. This is the behavior that many people expect when writing code. Neatly lined up code is easier to read.

As we experimented with this feature, we would tab across under each word, and press Enter. What happens next is surprising if you are not expecting it. Emacs considers that newline to be the only character you typed on the line, so pressing Tab on a subsequent line brings you nearly to the end of the line.

Press Tab repeatedly to the end of the window, press Enter, then press Tab once.


Emacs moves the cursor to the column where you pressed Enter.

If you press Enter but don't press Tab at all, the indentation level moves back to the left margin.

Changing tabs to align with each word can be helpful, if, for example, you're typing tables. However, the default tab behavior may not be helpful to you in all situations. If you are interested in changing the default behavior, read on and we'll describe how to get Emacs to do what you want it to do.


: 0.301. /Cache: 3 / 1