Emacs Basics Tips

By Xah Lee. Date: . Last updated: .

Here's answer to most frequently asked questions.

How to search text?

How to find replace?

Emacs: Find Replace in Current File

How to find replace for all files in a dir?

Emacs: Find Replace Text in Directory

How to insert/delete comment?

  1. Alt+x set-mark-commandCtrl+Space】 to mark, then move cursor to select text.
  2. Alt+x comment-dwimAlt+;】 to make the region into a comment or uncomment.

[see Emacs: Toggle Comment Current Line]

How to add a prefix to every line? (such as # or //)

Emacs: Edit Column Text, Rectangle Commands

How to delete the first few n chars of every line?

Emacs: Edit Column Text, Rectangle Commands

How to replace unprintable characters such as tab or newline characters in Emacs?

Alt+x query-replaceAlt+%】. When you need to insert a tab character, type Ctrl+q first, then press Tab. Same for inserting a line return.

[see Emacs: Newline Convention CR LF]

How to change file line endings between Windows/Linux/Mac?

Alt+x set-buffer-file-coding-system, then give a value of “mac”, “dos”, “unix”. Then, save.

[see Emacs: Convert File Line Ending]

How to record a sequence of keystrokes?

Emacs: Keyboard Macro

How to move thru camelCaseWords?

Emacs: Move Cursor by camelCase, snake_case

How to have spell-checker turned on?

Emacs: Spell Checking

How to find a command?

Emacs Principles, Command and Keys

List Lines

Emacs: List/Delete Matching Lines, Sort Lines

Highlight Words

Emacs Highlighting Commands

Sort Lines

Emacs: List/Delete Matching Lines, Sort Lines

Delete Trailing White Spaces

Emacs: Delete Trailing Whitespace

Make Spaces and Tabs Visible

Alt+x whitespace-mode. [see Emacs: Make Whitespaces Visible]

Multiple Clipboards

Emacs: Copy to Register

No restarting emacs when add to init file

Just select the new emacs lisp code, then Alt+x eval-region.

[see Emacs: Init File Tutorial]

Start a second shell

Ctrl+u Alt+x shell.

[see Emacs: Run Shell in Emacs]

Refresh a opened file to its saved state

Alt+x revert-buffer

[see Emacs: Refresh File Automatically]

Open file as hex-decimal (byte-code editor)

To open the file as hex, Alt+x hexl-find-file. If the file is already opened, Alt+x hexl-mode.

[see Emacs: Set Default Major Mode]

Set background color

Emacs: Set Color Theme

ErgoEmacs mascot-s276x226
Buy Xah Emacs Tutorial

Emacs Tutorial

Quick Start

Manage Windows

File

Buffer

Find Replace

Copy/Paste

Unicode

Whitespace

Rectangle Edit

Line Wrap

Shell

View Special File

Editing Brackets

Org Mode

HTML

Emacs Efficiency

Misc