2020-10-02
|~5 min read
|824 words
A course I’m taking strongly encourages the use of emacs, so I now have an opportunity to learn that along with vim! I suspect I will never become a super user in either (though I’m more inclined to give it a go with vim at the moment), but that’s okay. My goal is to be competent enough to be able to work in any environment. To that end, I’ll keep track of some of the lessons I’m learning so that I have a reference.
Emacs uses ⌃
(Control) and Meta1. Often times, these are written simply as C
and M
respectively.
This means that C-x
and ⌃-x
are the same. For simplicity, I will use the C
and M
convention.
C-x C-c
: Quit EmacsC-g
: Cancel the current actionC-x C-f
: Visiting (Open) a file (whether or not it already exists) - More on Visiting filesC-x C-s
: Save a fileC-x C-w
: Write a file (probably more familiar to you as Save as…)C-Space
: Set a mark (this is useful for highlighting. By setting a mark you are then able to navigate and highlight the text under the selection.)C-w
: Cut a highlighted regionM-w
: Copy a highlighted regionC-k
: Cut (kill) from the cursor to the end of the lineC-y
: Paste (yank)C-x u
or C-_
: Undo<DEL>
: Delete the character just before the cursorC-d
: Delete the next character after the cursorM-<DEL>
: Kill the word immediately before the cursorM-d
: Kill the next word after the cursorC-k
: Kill from the cursor position to end of lineM-k
: Kill to the end of the current sentenceC-p
: Previous lineC-b
: BackwardM-b
: Backward one wordC-f
: Forward one characterM-f
: Forward one wordC-n
: Next lineC-v
: Move forward one screenM-v
: Move backward one screenC-l
: Clear the screen (i.e. recenter the cursor in the center of the screen)M-<
: Jump to the beginning of the file (note, that’s actually <
, which means ⇧+,
)M->
: Jump to the end of the file (note, that’s actually >
, which means ⇧+.
)C-x b
: Switch to another buffer by entering its nameC-x C-b
: See a list of all current buffersC-x <left>
: Navigate to the previous bufferC-x <right>
: Navigate to the next bufferC-x k [buffer] ret
; Kill [buffer]
M-x kill-some-buffers
- Offer to kill buffers one-by-oneM-x kill-matching-buffers
- Kill buffers matching a regular expressionM-x clean-buffer-list
- useful for purging unmodified / stale buffersMore on killing buffers.
C-x 2
: Create a new window belowC-x 3
: Create a new window on rightC-x 0
: Close current windowC-x 1
: Close other windowsC-x o
: Goes to the other-window
. There are a number of solutions, but they all require plugins (some built-in) and configuration. For more of a discussion, see this StackExchange Q&A.C-z
: Open integrated terminalC-x C-q
: Disable Read-Only ModeIn addition to the help button/menu on the right…
C-h
: Hitting this will display a short message in the minibuffer: 𝙲-𝚑 (𝚃𝚢𝚙𝚎 ? 𝚏𝚘𝚛 𝚏𝚞𝚛𝚝𝚑𝚎𝚛 𝚘𝚙𝚝𝚒𝚘𝚗𝚜).C-h b
: Key bindings. This lists all key bindings that are valid for the current mode. Note that key bindings change from mode to mode.C-h a
: Command apropos. After typing C-h a
you can type a symbol and a buffer will appear that lists all symbols and functions that match that phrase.1 Mac keyboards do not have a Meta key be default (it’s typically an Alt
key), so the default is the ESC
(which is what Meta is converted to by Emacs anyway). If you do not want to use the ESC
key as the Meta, however, you can rebind it with the setting, “The Command key acts as the Emacs Meta key (source: Specifying A Meta Key). An easier way is to rebind it within your terminal. I use ITerm2, where the steps are described in the FAQ:
Q: How do I make the option/alt key act like Meta or send escape codes?
A: Go to Preferences > Profiles tab. Select your profile on the left, and then open the Keyboard tab. At the bottom is a set of buttons that lets you select the behavior of the Option key. For most users, Esc+ will be the best choice.
A similar solution is available for Mac’s native Terminal application as described in this Stack Overflow answer.
Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!