Skip to content
Materials and notes for the LigerLearn Emacs course
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Emacs from scratch

This repository contains materials and notes for the LigerLearn Emacs from scratch course.

This document is a cheat sheet for Emacs which you can use throughout the course as well in the future for reference.

The course can be found at

Follow along to learn all about how you can make use of Emacs in your workflow today!


Opening files

Key BindingFunctionDescription
C-x C-f(find-file)Visit a file
C-x C-r(find-file-read-only)Visit a file for viewing, without allowing changes to it
C-x C-v(find-alternate-file)Visit a different file instead of the one visited last
C-x 4 f(find-file-other-window)Visit a file, in another window - Don’t alter what is displayed in the selected window
C-x 5 f(find-file-other-frame)Visit a file, in a new frame - Don’t alter what is displayed in the selected frame
M-x find-file-literally(find-file-literally)Visit a file with no conversion of the contents

The find file command is bound to the key sequence C-x C-f and is probably the main method you will end up using to open up files in Emacs. There are a few key things you should know about C-x C-f:

  • If you choose to open the path leading to a directory rather than a file then Emacs will open up a DirEd buffer for that directory
  • If you give it a path to a file which does not exist then Emacs will create a buffer named after that file.

C-x C-v, which runs the (find-alternate-file) command is a useful keybinding to know:

  • This is convenient for the situation where you have accidentally opened the wrong file or a file which does not exist by accident.
  • Here rather than using C-x C-f to open the correct file and have two buffers you can just use C-x C-v to select the correct file and the buffer you ran the command from will be automatically replaced with the new one.

Alternative ways of opening files

In addition to the main method of opening files using C-x C-f there a number of alternative ways you can open file in Emacs (these are largely only possible if you are running a graphical Emacs session):

  1. Drag and drop a file from your file explorer into Emacs
    • On Windows the file explorer would be Windows Explorer, on Mac OS X it would be the finder.
  2. Set file associations to Emacs so that you can simply open the file directly in Emacs
  3. Use the menu bar at the top of Emacs to click File -> Open File and then navigate to the file and choose to open it.

Saving files

Key BindingFunctionDescription
C-x C-s(save-buffer)Saves the current buffer to file if it has been modified
C-x C-w(write-file)Save the current buffer as another file

Line wrapping

You can think of lines in two ways:

  • Logical line: this is all the text up to the point where press the enter key
  • Visual/screen line: this is all the text that can fit on one visual line on the screen in emacs

If the logical line is too big to fit in a visual line in your Emacs window then the default behaviour is to wrap the line. The wrapped line will be indicated by arrows in the window fringes (if you are using the GUI) or backslashes (if you are using Emacs in the terminal).

Certain commands such as go to the beginning of the line (C-a or HOME) will operate on the logical line rather than the visual line. To get commands that usually operate on the logical line to operate on the screen line you can enter visual line mode:

; Toggle on/off
M-x visual-line-mode

; Show the left and right arrow in the window fringes for lines which are wrapped
; even when using visual line mode
(setq visual-line-fringe-indicators '(left-curly-arrow right-curly-arrow))

An alternative to wrapping lines is to truncate them. You can choose to truncate lines by toggling on truncate-lines:

; Toggle on/off line truncating
M-x toggle-truncate-lines

C-q prefix

Key bindingFunction
C-q C-<letter-in-caret-notation>(quoted-insert ARG)
C-q <octal-number> RET(quoted-insert ARG)

The C-q prefix allows you to enter characters (ASCII control characters or otherwise) in a convenient way.

  • For example:
    • C-q C-<letter-in-caret-notation>
      • C-q C-@ inserts ^@
      • C-q C-A inserts ^A
    • C-q <octal-number> RET
      • C-q 0 RET inserts ^@
      • C-q 1 RET inserts ^A

If you do not want to be entering octal numbers you can set read-quoted-char-radix to the radix you would like to use:

(setq read-quoted-char-radix 8)  ; for octal
(setq read-quoted-char-radix 10) ; for decimal
(setq read-quoted-char-radix 16) ; for hexadecimal
You can’t perform that action at this time.