Emacs Keys Basics

By Xah Lee. Date: . Last updated: .

Basic Keyboard Shortcuts

Open, Save, Close, File

KeyCommand NamePurpose
Ctrl+x Ctrl+ffind-fileOpen a file
Ctrl+x Ctrl+ssave-bufferSave file
Ctrl+x kkill-bufferClose current file

Copy Paste Undo

Emacs's default Copy Cut Paste Undo keys
KeyCommand NamePurpose
Ctrl+/undoUndo. (To redo, type 【Ctrl+g】 then undo.)
Alt+wkill-ring-saveCopy
Ctrl+wkill-regionCut
Ctrl+yyankPaste

Moving Cursor

Use the arrow keys    , and Home, End, Page Up, Page Down keys.

KeyCommand NamePurpose
Ctrl+】 or 【Alt+bbackward-wordMove cursor left by word.
Ctrl+】 or 【Alt+fforward-wordMove cursor right by word.
Ctrl+Home】 or 【Alt+<beginning-of-bufferBeginning of file.
Ctrl+End】 or 【Alt+>end-of-bufferEnd of document.
KeyCommand NamePurpose
Ctrl+fforward-charMove cursor right 1 char.
Ctrl+bbackward-charMove cursor left 1 char.
KeyCommand NamePurpose
Ctrl+vscroll-up-commandpage down
Alt+vscroll-down-commandpage up

Deleting Text

KeyCommand NamePurpose
Alt+dkill-wordDelete the word to the right.
Alt+⌫ Backspacebackward-kill-wordDelete the previous word
Ctrl+kkill-lineDelete all characters from cursor to end of line

Select Text

Text Selection Commands
KeyCommand NamePurpose
Ctrl+Spaceset-mark-commandMark the starting point for copy/cut a text. (then move cursor to extend selection.)
Ctrl+x hmark-whole-bufferSelect All

Split Window

KeyCommand NamePurpose
Ctrl+x 2split-window-belowSplit window top / bottom
Ctrl+x 3split-window-rightSplit window side by side
Ctrl+x 1delete-other-windowsRemove all split panes
Ctrl+x oother-windowMove cursor to the other pane

Searching Text

To search a word, press 【Ctrl+s】, then type your search text, emacs will move the cursor to the location of the matched text as you type. Press 【Ctrl+s】 again to jump to the next occurrence, press 【Ctrl+r】 to jump to the previous occurrence.

Once you found what you are looking for, press Enter to exit.

To exit search and leave the cursor at the place before search started, press 【Ctrl+g】.

For detail, see: Emacs: Search / Highlight Word.

Find Replace Text

See: Emacs: Find and Replace Commands.

Standard Copy Paste Keys

emacs cua mode menu

To have standard keys for copy cut paste , turn on CUA mode,

Alt+x cua-mode

cua-mode activates the following keyboard shortcuts:

To have 「cua-mode」 always on, put the following in your emacs init.

;; use C-x for cut
;; C-c for copy
;; C-v for paste
(cua-mode 1)

Everything is a Command

In emacs, every keystroke executes a command. For example, when you type a key e, emacs actually runs the command self-insert-command.

Any key or key combination sequence you press ultimately calls a command.

There are over 3 thousand commands in emacs by default.

Most commonly used commands have a keyboard shortcut, such as moving the cursor, opening file, copy paste, close a file, search text.

To run a command by name, type 【Alt+x】 followed by the command name.

ShortcutCommand NameDescription
Alt+xexecute-extended-commandexecute a command by name
Ctrl+gkeyboard-quitCancel a command in progress, or cancel unfinished keyboard keystroke sequence

Finding a Command's Name or Keyboard Shortcut

If you know a command's name, you can find out its keyboard shortcut (if there is one). Alt+x describe-function.

If you know a keyboard shortcut, you can find out what command it calls. Alt+x describe-key.

ShortcutCommand NameDescription
Ctrl+h kdescribe-keyFind the command name of a key
Ctrl+h fdescribe-functionFind the key of a command

Example of Useful Commands

In emacs, a selection of text is called region. (aka text selection.)

Many commands acts on the selected text. Here are some examples of commands that act on the region.

Not all commands acts on region. Here are some commands that do not necessary need a region:

The above are just some examples of commands.

Like my tutorial? Put $5 at patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

Ask me question on patreon