Skip to main content

Emacs

https://www.gnu.org/software/emacs

Manual: https://www.gnu.org/software/emacs/manual/html_node/emacs/index.html

Reference Cards: https://www.gnu.org/software/emacs/refcards/index.html

https://www.emacswiki.org

https://emacsrocks.com

Emacs cheatsheet - https://quickref.me/emacs.html

Open with now window: emacs -nw <filename>

Meta key on macOS​

info

On iTerm2, you need to change the left option (⌥ or Alt) key as explained in Fix the Emacs "Meta" (M) key in iTerm2.

https://www.reddit.com/r/emacs/comments/mu12y7/best_mapping_for_m_meta_key/

On macOS, Meta is usually Option (⌥), not Command (⌘). So M-q normally means Option + Q.

You can also use the universal alternative:

Esc, then Q

Press and release Esc, then press q. Emacs interprets that as M-q.

Manage windows​

Emacs calls panes windows.

ShortcutAction
C-x oMove to the next window
C-x 0Close the current window
C-x 1Keep the current window and close all others
qClose many help windows when they are focused

If a help window opens beside your file (at the right), move to your file with C-x o if necessary, then press C-x 1.

Init file​

You can use ~/.emacs, ~/.emacs.el, ~/.emacs.d/init.el and others.

Interesting comment (source):

I would recommend ~/.emacs.d/init.el, though, because that makes it easier to keep the whole Emacs configuration under version control.

Undo​

C-x u

https://www.emacswiki.org/emacs/UndoCommands

Cut, copy and paste​

To cut and paste a single line you can use C-k to cut and C-y to paste. To cut a sentence, use M-k. To cut a word, use M-d.

To select a region, press Ctrl+Space to start selecting text (you should see "Mark set" at the minibuffer), then use the arrow keys to select the text you want. Once you have selected the text, you can cut it with Ctrl+w or copy it with M-w, then paste it with Ctrl+y.

Modern TermEmacs TermShortcut
CutKillC-w
CopyKill ring saveM-w
PasteYankC-y

You can also use the mouse. From https://web.physics.utah.edu/~detar/lessons/emacs/emacs/node8.html:

The mouse way is much simpler. Left-drag with the mouse to highlight the selected region. Then double right-click to cut. Move the cursor to the paste position and click with the middle mouse button. If you just want to copy, don't do the double right-click.

There is a second mouse way to select a region, which is particularly useful when you are selecting a large portion of your file. Left-click with the mouse on the first character. Then right click immediately to the right of the last character. Complete the operation as before.

Show line and column numbers​

Go to your init file and add (setq column-number-mode t). From https://www.gnu.org/software/emacs/manual/html_node/efaq/Displaying-the-current-line-or-column.html

Note that this works on version >= 26.