Skip to content

Instantly share code, notes, and snippets.

@lsgrep
Created October 1, 2015 04:18
Show Gist options
  • Save lsgrep/bd31d11a96dcf17ddb42 to your computer and use it in GitHub Desktop.
Save lsgrep/bd31d11a96dcf17ddb42 to your computer and use it in GitHub Desktop.
emacs essentials
File Handling Commands
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-w write-file Write the contents of the buffer to a file.
C-z suspend-emacs Suspend emacs.
Cursor Movement Commands
M-a backward-sentence Move back one sentence.
C-x [ backward-page Go back one page.
C-x ] forward-page Go forward one page.
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
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-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
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
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
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
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
C-s isearch-forward Start an incremental search forward.
C-r isearch-backward Starts an incremental search in the reverse direction.
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
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
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
C-x 2 split-window-horizontally Divide the current window horizontally in two.
C-x 5 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
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
C-x set-fill-prefix Prepend each line in paragrph 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
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
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
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?
Repeating Previous Commands
Repeat the most recent command: ‘C-x z’, and again with ‘z’.
See the recent commands (displayed in EmacsLisp): ‘M-x list-command-history’. Rerun a command by hitting ‘x’ on the line containing a command.
RepeatingComplexCommand allows you to choose which previous command as EmacsLisp and even modify it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment