Emacs: Indentation/Completion Commands

By Xah Lee. Date: . Last updated: .

Here's how to indent code.

Indent Current Line

Alt+x indent-for-tab-commandTab】.

Indent a Text Selection

Select a region, then

Alt+x indent-regionCtrl+Alt+\

More indent commands:

Force Insert Tab Character

The following method works everywhere (also works in minibuffer).

To insert a literal tab char, press Ctrl+q Tab.

To insert a newline char, type Ctrl+q Ctrl+j.

You need to use the above method to insert these characters, because for example in minibuffer, pressing Tab does name completion and pressing Enter finishes the prompt. In most programing language modes, pressing Enter or Tab also does some auto indenting.

[see Emacs: Newline Representation ^M ^J ^L]

Convert Tabs to Space in Source Code

Select a region first, then Alt+x untabify

Use tabify to change spaces to tabs.

Make Whitespace Visible

Emacs: Make Whitespaces Visible

Name Completion

Emacs: Name Completion

Tab/Space/Indent Setup

Emacs: Tab/Space/Indent Setup

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs

Emacs Tutorial

Emacs Init

Emacs Keys

ELisp

ELisp Examples

ELisp Write Major Mode


Emacs Tutorial

Quick Start

Manage Windows

File

Buffer

Dired

On Current File

Find Replace

Copy/Paste

Unicode

Font

Whitespace

Rectangle Edit

Line Wrap

Shell

View Things

Working with Brackets

Power Editing

Org Mode

HTML

Emacs Efficiency

Misc