Skip to content

Latest commit

 

History

History
1015 lines (881 loc) · 64.3 KB

emacs_user-manual.org

File metadata and controls

1015 lines (881 loc) · 64.3 KB

Emacs User Manual

📝 NOTE: (for Beginners) I personally prefer Emacs built-in TUTORIAL first, which is very well documented and easy to understand. In this documentation I’ll use Ctrl as C, Alt as M, Shift as S, Space as SPC and BackSpace as BS.

This documentation is still in progress, so you better stick to it. cheers! 🍻

Table of Contents

Basics of Emacs

Moving Around in the Buffer

General Shortcuts

KeystrokesCommand NameAction
C-nnext-linemove to next line (Down)
C-pprevious-linemove to previous line (Up)
C-fforward-charmove forward one char (Right)
C-bbackward-charmove backward one char (Left)
M-fforward-wordmove one forward
M-bbackward-wordmove one word backward
C-eend-of-linemove to end of line
C-abeginning-of-linemove to beginning of line
M-eforward-sentencemove forward one sentence
M-abackwards-sentencemove backwards one sentence
M-}forward-paragraphmove forward one paragraph
M-{backwards-paragraphmove backwards one paragraph
C-vscroll-upmove forward one screen
M-vscroll-downmove backward one screen
C-M-vscroll-other-windowScroll next window downward (when opened 2 >= windows)
C-M-S-vscroll-other-windowScroll next window upward
C-x [forward-pagemove forward one page
C-x ]backward-pagemove backward one page
M-<beginning-of-buffermove to beginning of file
M->end-of-buffermove to end of file
C-lrecenter-top-bottomScroll current line to center, top, bottom
M-C-lreposition-windowmake the current definition and/or comment visible.
M-rreposition-pointwithout moving the text on the screen, reposition point
M-(n)digit-argumentrepeat the next command (N) times
C-u (n)universal-argumentrepeat the next command (N) times
M--negative-argumentrepeat the next command negative (N) times
M-g cgoto-chargoto char (N) of file
M-g TABmove-to-columnmove point to column in the current line.
M-g M-ggoto-linegoto line (N) of file
C-gkeyboard-quitto cancel a command

Files

KeystrokesCommand NameAction
C-x C-ffind-filefind/create-new file and read it in a new buffer
C-x C-vfind-alternate-fileclose current and open another
C-x C-wwrite-filewrite buffer contents (save buffer as a new file)
C-x iinset-fileinsert file at cursor position
C-x l-Report number of lines on current page.
C-x C-ssave-buffersave current buffer in visited file if modified
C-x ssave-some-bufferprompt to save any buffer that has been modified
C-u C-x s-save any buffer that has been modified with no questions
C-x C-csave-buffers-kill-emacsOffer to save each buffer, then kill Emacs
C-u C-x C-c-force save buffers and quit
C-x C-f M-popen previously saved or opened
C-x d M-p RET Rrename previously saved or opened
C-x C-qread-only-modetoggle as read only
M-~not-modifiedmark buffer as unmodified
C-u M-~-mark buffer as modified
(none)kill-emacsforce quit
C-zsuspend-emacsSuspend Emacs temporarily
<insert>overwrite-modetoggle between overwrite mode and insert mode

Asking input on quit

  • save file /home/Document ? (y, n, !, ., q, C-r, C-h)
    KeyDescription
    ySave the specific file
    nDo not save the specific file
    !to Save all of files at once and then Quit
    qQuit immediately without saving
    .Save the specific file and then Quit
    C-rView the specific file
    C-hDisplay help information

If you try to Quit when there are still files that are not Saved, Emacs will ask you to confirm your intentions. You’ll see a message like:

Modified buffer exist; exist anyway?(yes/no)

Modeline

Modeline: Near the bottom of each window is special line, which called Modeline.

CharactersMeaning
--buffer has not been modified
**buffer has been modified
%%read only mode; buffer has not been modified
%*read only mode; buffer has been modified

Minibuffer

Key SequenceAction
M-pprevious input
M-nrecent input
TABcomplete name of buffer, file, symbol
C-isame as previous
M-r <REGEXP> RETsearch previous input backward with REGEXP
M-s <REGEXP> RETsearch for previous input forward with REGEXP
M-r RETsearch previous input backward again
M-s RETsearch for previous input again
C-h eshow recently echoed messages
C-gexit

Search

KeystrokesCommand NameAction
C-sisearch-forwardincremental-search forward
C-risearch-backwardincremental-search backward
C-s C-sisearch-repeat-forwardrepeat previous search
C-r C-risearch-repeat-backwardrepeat previous search backward
C-s C-wisearch-yank-wordstart with the word the cursor
C-s C-yisearch-yank-linestart with the text from cursor
C-s M-yisearch-yank-killstart with the text from kill ring
M-pprevious-search-stringselect PREVIOUS search string
M-nnext-search-stringselect NEXT search string
M-s wisearch-forward-wordforward incremental Word search
M-s w C-risearch-backward-wordbackward incremental Word search
M-C-sisearch-forward-regexpforward incremental REGEXP search
M-C-risearch-backward-regexpbackward incremental REGEXP search
  • Lower-case on searching is: (Case-Insensitive)
  • Upper-case on searching is: (Case-Sensitive)

Search & Replace

KeystrokesCommand NameDescription
M-%Query: search and replace
M-C-%Query: search and replace (REGEXP)
(none)replace-stringNo query: search and replace
(none)replace-regexpNo query: search and replace (REGEXP)
C-x ESC ESCrepeat-complex-commandEdit and re-evaluate last complex command
M-pto see previous
M-nto see next

Regular Expression

Basic character you can use to create a regular expression.

CharacterDescription
(char)any regular character matches itself.
.match any single character except RET and (like ? in file name).
*match zero or more of the preceding char.
+match one or more of the preceding char.
?match exactly zero or more of the preceding char.
^match the beginning of a line.
$match the end of a line.
\<match the beginning of a word.
\>match the end of a word.
\bmatch the beginning or end of a word.
\Bmatch anywhere not at the beginning or end of a word.
\dmatches any single digit(0-9).
\Dmatches any char but a digit.
\`match the beginning of the buffer.
'match the end of the buffer.
\(char)quotes a special character.
[ ]match one of the enclosed characters.
[^ ]match any character that is not enclosed.
\smatch any whitespace character, space, newline, tab, carriage, return, backspace
\Smatches any char except whitespace.
\wmatches any “word” char (upper-lower letters, digit, underscore).
\Wmatches any char but not these (upper-lower letters, digit, underscore).

e.g. search for the characters (Welcome) at the beginning of a line, press M-C-s and type ^Welcome.

  • IMHO the standard way is:
    1. Go to the top of your buffer.
    2. Type C-M-% for query-replace-regexp.
    3. Input ^\s-+ as regular expression and RET. (See explanation below.)
    4. Leave the replacement string empty, i.e., press RET again.
    5. You are prompted by query-replace-regexp in the minibuffer.
    6. Press ! to perform all replacements at once.
  • Explanation of the regular expression:
  1. The caret ^ stands for the beginning of line.
  2. The \s- stands for any character designated as space by the current modes syntax table.
  3. The + stands for one or more contiguous matches.

Mark, region and kill-ring

KeystrokesCommand NameAction
C-@ / C-SPset-mark-commandactivate mark where point is
C-x C-xexchange-point-and-markexchange location
M-hmark-paragraphmove the point to the beginning
C-M-hmark-defunmark the whole function
M-wkill-region-savecopy the region
C-x C-pmark-pagemarks the entire page
C-x hmark-whole-bufferselect the whole buffer
M-@set mark after next worddo not move point
ESC n M-@” ” more than one worduse a prefix argument(n)
C-M-@” ” after current sexpwithout moving point
  • Using set-mark-command to Remember Locations
Key SequenceAction
C-SPC C-SPCPush current position onto mark ring
C-u C-SPCReturn to previous position in the same buffer
C-x C-SPCReturn to previous position, which may or may not be in the same buffer

Block editing

KeystrokesAction
C-x r t(string-rectangle) inserts text at every line in the rectangle
  • C-x C-@ / C-x C-SPC
    • (pop-global-mark) Pop off global mark ring and jump to the top location. The global mark ring is updated automatically

Getting Help

Menu

KeyCommand NameAction
M-`text interaction with drop-down menu
F10same as (M-`)
(none)menu-bar-modetoggle existence of drop-down menu
(none)tool-bar-modetoggle existence of clickable tool bar

Meta Help

The help system is simple. Type C-h (or F1) and follow the directions. If you are a first-time user, type C-h t for TUTORIAL.

KeystrokesCommand NameAction
C-hhelp commandenter into Emacs help system
C-h ?help-for-helpruns the command help-for-help
C-h C-hhelp-for-help-
C-h thelp-with-tutorialstart Emacs TUTORIAL
C-h c <key> RETdescribe-key-brieflywhat is command for KEY
C-h k <key> RETdescribe-keydescribe command for KEY
C-h w <command> RETwhere-iswhere is key binding for COMMAND
C-h mdescribe-modeshow the current buffers modes
C-h odescribe-symboldisplay the full documentation of SYMBOL.
C-h bdescribe-bindingsshow current key bindings
C-x C-h-list bindings starting with C-x (see “key” below)
C-c C-h-list bindings starting with C-c (see “key” below)
C-h aapropos-commandlist commands matching search
C-u C-h a-list commands and functions matching search
C-h f functiondescribe-functiondescribe FUNCTION
M-x M-p C-h f RET-describe last command executed with M-x
C-h v <variable> RETdescribe-variabledescribe and show values for VARIABLE
C-h lview-lossagedisplay last few input keystrokes and the commands run.
C-h xdescribe-commandhelp info for a command (a function available using M-x)
C-h hview-hello-filelists many languages and characters
C-h eview-echo-area-messagesview the log of recent echo-area messages
  • Info help
KeystrokesCommand NameAction
C-h iinfoopen directory of manuals
C-h i m-go to info and SELECT m for menu
C-h r-Emacs info manual
C-h F-Emacs FAQ
C-h C-aabout-emacsdisplay the *About GNU Emacs* buffer
C-h sdescribe-syntaxin the syntax table of BUFFER.
C-h Sinfo-lookup-symbolfind description of symbol in manual

Killing and Deleting

KeystrokesAction
C-ddelete char under cursor
BSdelete previous char
M-z charkill from cursor upto char
M-^join this line to previous and fix up whitespace at join
M-\delete all SPC & TABS around point (either side of point)
M-SPCdelete all SPC & TABS around point, leaving one space.
M-ddelete next word
M-BSdelete previous word
C-kdelete from the cursor to end-of-line
M-kdelete next sentence
C-M-kkill the sexp (balanced expression) following point.
C-S-BSdelete entire line the point is on
C-x BSdelete previous sentence
C-x C-oget rid off all blank line around current line except one
C-yrestore what you’ve deleted (YANK LAST KILL)
C-u C-ycursor at beginning
M-yREPLACE YANKED with PREVIOUS KILL
C-wdelete a marked region
M-wcopy the region (so it can be pasted with C-y)
M-C-wappend next kill to newest kill ring entry

Undo/Redo

KeystrokesCommand NameAction
C-_ or C-/undoUndo some previous changes.
C-g C-_ or C-?undo-redoUndo the last undos, i.e. Redo the last changes
(none)revert-bufferto Undo all-changes made since you last saved the file.

Tweaks

  • Attention: This topic here is only applicable for my personal configuration of GNU Emacs. If you’re using my config than it’s totally fine, go ahead and use as it say’s. 👍🏼
KeystrokesAction
C-c tToggle ON/OFF transparency.
C-c TChange themes, choose your desired one and press Enter
C-F5Toggle (display-line-numbers-mode-relative)
M-(0-5)Change workspace (eyebrowse)
C-`Copy current line
C-h(backward-delete-char), same as using BackSpace in Emacs
C-S-H(kill-whole-line)
C-w(backward-kill-word)
C-q(kill-region)
C-z(undo-only)
C-S-z(undo-tree-redo)
C-!Eshell
M-pprevious-buffer
M-nnext-buffer
M-oother-window
C-.other-window
C-,previous-window
C-S-rrename-file
C-c DDelete-current-file
C-x C-ltoggle-truncate-lines

Advance Editing

KeystrokesAction
M-/(dabbrev-expand) Expand previous word “dynamically”
C-M-osplit line at point
M-mmove to the first nonblank character on the current line
C-M-\Indent several lines to same column
C-x TABShift block of lines rigidly right or left
C-q TABInsert a literal \T
M-i / C-iIndent from point to the next prespecified tab stop column

Emacs-lisp

  • M-x eval-region
  • M-x eval-buffer
  • M-x load-file ~/.emacs.d/init.el
  • M-x revert-buffer

Narrowing

KeysDescription
C-x n nNarrow down to between point and mark (‘narrow-to-region’).
C-x n wWiden to make the entire buffer accessible again (‘widen’).
C-x n pNarrow down to the current page (‘narrow-to-page’).
C-x n dNarrow down to the current defun (‘narrow-to-defun’).

Text conversion and transposition

  • M-l, M-u, M-c: lowercase, uppercase, capitalize first character
  • C-t, M-t, C-M-t, C-x C-t: transpose character, word, expression, line
KeystrokesDescription
M-lchange following word to lowercase
M-uchange following word to uppercase
M-cchange following word initial letter capital
M-- lchange previous word to lowercase
M-- uchange previous word to uppercase
M-- cchange previous word initial letter capital
C-x C-lConvert the region to lower case
C-x C-uConvert the region to upper case
C-tTranspose two adjacent characters and move point forward by one
M-tTranspose two adjacent word
C-M-tTranspose two adjacent expression
C-x C-tTranspose two adjacent consecutive lines
C-u 2 M-z edelete all characters to the 2nd occurrence of e
M-- M-z edelete all characters to the previous occurrence of e
C-u -4 M-z edelete all characters to the 4th previous occurrence of e

Recursive Editing

Let’s say you are in middle of a long search and replace operation, and you happen to notice a different change you want to make. At such a times, it can be inconvenient to stop what you are doing just to make a single change. However, if you wait until your search and replace operation is finished, you may forgot what it was you wanted to change.

Instead you can press C-r. This pauses the search and replace, and put you back into a recursive editing environment. You can now make any change you want. When you are finished, press M-C-c. This will stop recursive editing and return you to the search and replace operation, exactly where you left. Or, C-] (abort-recursive-editing)

Whenever you press C-r, Emacs will put square brackets [ and ] around the name of the mode on your modeline.

Another way to start recursive editing during a search and replace operation is by pressing C-w. This will delete the current matching pattern and then start recursive editing.

KeystrokesDescription
C-]exit recursive edit
C-M-ccancel recursive edit
C-[ C-csame as (C-M-c)
(top-level)cancel all

Deleting Lines and Parts of Lines

Key SequenceAction
C-0 C-kDelete from point to beginning of line
C-S-BSDelete entire line the point is on

Buffers, Windows and Frames

Emacs Buffer

  • The Emacs object containing text
  • Buffer != file: a file can be opened in multiple buffers
  • C-x C-f, C-x C-b, C-x k: open file, switch buffer, kill buffer

Emacs Window

  • The Emacs object showing a buffer
  • Emacs’ window != window in Linux/Windows (Emacs calls it frame)
  • C-x 0, 1, 2, 3: delete, maximize, split horizontally/vertically
  • C-x {, }, ^, _: shrink, enlarge horizontally/vertically
KeystrokesDescription
C-x 0Delete the selected window
C-x 1Delete all windows except selected window
C-x 2split selected window vertically
C-x 3split selected window horizontally
C-x omove cursor to the next(other) window
C-x }make selected window wider
C-x {make selected window narrower
C-x ^make selected window larger
shrink-windowmake selected window smaller
KeystrokesDescription
C-x bDisplay a different buffer in selected window
C-x bCreate a new buffer in selected window
C-x 4 bDisplay a different buffer in next window
C-x C-b oopen a file in other-window from Buffer List
C-x 4 C-osame as(C-x 4 b) but don’t change selected window
C-x C-bDisplay a list of all buffers
C-x kkill (delete) a buffer
C-x 4 C-fread contents of file into next window
C-x 4 fsame as (C-x 4 C-f)
C-x 4 rsame as (C-x 4 C-f), but in read-only mode

Note: Use C-x b for creating a new buffer only when you don’t want to save.

Emacs Frame

KeystrokesAction
C-x 5 2to open a new frame
C-x 5 oto go to another frame
C-x 5 fopen a frame on particular name of file
C-x 5 C-fsame as (C-x 5 f)
C-x 5 bto move to a buffer and put it in a new frame

Repeat Command

KeystrokesCommand NameDescription
C-x zrepeatRepeat most recently executed command.
C-x ESC ESCrepeat-complex-commandEdit and re-evaluate last complex command.
M-pto see previous
M-nto see next

Built-In Programs

You can quit any Emacs build-in-program by pressing q.

Dired Buffer

Using dired as a file manager in Emacs 💪

One of the great things about it is that it also supports all of the abstractions that Emacs does, like TRAMP for accessing remote machines.

C-x d (dired-at-point) - Prompt for directory and open dired there C-x C-j (dired-jump) - to the name of the current file, in dired

Once inside of dired, you can navigate and perform actions with the following:

KeyAction
n / pnext-line/previous-line
RETopen a file or directory
fopen the file
eopen the file
oopen the file in the other window (alongside)
C-opreview file but stay in dired buffer
Xexecute shell command on file
!perform a shell function on the file
&perform a shell function asynchronously on the file
(hide/unhide details for the listing
^go up one directory
+prompt to create a directory
Zcompress or uncompress file at point
grefresh buffer
hdisplay help summery
iinsert the sub-directory at point
jjump to a location in dired
kremove section, work with previous argument(C-u k)
Ccopy the file to a location
Rrename/move the file to a location
Mchmod a file (change permissions)
Ochown a file (change owner)
Gchgrp a file (change group)
qquit/close the dired window
  • Mark/Unmark
KeyDescription
mMark current file/directory, move cursor down
BSUnmark current file/directory, move cursor up
uUnmark not-current file/directory, move cursor down
UUnmark all files/directories
RMove marked file or current file to another directory
Qquery replace marked files
  • Deleting
KeyDescription
dFlag file for Deletion.
xDelete files flagged by (d).
DDelete directly without marking.
  • Writable Dired
KeyDescription
C-x C-qEnter into editable mode from read-only mode
C-c C-cSave and quit editing mode
C-c EscAbort changes and quit editing mode

Regular Expression

In order to mark the items that are matched by the search terms.

  • % and then m

Let’s search for all the files whose ending is .el by entering .el in minibuffer.

Now you can see item has been marked is by the astrict(*) sign on the left side of window.

  • Toggle the mark by pressing: t

It’ll reverse the matching terms. So instead of matching items, it do reverse of selection.

The Info manual

KeystrokesPurpose
[, ]previous/next node
l, rgo back/forward History
n, pprevious/next sibling node
ugoes up one level to a parent node
SPCscroll one screen at a time
TABcycle through cross-references and links
RETopens the active link
mprompts for a menu item name and opens it
qclose the Info Buffer

customize

  • Tools to help you change user options.
CommandsDescription
emacs-init-timerun time of loading user init file
customizemain menu
customize-variablevariable
customize-apropossearch
customize-modemode
global-set-keydefine key binding
local-set-keydefine key binding for current buffer
normal-modereread settings in file local variables
display-timeshow clock, system load and email flag in mode line
display-time-modeturn off
display-time-worldshow times around the world
display-battery-modeshow system power
size-indication-modeshow size in mode line
column-number-modeshow column number in mode line
toggle-indicate-empty-linesshow end of file in fringe
ruler-modeadd a ruler to the current buffer’s window
menu-bar-modetoggle existence of drop-down menu
tool-bar-modetoggle existence of clickable tool bar
scroll-bar-modetoggle scroll bar
toggle-scroll-bartoggle scroll bar in current frame
blink-cursor-modetoggle blinking of cursor
normal-erase-is-backspace-modefix delete and backspace keys

eww

eww: Emacs web browser.

ses

ses: create and edit spreadsheet files.

Calender

  • Calendar and Diary

Shells

KeystrokesCommand NameDescription
M-!shell commandExecute string COMMAND in inferior shell; display output, if any.
M-│shell-command-on-regionExecute string COMMAND in inferior shell with region as input.
M-xshellstart a separate shell in it’s own Buffer.
C-u M-│run shell command in buffer region

e.g. First select the region for formatted then enter into shell by pressing M-|. And then enter command fmt -w 80 to set width and show result on minibuffer.

Enter into shell by: M-x shell. Look at the menu: you have several keys to interact with the shell. Some of them are:

KeyAction
M-p / C-upfetch previous input of command line
M-n / C-downfetch next input of command line
M-rsearch backward a regexp in cmnd history. C-r to cycle
C-c C-xfetch the next subsequent command from the history
C-c .fetch one argument from an old shell command
C-c C-ldisplay the buffer’s history of shell cmnd in another window
C-c rgo to beginning of output
C-c pgo to beginning of previous output group
C-c csend the C-c command to the shell
C-c odelete the output of the last command

eshell

Command History and Prompt Key Bindings

Eshell comes with a feature-rich command history facility. Because Eshell does not use comint-mode it does not have all the history features available to it, but most of the common ones do exist.

KeystrokesAction
M-r / M-ssearch backwards/forwards for a command by regexp
M-p / M-ngoes backwards/forwards in the command history list
C-a / C-emove to the beginning or end of line
C-c C-okills the output of the previous command
C-c M-binserts the printed buffer name at point
C-c M-iinserts the printed process name at point
C-c M-vinserts an environment variable name at point
C-c M-dtoggles between direct input and delayed input (send on RET)
C-c C-p / C-c C-njump to the previous/next cmnd prompt in Eshell
C-c M-r / C-c M-seshell-previous/next-matching-input-from-input
  • Unfortunately, the search-as-you-type history search in M-x shell (bound to M-r) is not implemented in Eshell.

Because I program a lot, I tend to use M-m instead of C-a to move to the beginning of the line. M-m skips indentation and moves to the first non-whitespace char, unlike C-a.

That command does not work in Eshell, for obvious reasons, but you can rebind it to the same key as C-a:

(define-key eshell-mode-map (kbd "M-m") 'eshell-bol)

History Interaction

You can rewrite previous commands found in Eshell’s history. The syntax is similar to what you find in bash, but it’s just a subset of the most common features. It’s probably easier to refer you to the bash info manual for detailed information on how the history interaction works. I’ve included a small table below that describes most of the history syntax Eshell supports.

You may also want to read my article on Shell & Comint Secrets: History commands. Although it concerns comint-mode-derived things, it’s useful to know about anyway.

CharsAction
!!repeats the last command
!lsrepeats the last command beginning with ls
!?lsrepeats the last command containing ls
$_returns the last parameter in the last executed command
!ls:nextract the nth argument from the last cmnd beginning with ls
!ls<tab>using pcomplete, show completion results matches ls
^old^newusing the last command, replaceold with new and run it again
  • Commandline Interaction

Eshell also has some support for bash history modifiers (like !!:s/old/new/) and the bash reference on history interaction would be a good place to brush up on that.

You can use \ to escape newlines and it supports rudimentary multi-line input that way.

Another way of doing multi-line literal strings is with single quotes: begin a single quote and hit enter, and you are free to enter text until the closing quote delimiter is encountered. If you use double quotes Eshell will expand subshell commands and do variable expansion. In this sense it’s quite similar to bash, though without the support for bash heredocs.

emacsclient

An Emacs server creates a special emacs process that listens on a socket for connecting to it. This way the initialisation is already done before you connect to it and all configurations are already loaded. This is the actual “slow” part of emacs. And is a bit similar to starting python, which also needs to load its libraries at start.

With the emacs server running, you can connect to it using the emacsclient program.

alias vim='emacsclient -nw'

What is so cool about the emacs server?

Saving a lot of response time and making working with emacs feel much faster is the obvious advantage. However, there is a much bigger one:

With the emacs server, you can connect to it from the terminal and X Window. Because the emacs server also manages the buffers (“open files” for non-emacs users), you can view the same open file from the terminal or an x window.

Emacs does “chunk-wise” completion of these strings, too? For example, M-x j-p-p-b <tab> completes to M-x json-pretty-print-buffer

SEXPS

KeystrokesCommand NameAction
C-M-fforward-sexpMove forward by s-expression.
C-M-bbackward-sexpMove backward by s-expression.
C-M-ddown-listMove forward down one level of parentheses.
C-M-ubackward-up-listMove backward out of one level of parentheses.
C-M-nforward-listMove forward across one balanced group of parentheses.
C-M-pbackward-listMove backward across one balanced group of parentheses.
C-M-kkill-sexpKill the sexp (balanced expression) following point.
  • Selecting words or sexps without moving the cursor:
KeystrokesAction
C-M-SPC M-wThis does not move the cursor
C-M-SPC C-M-SPC M-wIf you want to select the next two words after point
C-M-SPC C-wKilling next word or sexp
C-M-KKilling next word or sexp

Fold/Unfold Blocks

Fold/Unfold code blocks with hs-minor-mode

Key bindingHideshow modeKey bindingOutline minor mode
C-c @ C-ahs-show-allC-c @ TABoutline-show-children
C-c @ C-chs-toggle-hidingC-c @ C-koutline-show-branches
C-c @ C-dhs-hide-blockC-c @ C-ooutline-hide-other
C-c @ C-ehs-toggle-hidingC-c @ C-qoutline-hide-sub-levels
C-c @ C-hhs-hide-blockC-u n C-c @ C-lHide all blocks n levels below this block
C-c @ C-lhs-hide-level
C-c @ C-shs-show-block
C-c @ C-ths-hide-all
C-c @ ESCPrefix Command
C-c @ C-M-hhs-hide-all
C-c @ C-M-shs-show-all
  • hs-isearch-open
    • Specifies what kind of hidden blocks to open in isearch-mode.

The value should be one of these four symbols.

  • code (open only code blocks)
  • comment (open only comments)
  • t (open both code blocks and comments).
  • nil (open neither code blocks nor comments)
  • hs-special-modes-alist
    • A list of elements, each specifying how to initialize Hideshow variables for one major mode. See the variable’s documentation string for more information.

Bookmark

Note that some commands (especially ones which are liable to move you an unknown or arbitrary distance from your original location) will automatically push to the mark ring so that you can use C-u C-SPC to return afterwards. This includes isearch, so after using C-s to go somewhere, you can easily jump back again.

ShortcutCommand InvokedDescription
C-x r mbookmark-setCreate / set bookmark.
C-x r bbookmark-jumpOpen bookmark.
C-x r lbookmark-bmenu-listList bookmarks.
  • Delete Bookmark
    • go to Bookmark and Select by pressing d than to Delete press x

Register

Specify a prefix on copy/move commands to delete the original.

Key SequenceFunction
C-x r s ρCopy position to register ρ
C-x r j ρJump to the position in register ρ
C-x r s ρCopy/Move region to register ρ
C-x r i ρInsert object in register ρ at point
C-x r r ρCopy/Move rectangle to register ρ
C-x r w ρCopy current frame config to register ρ
C-x r f ρCopy all frame configs to register ρ
C-u N C-x r n ρInsert N into register ρ
C-u I C-x r + ρIncrement register ρ by I

If you’re taking advantage of register functionality in elisp, use some non-conflicting symbol for the name, rather than a char, so that you can’t conflict with interactively-set registers (unless, of course, you want to do that).
The register retains this information until you store something else in it.

If you use (C-x r j) to go to a saved position, but the buffer it was saved from has been killed, (C-x r j) tries to create the buffer again by visiting the same file. Of course, this works only for buffers that were visiting files.

Keyboard Macros

ShortcutCommand InvokedDescription
C-x (kmacro-start-macroDefine keyboard macro (Start recording key strokes)
C-x )kmacro-end-macroEnd keyboard macro definition (Stop and save recording key strokes)
C-x ekmacro-end-and-call-macroPlayback keyboard macro, can just keep pressing e after first press
C-x C-k SPCkmacro-step-edit-macroOpen keyboard macro debugger
C-x C-k eedit-kbd-macroEnter macro editor, (C-c C-c) to finish editing
C-x C-k nkmacro-name-last-macroSave the keyboard macro for later use
insert-kbd-macroInsert a saved macro into the file, in Emacs lisp

Miscellaneous

KeystrokesCommand NameAction
(none)emacs-uptimeshow time since Emacs started
(none)auto-fill-modeturn ON/OFF auto-fill-mode
M-qfill-paragraphfill paragraph at or after point
ESC 1 M-q-justify and Fill paragraph at or after point
(none)fill-regionfill each paragraph in the region
ESC 1 M-xfill-regionjustify and Fill each paragraph in the region
(none)”-“-as-paragraphfill region as one long paragraph
ESC 1 M-x-justify and Fill region as one long paragraph
C-x fset-fill-columnset the fill column value
M-=count-words-regioncount lines, words and characters in the region
C-q charquoted-insertread next input character and insert it

Miscellaneous Text Commands

KeyCommandAction
M-o M-scenter-lineCenter line (n lines with prefix n)
C-M-wappend-next-killAppend next kill
(none)linum-modeTurn on line numbers in left fringe

Commands for Matching Lines

COMMANDALIASACTION
keep-linesdelete-non-matching-linesDelete lines not matching regexp
flush-linesdelete-matching-linesDelete lines matching regexp
how-manycount-matchesCount lines matching regexp
occurlist-matching-linesShow lines matching regexp in another buffer
highlight-lines-matching-regexphi-lock-line-face-bufferHighlight lines matching regexp
multi-occurOccur on multiple buffers
multi-occur-in-matching-buffersOccur on buffers chosen by regexp

Enter Numeric values

Insert integer trough a significant point

  • C-10 C-u 0
    • will give 10 zeros after the point.
  • C-x C-b o
    • open a file in other-window from Buffer List

Spelling Check

Interface To Spell (Ispell) and On The Fly Spell (Flyspell)

ShortcutCommand InvokedDescription
M-$ispell-wordcheck and correct spelling of word under or before the cursor
M-TABcompletion-at-pointcomplete the word before point based on the spelling dictionary
C-M i--
C-c $flyspell-correct-word-before-pointCorrect word before point
M-xispell-buffercheck the current buffer for spelling errors
-ispell-regioncheck a region for spelling errors
-flyspell-modeEnable Fly-spell mode, which highlights all misspelled words
-flyspell-prog-modeEnable Fly-spell mode for comments and strings only
-flyspell-bufferCheck and correct spelling in the buffer

ORG

This topic Org is pretty huge on it’s own. So, I made a separate manual for org-mode and moved everything about org-mode there.
Please, check this out here: 👉🏽 ORG-user-manual.

Conclusion

For more you can go here: Reference Sheet by Aaron Hawley