Emacs is a highly versatile and flexible text editor that offers a lot of powerful extensions and packages to its users. It is often considered to have a very steep learning curve, and with having so many things installed, it becomes hard to keep track of them all.

Hence, we have created this Emacs cheatsheet to help smoothen your experience.

Terminology

To make commands easier to understand, Emacs has a few abbreviations that need to be clarified before moving onto looking at some of its necessary commands.

The following specifies what each terminology means in terms of key bindings:

  • C-x means: click on Control and x at the same time
  • M-x means: type Alt then x; M here refers to Meta

Accessing Help

Emacs has a pretty detailed and straightforward help system. For first time users, it offers a built-in tutorial that can be accessed by using Ctrl h followed by t keys.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

By hitting Ctrl h followed by r, users can get access to the extremely detailed manual of Emacs.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Basic File Handling Commands

To open or create a file, hit the keys Ctrl x followed by Ctrl f and then enter the filename. If a file exists with that name, it will open that file. However, if a file with that name isn’t present, then Emacs will create a new file with that name.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

To replace this currently opened file with another, hit the keys Ctrl x followed by Ctrl v and enter the filename of the new file.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

A file can be saved with Ctrl x, followed by Ctrl s. To save a file with a different name, use the shortcut Ctrl x followed by Ctrl w and then enter the new filename.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

The shortcut Ctrl x, followed by i, can also be used to insert the contents of another file into your current file.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

To check the number of files or buffers opened, hit Ctrl x, followed by Ctrl b.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

To switch from one file to another, hit Ctrl x, followed by b.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

To close files, hit Ctrl x, followed by k. If no file is specified, then the default file is closed.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

To quit Emacs, hit Ctrl x followed by Ctrl c.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Moving Around

Similar to Vim, Emacs offers shortcuts for cursor movements as an alternative to using the mouse. The following table describes these in detail

Keys Movement
Movement By Forward Backward
Characters Ctrl f Ctrl b
Words Alt f Alt b
Lines Ctrl n Ctrl p
Sentences Alt e Alt a
Paragraphs Alt } Alt {
End/start of line Ctrl e Ctrl a
End/start of buffer Alt > Alt <
Scrolling Ctrl v (Down) Alt v (Up)

To display line numbers in your Emacs, hit Alt x and enter linum-mode. Now using this, you can go to a specific line number by hitting Alt g followed by g and then entering the line number. For example:

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Editing Tools



Emacs is quite a popular text editor, and that is mainly due to the amazing editing tools it provides to its users. One of these is the ability to repeat a command by the length specified. To do this, hit Ctrl u followed by entering the length of repeating and then entering the command to be repeated. For example, if I want to scroll three pages down, then this would be:

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Before being able to apply commands like copy and cut, we first have to select the region on which these commands will be applied. This is done by Ctrl Space. To mark the whole region that you want to select, drag the cursor to the end-point. For example, in the image below, the rectangle specifies the beginning of the selection and the circle its end.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

To select the contents of the whole file, hit the keys Ctrl x followed by h.

After selecting, you can apply the copy command on this using the keys Alt w. The cut command provides you with several options. To cut a single word, hit Alt d. To cut a single line, hit Ctrl k. To cut the whole selected region, hit Ctrl w.

Text can be pasted by using the shortcut Ctrl y. You can cycle around the killed items by using the key Alt y.

Latest Cut Item:

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Using Alt y to replace this with old killed item:

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Undo and redo operations can be applied by Ctrl / and Ctrl g followed by Ctrl / keys respectively.

To increase the text size of the screen, click the keys Ctrl x followed by Ctrl (plus) and decrease the text size by Ctrl x followed by Ctrl – (minus).

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Searching and Replacing Text

To perform a simple incremental search, use the keys Ctrl s. Jump from one result to another by continuously pressing this key.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

To perform this incremental search in reverse, use the keys Ctrl r.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

For regular expression, search to take place, hit the keys Ctrl Alt s.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

To perform a simple query, replace, use the keys Alt Shift 5.

Asking for the word to be replaced:

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Asking for the word to replace with:

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Similarly, Emacs also lets users perform a replacement of regular expressions using the keys Ctrl Alt Shift 5.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Error Recovery

Emacs has some great commands that offer aid in recovering or restoring the contents of a file. To abort commands that are either running or have been partially typed, click Ctrl g.

To recover a file whose data might have been lost, use the keys Alt x to open the mini-buffer and then enter recover-file.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

To recover the entire session, then hit Alt x and enter recover-session.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

To revert a changed file to its original form, hit Alt x and enter revert-buffer.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Accessing External Tools



The powerful nature of Emacs is seen from the fact that it makes integration with multiple external tools possible. This is one of the reasons why it is considered to be more than a text editor.

To open the shell inside Emacs, hit Alt x and enter the shell.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Emacs also has the GDB debugger built-in, which can be opened by hitting Alt x and entering gdb.

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Emacs also offers interesting games such as tetris, solitaire to its users. To open tetris, simply hit Alt x and enter tetris.

Command:

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Result:

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Conclusion?

To keep track of all the commands in Emacs, a cheat sheet becomes quite necessary to have since Emacs has lots of tools inside of it, and accessing them through the menu is quite the hassle.

About the author

Emacs Cheatsheet Emacs Practitioners Guide to Emacs Editor

Zeeman Memon

Hi there! I’m a Software Engineer by degree, Blogger by skills who loves to write about tech, develop websites & do SEO. You can reach out to me on LinkedIn.