Emacs Keys Basics

By Xah Lee. Date: . Last updated: .

Here's list of basic emacs default keys.

Open, Save, Close, File

Ctrl+x Ctrl+ffind-fileOpen
Ctrl+x Ctrl+ssave-bufferSave
Ctrl+x kkill-bufferClose

Copy Paste Undo

Ctrl+_undoUndo. (To redo, type Ctrl+g then undo. (all subsequent undo is redo, until you type something else.))
Alt+wkill-ring-saveCopy
Ctrl+wkill-regionCut
Ctrl+yyankPaste

Move Cursor

Use the arrow keys , and Home, End, PageUp, PageDown keys.

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.
Ctrl+fforward-charMove cursor right 1 char.
Ctrl+bbackward-charMove cursor left 1 char.
Ctrl+vscroll-up-commandpage down
Alt+vscroll-down-commandpage up

Delete Text

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

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

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

Search 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 Text in Current File.

Find Replace Text

Emacs: Find Replace in Current File

Standard Copy Paste Keys

To have standard keys for copy cut paste , turn on CUA mode, Alt+x cua-mode

emacs cua mode menu 2021-07-19
emacs cua mode menu

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.

execute-extended-commandAlt+x
Execute a command by name
keyboard-quitCtrl+g
Cancel a command in progress, or cancel unfinished keyboard keystroke sequence

Find What a Key Do

Alt+x describe-keyCtrl+h k
Prompt to type a key shortcut, then show command name and doc bound to that key.

Find a Command's Key

Alt+x describe-functionCtrl+h f
Prompt to type a command name, it'll shows the command's key, if any.

How to Define Keys

You can define your own keys for any command.

Emacs: How to Define Keys

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial

Emacs Tutorial

Emacs Init

Emacs Keys

ELisp

ELisp Examples

ELisp Write Major Mode


Emacs Tutorial

Quick Start

Manage Windows

File

Buffer

Find Replace

Copy/Paste

Unicode

Whitespace

Rectangle Edit

Line Wrap

Shell

View Special File

Working with Brackets

Org Mode

HTML

Emacs Efficiency

Misc