User Tools

Site Tools


Emacs Cheatsheet

Basic Movement and Editing Commands

C-x C-f Find file and load into buffer (Emacs prompts for filename)
C-x C-s Save the current buffer
C-x C-w Save the current buffer under a different name (Emacs prompts for the new name)
C-x C-c Quit Emacs, prompting if you have not saved any buffers
Arrow keys or C-f, C-b, C-n, C-p Right (forward), left (back), down (next), up (previous), respectively
C-k Delete from cursor to end of line
C-a Go to start of line
C-e Go to end of line
C-v Go down a page
M-v Go up a page
M-f Go to next word
M-b Go back one word
M-a Go to previous sentence
M-b Go to next sentence
C-/ Undo
C-_ Undo (alias for C-/)
C-x u Undo (alias for C-/)
C-g Abort the current command
C-l Redraw and center screen at cursor
M-< Go to start of buffer
M-> Go to end of buffer
C-d Delete next character
M-d Delete next word
M-| Execute shell command on region
Backspace Delete previous character

Kill & Yank (Cut/Copy and Paste)

C-space Set the mark
C-w Cut (kill)
M-w Copy (kill)
C-y Paste (yank)
M-y Paste (yank) next saved selection
C-x h Set point to start of buffer and mark to end of buffer (select the entire buffer)
C-x C-x Swap point and mark

Search & Replace

C-s Incremental search forward
C-r Incremental search backward
C-M-s Regexp search forward
C-M-r Regexp search backward
M-% Search and replace
M-x query-replace-regexp Search and replace with regexps
C-g Abort a search
C-w During a search, highlight the word around the cursor
Up, down arrow keys or M-p, M-n Access search string history

Emacs Modes

M-x modename Toggle the given major or minor mode
C-h m Display help on the current major mode, including any special key bindings in effect
M-q Used in text-mode to reformat a paragraph of text manually
M-x global-font-lock-mode Toggle syntax highlighting


C-x b Switch to another buffer
C-x C-b Display buffer list
C-x k Kill current buffer (Emacs prompts for confirmation)
M-x iswitchb-mode Enable iswitch mode, for smart buffer name completion with C-x b


C-x 0 Close this window
C-x 1 Close all other visible windows
C-x 2 Split horizontally
C-x 3 Split vertically
C-x o Switch to other window
C-M-v Scroll other window

Dired Mode

M-x dired Load dired mode (Emacs prompts for directory name)
C-x C-f Dired mode loaded when a directory is specified as load file
Left, right arrow keys or p, n Previous and next file, respectively
Enter Visit this file in this window
o Visit this file in a new window
g Refresh directory view
m Mark file
u Un-mark file
d Mark a file for later deletion
x Delete all files marked for deletion (Emacs prompts for confirmation)
D Delete this file right now (Emacs prompts for confirmation)
C Copy this file, or copy currently marked files (Emacs prompts for destination)
R Rename/move this file, or rename/move currently marked files (Emacs prompts for destination)
M Chmod this file, or chmod currently marked files (Emacs prompts for new permissions)
O Chown this file, or chown currently marked files (Emacs prompts for new owner)
G Chgrp this file, or chgrp currently marked files (Emacs prompts for new group)
+ Create directory (Emacs prompts for directory name)
! Execute shell command on this file, or currently marked files (Emacs prompts for command)

Shell Modes

M-x shell Shell mode, use M-p and M-n for command history
M-x eshell Cross-platform Emacs Lisp shell emulator, use arrow keys for command history
M-x ansi-term Full terminal emulator, suitable for full-screen applications.

Getting Help

C-h t Emacs tutorial
C-h a Apropos (Emacs prompts for keyword or regexp)
C-h i Load info browser
C-h m Display help on current mode
C-h f Display help on function (Emacs prompts for function)
C-h k Display help on key (Emacs prompts for key)
M-x man Display a man page in a new buffer (Emacs prompts for man page)

w3m mode

M-x w3m Start browsing web with emacs-w3m.
q Close all emacs-w3m windows, without deleting buffers.
Q Exit browsing web. All emacs-w3m buffers will be deleted.
RET Display the page pointed to by the link under point.
C-c C-c Submit the form at point.
R Reload the current page.
r Redisplay the current page.
TAB Move the point to the next anchor.
M-TAB Move the point to the previous anchor.
B Move back to the previous page in the history.
N Move forward to the next page in the history.
U Visit the web page.
H Go to the Home page.
M-d Download the URL.
d Download the URL under point.
\ Display the html source of the current page.
SPC Scroll up the current window, or go to the next page.
b Scroll down the current window, or go to the previous page.
> Scroll to the left.
< Scroll to the right.
. Shift to the left.
, Shift to the right.
M-l Recenter horizontally.
j Next line.
k Previous line.
l Forward char.
h Backward char.
s Display the history of pages you have visited in the session.
S Prompt for a search query and submit it to google.
v Display the bookmarks list.
a Add a url of the current page to a new bookmark.
M-a Add the url under point to a new bookmark.

Sample .emacs

  ;; Sample ~/.emacs file
  ;; Un-comment what you want to enable and re-start Emacs
  ;;Load iswitch mode
  ;;(require 'iswitchb)
  ;;Make text mode the default for new buffers
  ;;(setq default-major-mode 'text-mode)
  ;;Turn on refill-mode whenever text mode is entered
  ;;(add-hook 'text-mode-hook
  ;;  '(lambda () (refill-mode 1)))
  ;;Enable syntax highlighting when it's allowed
  ;;(when (fboundp 'global-font-lock-mode)
  ;;  (global-font-lock-mode t))
  ;;Fix the backspace key
  ;;(normal-erase-is-backspace-mode 1)
  ;;Use cperl-mode for editing Perl code, it is better than perl-mode
  ;;(defalias 'perl-mode 'cperl-mode)
  ;;Don't blink my cursor, please
  ;;(blink-cursor-mode nil)
  ;;Display the current time in the modeline
  ;;(display-time-mode t)
  ;;Start the emacs server
  ;;When this is running, programs calling emacsclient open a buffer
  ;;in the already running emacs. Useful in mutt or pine for composing
  ;;mail in Emacs. Type C-x # to exit client buffer and send the text
  ;;back to the application that called it.

$Id: emacs-cheatsheet.html,v 1.4 2013/01/18 11:00:13 nullogic Exp $ Emacs Cheatsheet - traditional link (using RCS)

emacs_cheatsheet.txt · Last modified: 2021/03/21 06:39 by hc9