Emacs Keys

From Coder Merlin
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

Overview[edit]

  • A key sequence will be displayed as a series of keys, presented from left to right in the order that each key should be pressed. A space character will separate each of these keys. For example, if the key sequence is q u, this indicates that you should press and release the q key, and then press and release the u key.
  • In some cases, a key sequence requires that a key be pressed with a modifier. In these cases, the modifier will appear first, followed by a hyphen, followed by the second key. A very common modifier is SHIFT. For example, SHIFT-Q would indicate that you first press (and hold) the SHIFT key, then press and release the Q key, then release the SHIFT key. However, because the need to use the shift key is apparent based on the character required, we generally won't show the need for this modifier. As an example, if the required sequence is 4, you'd simply press and release the 4 key. However, if the required sequence is $, you'd need to press and hold the SHIFT key, press and release the $ key, and then release the SHIFT key. All other modifier keys will be displayed explicitly.
  • The sequence CONTROL-u indicates that you first press (and hold) the CONTROL key, then press and release the u key, then release the CONTROL key. The emacs manual will refer to this sequence as C-u.
  • The sequence ALT-x indicates that you first press (and hold) the ALT key, then press and release the x key, then release the ALT key. The emacs manual will refer to this sequence as M-x.
  • If there is a space rather than a dash between keys, the first key must be released before pressing the next key. For example, ESC x indicates that the ESC key should be pressed and released, and then the x key should be pressed and released.
  • There are some cases which require two modifier keys. As an example, the sequence CONTROL-SHIFT-_ indicates that you should first press and hold the CONTROL key, then press and hold the SHIFT key, then press and release the _ key, and then release the other two modifier keys.

Help[edit]

Key Sequence Purpose
CONTROL-h ? Provide help options
CONTROL-h t Start the tutorial
CONTROL-h k Provide details about a key sequence
CONTROL-h c Provide the name of a specific command
CONTROL-h f Describes a specific function
CONTROL-h a Provide a list of commands appropriate for the specified description
CONTROL-h i information mode facilities to read included manuals
CONTROL-h m Provide details about the current mode

Undo and Cancellation[edit]

Key Sequence Purpose
F9 Undo the changes made by a command (Merlin Extension)
CONTROL-SHIFT-_ Undo the changes made by a command
CONTROL-g CONTROL-SHIFT-_ Redo a previously "undo"
CONTROL-g Cancel a partially typed command or argument prefix

Suspend and Exit[edit]

Key Sequence Purpose
CONTROL-x CONTROL-c Exit emacs
CONTROL-z Suspend emacs temporarily

Navigation[edit]

Key Sequence Purpose
CONTROL-v Scroll down (forwards) one page
ALT-v Scroll up (backwards) one page
CONTROL-l (second character is lowercase 'L') Clear screen and redisplay the text, moving the cursor to the vertical center
CONTROL-f Move the cursor forward one character
CONTROL-b Move the cursor backward one character
CONTROL-p Move the cursor up one line (previous line)
CONTROL-n Move the cursor down one line (next line)
ALT-f Move the cursor forward one word
ALT-b Move the cursor backward one word
CONTROL-a Move the cursor to the beginning of a line
CONTROL-e Move the cursor to the end of a line
ALT-a Move the cursor to the beginning of a sentence
ALT-e Move the cursor to the end of a sentence
ALT-SHIFT-< Move the cursor to the beginning of the file
ALT-SHIFT-> Move the cursor to the end of the file

Deleting, Killing, and Yanking Text[edit]

Key Sequence Purpose
CONTROL-d Delete character under the cursor
DEL Delete character to the left of the cursor
ALT-d Kill word after the cursor
ALT-DEL Kill word before the cursor
CONTROL-k Kill text from the cursor to the end of the line
CONTROL-u 0 CONTROL-k Kill text from the cursor to the beginning of the line
ALT-k Kill text from the cursor to the end of the sentence
CONTROL-w Kill selected text (in region)
CONTROL-y Yank text from the first block of the kill ring, and insert it at the current cursor position
ALT-y Yank text from the previous block of the kill ring, and insert it at the current cursor position

Marking a Region[edit]

Key Sequence Purpose
CONTROL-SPACE Mark the beginning of a region
CONTROL-x h Mark the entire text

Repeating Commands[edit]

Key Sequence Purpose
CONTROL-u <numeric sequence> Repeat next command <numeric sequence> times

Windows[edit]

Key Sequence Purpose
CONTROL-x 1 (second character is the digit one) Return to one window (closes all other windows)
CONTROL-x 2 Split the screen horizontally
CONTROL-x 3 Split the screen vertically
CONTROL-x 0 (the second character is the digit zero) Close the current window
CONTROL-x o (the second character is lowercase "O") Move the cursor to the other window
CONTROL-ALT-v Scroll the other window
ALT-x rotate-frame Rotate frames
ALT-x transpose-frames Transpose frames

Buffers[edit]

Key Sequence Purpose
CONTROL-x CONTROL-b Display a list of all buffers
CONTROL-x b Switch to the specified buffer
CONTROL-x  Select previous buffer
CONTROL-x  Select next buffer

Files[edit]

Key Sequence Purpose
CONTROL-x CONTROL-f Find the specified file
CONTROL-x 4 CONTROL-f Find the specified file and open in other window
CONTROL-x CONTROL-s Save the current file
CONTROL-x s Save changed files (prompts for all confirmation)

Find and Replace Strings[edit]

Key Sequence Purpose
CONTROL-f Incremental forward search
CONTROL-r Incremental reverse search
ALT-x replace-string RET Replace the specified string with another

Formatting[edit]

Key Sequence Purpose
ALT-x auto-fill-mode RET Toggle auto-fill mode
CONTROL-x f Specify margin in terms of characters
ALT-q Re-fill the paragraph using the current margin
ALT-x set-justification-leftRET Left justify the region
ALT-x set-justification-rightRET Right justify the region
ALT-x set-justification-fullRET Full justify the region


Spelling[edit]

Key Sequence Purpose
ALT-x flyspell-modeRET Enable Flyspell mode, which highlights all misspelled words.
ALT-$ Check and correct spelling of the word at point
ALT-x ispellRET Check and correct spelling of the entire buffer (or region)

Macros[edit]

Key Sequence Purpose
F3 Start recording macro
F4 Finish recording macro
F4 Use previously recorded macro
ALT-X name-last-kbd-macro Assign name to last keyboard macro
ALT-X insert-kbd-macro Copy macro to buffer

May subsequently be placed in emacs initialization file.
Assign key to macro in emacs initialization file:
(global-set-key (kbd "<f5>") 'save-compile-run)

ALT-X macro-name Run specified macro

Building and Running (Merlin Extensions)[edit]

Key Sequence Purpose
F5 a Async Shell Command
F5 b Build
F5 c Compile (similar to build but enables links to errors)
F5 r Build and Run
F5 s Shell command
F5 w Switch to compilation window

Language Services (Merlin Extensions)[edit]

Key Sequence Purpose
F6 a Apply action
F6 c Comment region
F6 d Find definition
F6 e List errors
F6 n Next error
F6 p Previous error
F6 r List references
F6 u Uncomment region
F6 w Describe what is at point
Shift-Tab List completion candidates
ALT-x lsp-restart-workspace Restart LSP
ALT-x lsp-describe-session Describes the current LSP session
ALT-x lsp-workspace-folders-remove project-root Remove project-root from the list of workspace folders
ALT-x lsp-workspace-folders-add project-root Add project-root to the list of workspace folders