- Keys
- By Topic
- From Cool Keys in Emacs
- File Handling Commands
- Cursor Movement Commands
- Deletion Commands
- Paragraphs and Regions
- Transposition Commands
- Capitalization Commands
- Incremental Search Commands
- Word Abbreviation Commands
- Buffer Manipulation Commands
- Window Commands
- Special Shell Characters
- Indentation Commands
- Centering Commands
- Macro Commands
- Detail Information Help Commands
Keys
By Topic
Macros
C-x ( –
kmacro-start-macro
Use C-x )
to finish recording and make the macro available.
Use C-x e
to execute the macro. After hitting C-x e
to run it once, keep
hitting just the 'e' key for repeated execution.
Use M-x kmacro-name-last-macro
to give it a permanent name.
Use M-x kmacro-bind-to-key
to bind it to a key sequence.
Appending to a macro
- Non-nil arg (prefix arg) means append to last macro defined.
- So, with
C-u
prefix, append to last keyboard macro defined. - Depending on `kmacro-execute-before-append', this may begin by re-executing the last macro as if you typed it again.
- Otherwise, it sets
kmacro-counter
toARG
or 0 if missing before defining the macro.
Counters
- Use
M-x kmacro-insert-counter
to insert (and increment) the macro counter. - The counter value can be set or modified via
M-x kmacro-set-counter
andM-x kmacro-add-counter
. - The format of the counter can be modified via
M-x kmacro-set-format
.
Handy
key | Description |
---|---|
C-x z | Repeat most recently executed command. |
C-x M-: | Edit and re-evaluate last complex command (or arg-th from last.) |
M-x list-matching-lines | shows you all the lines in a buffer that match some regexp |
M-t | transpose-words. Use negative prefix to go the other way. |
fill-paragraph (Alt-p) | intelligently line-wraps your text for you: an absolute must, and it works inside source-code comments. |
M-q |
“fills” (word-wraps) what you’re on. It honors comments, bulleted lists, indentation, and other little things. I use it in programming modes to fill comments and I use it in text, HTML, and GXP modes to automatically split up long lines. |
C-/ |
is Undo |
M-/ |
expands the word you’re on (useful for long variable/function names) |
C-c / |
/ in HTML mode will close the last open tag |
C-x p - |
p - runs p4 diff and shows you the results in an editable buffer |
M-\ |
deletes all whitespace at the cursor location |
M-space |
replaces all whitespace with one space |
C-x C-o |
delete-blank-lines . Also see delete-trailing-whitespace , tabify , untabify , indent-region , etc. |
M-m |
Jump to first non-blank character in line (use instead of C-a TAB. |
M-x occur |
Display in a separate buffer the list of all lines in the current buffer that match a regex. |
C-M-s |
Regular expression incremental search |
M-% |
Query replace (M-x re-builder) |
M-C-% |
Query regex replace (M-x query-replace-regex) |
C-x r SPC register |
Record the position of point and the current buffer in register r (point-to- register). |
C-x r j register |
Jump to the position and buffer saved in register r (jump-to-register). |
C-s C-s |
Search for most recently searched item |
C-s M-p |
Previous item in search history |
C-s M-n |
Next item in search history |
C-x n n |
Narrow buffer to the current region |
C-x n w |
Restore ("widen") buffer |
C-y |
Yanks last killed text |
M-y |
Replace yanked text with previously killed text |
C-w |
Kill region ("cut") |
M-w |
Save region to kill ring without deleting ("copy") |
M-z |
M-z (Zap), similar to df in vim, but can go to other lines |
M-g g |
Jump to specified line |
C-SPC |
Set mark to the current location |
C-x C-x |
Swap point and mark |
C-x r <SPC> |
Record the position of point and the current buffer in register |
C-x r j |
Jump to the position and buffer saved in register |
From Cool Keys in Emacs
File Handling Commands
key | function | Description |
---|---|---|
C-x C-f |
find-file | Find a file and read it to screen. |
C-x C-v |
find-alternate-file | Read a different file. |
C-x i |
insert-file | Insert a file at the cursors position. |
C-x C-s |
save-buffer | Save the current buffer. |
C-x C-w |
write-file | Write the contents of the buffer to a file. |
C-x C-c |
save-buffers-kill-emacs | Save all open buffers and get out of emacs. |
C-z |
suspend-emacs | Suspend emacs. |
Cursor Movement Commands
key | function | Description |
---|---|---|
C-f |
forward-char | Move cursor one character. |
C-b |
backward-char | Move backward one character. |
C-p |
previous-line | Move up one line. |
C-n |
next-line | Move down one line. |
M-f |
forward-word | Move to the next word. (words are defined by whitespace/special characters.) |
M-b |
backward-word | Move to the previous word. |
C-a |
beginning-of-line | Move to the beginning of the line. |
C-e |
end-of-line | Move to the end of the line. |
M-a |
backward-sentence | Move back one sentence. |
C-v |
scroll-up | Scroll up one screen. |
M-v |
scroll-down | Scroll down one screen. |
C-x [ |
backward-page | Go back one page. |
C-x ] |
forward-page | Go forward one page. |
M-> |
end-of-buffer | Move to end of buffer. |
M-< |
beginning-of-buffer | Move to beginning of the current buffer. |
C-l |
recenter | Redraw the screen with the current line in the center. |
M-(a number) |
digit-argument | Do the next command (a number) of times. |
Deletion Commands
key | function | Description |
---|---|---|
Del |
backward-delete-char | Delete the previous character. |
C-d |
delete-char | Delete the character under the cursor. |
M-Del |
backward-kill-word | Delete the previous word. |
C-k |
kill-line | Delete from the cursor to the end of line. |
M-k |
kill-sentence | Delete the sentence the cursor is in. |
C-x Del |
backward-kill-sentence | Delete the previous sentence. |
C-y |
yank | Restore deleted text at cursor. |
C-w |
kill-region | Delete a marked region. |
backward-kill-paragraph | Delete the previous paragraph. | |
kill-paragraph | Delete from the cursor to the end of the paragraph. |
Paragraphs and Regions
key | function | Description |
---|---|---|
C-@ |
set-mark | Mark the beginning (or end) of a region. |
C-Space |
set-mark | Ibid. |
C-x C-p |
mark-page | Mark the current page. |
C-x C-x |
exchange-point-and-make | Exchange the location of the cursor and the mark. |
C-x h |
mark-whole-buffer | Mark the current buffer. |
M-q |
fill-paragraph | Reset the paragraph. |
M-g |
fill-region | Reformat individual paragraphs with region. |
M-h |
mark-paragraph | Mark select paragraph. |
Stopping and Undoing Commands
key | function | Description |
---|---|---|
C-g |
keyboard-quit | Stop current command Now! |
C-x u |
advertised-undo | Undo the last edit (do it often) |
revert-buffer | Return the buffer to the state when last autosaved. |
Transposition Commands
key | function | Description |
---|---|---|
C-t |
transpose-chars | Transpose the two letters. |
M-t |
transpose-words | Switch two words. |
C-x C-t |
transpose-lines | Switch two lines. |
transpose-sentences | Switch two sentences. | |
transpose-paragraphs | Switch two paragraphs. |
Capitalization Commands
key | function | Description |
---|---|---|
M-c |
capitalize-word | Capitalize the first letter of the current word. |
M-u |
upcase-word | Make the word all uppercase. |
M-l |
downcase-word | Make the word all lowercase. |
C-x C-l |
downcase-region | Make the region all lowercase. |
C-x C-u |
uppercase-region | Make the region all uppercase. |
Incremental Search Commands
key | function | Description |
---|---|---|
C-s |
isearch-forward | Start an incremental search forward. |
C-r |
isearch-backward | Starts an incremental search in the reverse direction. |
C-w |
During isearch, adds the word following point to the search buffer. | |
C-y |
During isearch, adds the rest of the current line to the search buffer. | |
M-y |
Yank at isearch prompt | |
Meta |
Stop a successful search. | |
C-g |
keyboard-quit | Stop searching and return to the starting point. |
Del |
Delete an incorrect character whilst searching. |
Word Abbreviation Commands
key | function | Description |
---|---|---|
abbrev-mode | Enter abbreviation mode. | |
C-x - |
inverse-add-global-abbrev | Type in a global abbreviation, then its meaning. |
C-x C-h |
inverse-add-local-abbrev | Type in a local abbreviation, then its meaning. |
unexpand-abbrev | Undo the last word abbreviation. | |
write-abbrev-file | Write out the word abbreviation file. | |
edit-abbrevs | Edit the current word abbreviations. | |
list-abbrevs | View the current word abbreviations. | |
kill-all-abbrevs | Kill any abreviations for this session. |
Buffer Manipulation Commands
key | function | Description |
---|---|---|
C-x b |
switch-to-buffer | Move to the specified buffer. |
C-x C-b |
list-buffers | Display the list of currently active buffers. |
C-x k |
kill-buffer | Kill the current buffer |
kill-some-buffers | Ask about deleting each buffer currently active. | |
rename-buffer | Rename the current buffer to something else. | |
C-x s |
save-some-buffers | Ask whether to save each modified buffer |
Window Commands
key | function | Description |
---|---|---|
C-x 2 |
split-window-horizontally | Divide the current window horizontally in two. |
C-x 3 |
split-windws-vertically | Divide the current window vertically in two. |
C-x > |
scroll-right | Scroll the window right. |
C-x < |
scroll-left | Scroll the window left. |
C-x 0 |
delete-window | Delete the current window. |
C-x 1 |
delete-other-windows | Delete all the windows except this one`. |
delete-windows-on | Delete all windows open to a particular buffer. | |
C-x ^ |
enlarge-window | Make the current window taller. |
shrink-window | Make the current window smaller. | |
C-x } |
enlarge-window-horizontally | Make the window wider. |
C-x { |
shrink-window-horizontally | Make the window less wide. |
M-C-v |
scroll-other-window | Scroll the other window. |
C-x 4 f |
find-file-other-window | Find a file in the other window. |
C-x 4 b |
switch-to-buffer-other-window | Select a buffer in the other window. |
compare-windows | Compare two buffers and show the first difference. |
Special Shell Characters
key | function | Description |
---|---|---|
shell | Start a shell. | |
C-c C-c |
interrupt-shell-subjob | Terminate the current job in a shell. |
C-c C-d |
send-shell-eof | Send the EOF character (Ctrl-d) |
C-c C-u |
kill-shell-input | Erase the current line. |
C-c C-w |
backward-kill-word | Erase the previous word. |
C-c C-z |
stop-shell-subjob | Suspend the current shell job. |
Indentation Commands
key | function | Description |
---|---|---|
C-x |
set-fill-prefix | Prepend each line in paragraph with characters from beginning of the line up to the current cursor column. cancel by doing this in column 1. |
M-C-\ |
indent-region | Indent a region to match the first line in region. |
M-m |
back-to-indentation | Move the cursor to first character in line. |
M-C-o |
split-line | Split line at cursor into two lines... weird. |
fill-individual-paragraphs | Reformat indented paragraphs, keep indentation. |
Centering Commands
key | function | Description |
---|---|---|
M-s |
center-line | Center the current line. |
center-paragraph | Center the paragraph that the cursor is on. | |
center-region | Center the currently defined region. |
Macro Commands
key | function | Description |
---|---|---|
C-x ( |
start-kbd-macro | Start a new macro definition. |
C-x ) |
end-kbd-macro | End the current macro definition. |
C-x e |
call-last-kbd-macro | Execute the last defined macro. |
M-(number) C-x e |
call-last-kbd-maco | Do that last macro (number times). |
C-u C-x ( |
stat-kbd-macro | Execute last macro and add to it. |
name-last-kbd-macro | Name the last macro before saving it. | |
insert-last-keyboard-macro | Insert the macro you made into a file. | |
load-file | Load a file with macros in it. | |
C-x q |
kbd-macro-query | Insert a query into a keyboard macro. |
M-C-c |
exit-recursive-edit | Get the hell out of a recursive edit. |
Detail Information Help Commands
key | function | Description |
---|---|---|
C-h a |
command-apropos | What commands work like this...? |
apropos | What functions and variables work like this...? | |
C-h c |
describe-key-briefly | What command does this key sequence do? |
C-h b |
describe-bindings | What are the key bindings for this buffer? |
C-h k |
describe-key | What command does this sequence do, and tell me about it. |
C-h l |
view-lossage | What are the last 100 characters typed? |
C-h w |
where-is | What is the key binding for this? |
C-h f |
describe-function | What does this function do? |
C-h v |
describe-variable | What is this variable? |
C-h m |
describe-mode | Tell me about this mode. |
C-h s |
describe-syntax | What is the syntax table for this buffer? |