Emacs cheatsheet
Useful manual about running (remote) emacs and working with options, registers and bookmarks
Famous Emacs Users (that are not famous for using Emacs)
DEFINITIONS | |
---|---|
point | cursor position |
mark | beginning of the selected area |
region | selected area; the area between 'mark' and 'point' |
buffer | document/workspace |
font locking | syntax highlighting |
filling | line wrapping |
frame | window |
mode line | status bar |
window | window pane |
KEYS - other way to push them | |
Check the NEW LINES, INDENTATIONS section as well. | |
M-TAB | F11-TAB, ESC-TAB |
C-M-X | C M-X , where X is any key. Sometimes terminal can't recoginze tree keys down together. In such case you should separate C and M. |
TAB | C-i = indent-for-tab-command |
RET | Enter = C-m |
Quote Insert | C-q quotes the next character. Eg, when you need to insert a new line, you |
ESC | C-[ |
DEL | C-? |
FILE Commands | |
C-x C-f | find-file Find a file and read it to screen. Repeatedly typing M-p and M-n will let you browse through the file history. |
C-x C-r | open file in readonly mode |
C-x C-v | find-alternate-file Open a different file and kill current buffer. |
tramp | Tramp It allows you to edit "remote" files as if they were local to your machine, taking care of opening up shells, retrieving and writing data for you, etc. You simply specify remote files using a special syntax in C-x C-f (and near anywhere else Emacs asks you for a filename), e.g.: /ssh:phil@remotehost:records/pizza-toppings.txt. I say "'remote'" in quotes above because Tramp is general enough that you can also use it to edit local files— as another user— via su or sudo e.g.: /sudo::/etc/hosts. |
revert-buffer |
revert buffer to the state written on the disk |
C-x i | insert-file |
C-x C-s | save-buffer |
C-x C-w | write-file Save the current buffer as... |
C-x s | save-some-buffers . Ask whether to save each modified buffer |
C-x C-q | toggle read only mode |
DIRECTORY COMMANDS | |
C-x d | dired . Opens a buffer that lists the directory and allows you to perform operations on the files. There are many features (to many to list here) |
in dired mode | |
+ | dired-create-directory |
d | dired-flag-file-deletion Flags the current file for deletion. |
~ | dired-flag-backup-files . Flags all files ending with ~ for deletion (backup files) |
x | dired-do-flagged-delete Delete all files marked for deletion (lines beginning with a D) |
D | dired-do-delete . Deletes the currently highlighted file(s) |
C | dired-do-copy . Copies the currently highlighted file(s). Prompts for the destination. |
R | dired-do-rename . Renames the currently highlighted file(s). Prompts for the destination. |
% R | dired-do-rename-regex |
m | dired-mark . Mark the current file (marks with a *) |
u | dired-unmark |
* c | dired-change-marks . Changes marks from first prompted letter to second prompted letter (example - * c D SPC - this will clear the deletion flag) |
! | dired-do-shell-command . Execute command on files marked with *. If your command contains a *, the list of marked files will be substituted in place and executed. Otherwise, the command will be played once with each marked file as the last argument. |
g | revert-buffer . Refreshes the current dired directory. |
QUITING | |
C-j | exit-minibuffer = RET - Terminates the minibuffer argument (when in minibuffer). |
C-x C-c | save-buffers-kill-emacs |
C-g | keyboard-quit. If you are in a key request sequence that you can't get out of, this returns you to the main buffer |
C-] | Abort innermost recursive editing level and cancel the command which invoked it (abort-recursive-edit ). |
ESC ESC ESC | keyboard-escape-quit - Either quit or abort, whichever makes sense |
C-x k | kill-buffer |
C-z / C-x C-z | suspend-emacs |
:next n | go to next n buffer |
:args | print opened windows (buffers) and propt for number of window to go to |
MOVEING | |
M-g c | goto-char - go to absolute position (as an integer) from the beginning of the buffer |
M-g TAB | move-to-column |
M-g g, M-? | goto-line |
C-b / C-f | character backward / forward |
M-b / M-f | word backward / forward |
C-p / C-n | line backward / forward |
C-a / C-e | begin / end of line |
M-a / M-e | sentence backward / forward |
M-{ / M-} | paragraph backward / forward |
C-x [ / C-x ] | page backward / forward |
C-M-b / C-M-f | sexp backward / forward |
C-M-a , C-M-home / C-M-e , C-M-end | function backward / forward (beginning-of-defun / end-of-defun ) |
M-< / M-> | beginning / end of buffer |
M-m | back-to-indentation Move (forward or back) to the first nonblank character on the current line |
M-g n, M-g M-n, C-x ` | next-error usefull on external buffer, not only about errors (which compilation result, grep result, advanced search etc...) |
M-g p, M-g M-p | previous-error usefull on external buffer, not only about errors (which compilation result, grep result, advanced search etc...) |
C-M-n / C-M-p | Move forward / backward across one balanced group of parentheses. |
subword-mode | Mode rewires the movement and edit commands to work on CapitalizedWords |
C-x C-n | set-goal-column Set the current horizontal position as a goal for C-n and C-p. Those commands will move to this position in the line moved to rather than trying to keep the same horizontal position. |
from vim | |
[( / ]) | evil-previous-open-paren / evil-next-close-paren |
[[ / ][ | evil-backward-section-begin / evil-forward-section-end |
[] / ]] | evil-backward-section-end / evil-forward-section-begin |
[{ / ]} | evil-previous-open-brace / evil-next-close-brace |
% | viper-exec-mapped-kbd-macro . eg: when cursor on parenthase, go to other matching parenthase |
fastnav is a set of functin to fast navigaten on a buffer. | |
C-f z / Z | fastnav-zap-up-to-char-forward / backward |
C-f s / S | fastnav-jump-to-char-forward / backward |
C-f r / R | fastnav-replace-char-forward / backward |
C-f i / I | fastnav-insert-at-char-forward / backward |
C-f j / J | fastnav-execute-at-char-forward / backward |
C-f k / K | fastnav-delete-char-forward / backward |
C-f m / M | fastnav-mark-to-char-forward / backward |
C-f p / P | fastnav-sprint-forward / backward |
C-f b char | delete-between-pair. It my function to imitate vim ci (change inside) - a function to change the content between char (eg: [, ', ... ) |
Smart Scan will try to infer the symbol your point is on and let you jump to other, identical, symbols elsewhere in your current buffer with a single key stroke. | |
M-n / M-p | smartscan-symbol-go-forward / smartscan-symbol-go-backward |
(C-u) M-' | smartscan-symbol-replace Replaces the symbol at point with another string in the entire buffer. With C-u prefix the scope is limited to the current defun. |
S-EXPRESSIONS | |
An S-expression (sexp for short) is the name for balanced parentheses (and the text they enclose) in Lisp. In Emacs, this useful notion is available in most modes; it's especially useful for editing programming languages. The characters that Emacs recognizes as parens are usually regular parentheses (aka round brackets), square brackets, and braces (aka curly brackets), but it depends on the mode (for some languages, angle brackets may act as parens). But sexps are more than just balanced parens: they're defined recursively. A word that doesn't contain any parens also counts as a sexp. In most programming language modes, quoted strings are sexps (using either single or double quotes, depending on the syntax of the language). The sexp commands move in terms of all these units. These commands may seem confusing at first, but for editing most programming languages they're fantastic. Not only do they move you around quickly and accurately, but they help spot syntax errors while you're editing, because they'll generate an error if your parens or quotes are unbalanced. | |
C-M-b, C-M-left | backward-sexp . Moves backward over the next sexp. If your cursor is just to the right of a left paren, C-M-b will beep, because there's no sexp to the left to move over: you have to move up |
C-M-f, C-M-right | forward-sexp . Moves forward over the next sexp... |
C-M-u, C-M-up | backward-up-list . Move backward up one level of parens |
C-M-d, C-M-down | down-list . Move down one level of parens. E.g., if your cursor is sitting on the return type of a C function declaration, C-M-d moves to the inside of the formal parameter list. |
[n] C-M-k | kill-sexp . Kills the sexp after the cursor. When n - kills nth sexp before the cursor |
backward-kill-sexp |
|
raise-sexp , |
|
C-M-@, C-M-SPC | mark-sexp . Sets the region around the same sexp that C-M-f would move to. |
thinkgatpt - very powerfull library to text manipulation in emacs. | |
paredit | Usefull minor mode to operate on parenthases: cheatsheet |
C-d | easy-kill . Aims to be a drop-in replacement for `kill-ring-save'. Things are: w: word, s: sexp, l: list, f: filename,
d: defun , D: defun-name , e: line , b: buffer-file-nam
|
SCROLLING | |
C-l | recenter . Press again to move the line to the top and again to move it to the bottom |
M-o M-s | center-line , indent line to the centre (horizontally). |
C-v == C-b, M-v == C-d | scroll-up, scroll-down - scroll one screen up / down |
C-x <, C-x > | scroll left / right |
C-u C-l | scorll current line to center of screen |
from evil | |
C-S-y, C-S-e | evil-scroll-line-up - scroll one line up / down (I have bind it to use standard emacs bind for C-y) |
COPY, PASTE (yank), DELETE (kill) | |
delete | |
By deleting emacs usually put the content into kill-ring-save buffer. The standard way in emacs to copy something is to delete it and the undo (or paste it back) | |
DEL; C-d, backspace | delete character backward / forward |
M-DEL, M-d | kill word backward / forward |
M-0 C-k, C-k | kill to begin / end of line |
C-S-backspace == C-a C-k C-k | kill-whole-line |
C-x DEL, M-k | kill sentence backward / forward |
C-w | kill region |
M-z char | zap-to-char kill to next occurrence of char |
clipboard-kill-region | cut selection from Emacs to clipboard |
copy / paste | |
clipboard-kill-ring-save | copy selection from emacs to clipboard |
clipboard-yank | paste from clipboard to emacs. Actually emacs takes clipboard copies to his kill-ring |
M-w | kill-ringa-save - "emacs" copy region |
C-y | paste (yank back) last thing killed. |
y | in normal mode: vimpulse-yank (copy) |
M-y | replace last yank with previous kill |
C-M-y | yank-and-indent - paste last content and indent |
mosue: right-left click | right click to set the mark and the left click to select |
thingopt | |
Thingopt is a great set of utilities to extend emacs copy/paste/delete functionalities around different type of context (using ThingAtPoint) | |
kill-thing, copy-thing, mark-thing, upward-mark-thing - execute command with thing (use tab to get hints about possible things) |
|
C-c d | kill-region-dwim convinient wrapper for kill-region based on thing under the point.
Available arguments:
w - word,
e - sexp
s - symbol
t - sentence
p - paragraph
f - defun
F - filename
l - list
L - up-list
S - string
U - url
P - page
(eg |
C-c w | kill-region-save-dwim convinient wrapper for kill-ring-save based on thing under the point (use TAB to autocomplete for options |
UNDO / REDO | |
C-_, C-/, C-x u, u (from viper) | undo, last by first undo-tree |
M-_, C-?, C-r (from viper) | redo |
C-x u | undo-tree-visualize lub advertised-undo |
C-x r u | undo-tree-save-state-to-register |
C-x r U | undo-tree-restore-state-from-register |
in undo visualizer | |
"up", p, C-p | undo changes |
"down", n, C-n | redo |
"left", b, C-b | undo-tree-visualize-switch-branch-left |
"right", f, C-f | undo-tree-visualize-switch-branch-right |
t | Toggle display of time-stamps |
q, C-q | quit |
, < / . > | scroll left / right |
"page up", "page down" | scroll up, down |
THE MARK AND THE REGION | |
Emacs uses the mark to save your previous position while making jumps (eg word, paragraph..) | |
C-SPC | set-mark-command it will be binded to 'r' vim mark (so we can access it with 'r).
With prefix argument (see below), e.g. C-u C-SPC , jump to the mark, and
set the mark from position popped off the local mark ring (this does not affect
the global mark ring). Use C-x C-@ to jump to a mark popped off the global
mark ring (see `pop-global-mark'). |
C-u C-SPC, C-x SPC (custom) | Cycle through mark ring (jumps back to previous mark position in the current buffer). You can sequentially call this funciton to jump further in the ring |
C-x C-SPC | pop-global-mark Pop off global mark ring and jump to the top location.
(like C-u C-SPC but takes all buffers into account) |
C-x C-x | exchange-point-and-mark . Swaps mark and point (move point to the place before jump). |
M-. | find-tag tagname Find tag (in current tags table) whose name contains tagname. Select the buffer containing the tag's definition, and move point there. The default for tagname is the expression in the buffer around or before point. |
M-* | pop-tag-mark Pop back to where M-. was last invoked. |
M-r | recenter-positions - moves the point between the top, center and bottom (by default) of the visible window but without actually scrolling up or down |
M-@ | mark-word . Sets the region around the next word, or from point to the end of the current word, if you're in the middle of one. |
M-h | mark-paragraph . Sets the region around the current paragraph. |
C-M-@, C-M-SPC | mark-sexp . Sets the region around the same sexp that C-M-f would move to. |
C-M-h | mark-defun . Sets the region around the current defun. |
C-x C-p | mark-page . Sets the region around the current page. |
C-x h | mark-whole-buffer . Sets the region around the entire buffer. |
C-w, S-delete | kill-region . Actuall C-w is overwrited by vimpulse. Kills the region. It goes on the kill ring, of course. |
M-w | kill-ring-save . Saves the region to the kill ring without removing it from the buffer. This is exactly equivalent to typing C-w C-y. |
C-x n n | Narrow buffer to the current region. This makes everythin beside current region invisible. |
C-x n w | Restore buffer after narrowing |
MOVEING ON MARKS, JUMPING | |
CAUTION: vimpuls and emacs registers lives in separate namespace. So we can use the same register letter for marging different things in emacs and vimpulse CAUTION2: emacs mark lives in viper r register |
|
C-u C-SPC | Go to previous mark position |
from viper | |
m [a-zA-Z] | mark current position with letter |
' | vimpulse-goto-mark-and-skip-white |
` | (at tilda) vimpulse-goto-mark |
' [a-z] | go to mark [a-z] within current file |
' r | go to mark emacs "quotemark" - the mark from last emacs move |
' [A-Z] | go to mark [A-Z] within any file |
' [0-9] | go to position where was last exited |
' ' | go to the position before last jump |
' " | go to the position before last editing this file |
' [ | go to the start of previously operated or put text |
' ] | go to the end of previously operated or put text |
' < | go to the start of the previous Visual area |
' > | go to the end of the previous Visual area |
:marks | |
:jumps | |
WORKING WITH REGISTERS | |
Emacs registers are places you can save text or positions for later use. Text saved in a register can be copied into the buffer once or many times; a position saved in a register is used by moving point to that position. Rectangles can also be copied into and out of registers | |
C-x r v / view-register |
list-registers , the second prompts for register and view it |
position / window / frame in registers | |
C-x r SPC r | point-to-register . Save location of point (positin) in register r |
C-x r w / C-x r f | save window / frame configuration to register |
C-x r j | register-to-point == jump-to-register . Both make the same. Jump to the saved location / window / frame configuration saved in registe |
text in registers | |
C-x r s == C-x r x | copy-to-register . Prompts for register letter. Saves text between point and mark (region) in the register. |
C-x r i == C-x r g | insert-register |
RECTANGLE | |
When you must specify a rectangle for a command to work on, you do it by putting the mark at one corner and point at the opposite corner. The rectangle thus specified is called the region-rectangle because it is controlled about the same way the region is controlled. But remember that a given combination of point and mark values can be interpreted either as specifying a region or as specifying a rectangle; it is up to the command that uses them to choose the interpretation. | |
C-x r o, C-x r k | open-rectangle, kill-rectangle . Insert blank space to fill the space of the region-rectangle. The previous contents of the region-rectangle are pushed rightward / Delete the text of the region-rectangle, moving any following text on each line leftward to the left edge of the region-rectangle. To use this method, mark the region of text you wish to indent or outdent, then move the point to the left or right the number of horizontal spaces you want to insert or delete. Then type C-x r o (opens rectangle of whitespace between point and mark.) or C-x r k . Killed rectangles goes to rectangle kill ring. |
C-x r d | delete-rectangle . Deleted rectangle is don't go to delete rectangle ring |
C-x r y | yank-rectangle Inserts last killed rectangle at point. Upper left corner goes to the point position (remember to set it) |
C-x r r | copy-rectangle-to-register After that it asks you for a register (any letter) to copy the rectangle to. Then use C-x g to retrieve register |
C-x r c | Clear the region-rectangle by replacing all of its contents with spaces (clear-rectangle). |
C-x r t string | string-rectangle Replace rectangle contents with string on each line |
:delete-whitespace-rectangle | Delete whitespace in each of the lines on the specified rectangle, starting from the left edge column of the rectangle |
:string-insert-rectangle string | Insert string on each line of the rectangle. |
BOOKMARKS | |
C-x r m | bookmark-set . Prompts for bookmark name (default is buffer name). Saves point in a bookmark. This information is saved even if you close Emacs. |
C-x r b | bookmark-jump . Prompts for bookmark name. Jumpts to point saved in that bookmark |
C-x r l | bookmark-bmenu-list . Lists all saved bookmarks. Typing "j" when on a bookmark jumps to the file. Dired commands are used to delete bookmarks (Type "d" when on file - then "x" to delete bookmark). |
SEARCHING and REPLACING | |
more about searching and repleacing: here Search is not case sensitive, by default. If your search string contains a capital letter, search is automatically case sensitive. To make your search absolutely case-sensitive, you need to set the variable case-fold-search to t or nil. The menu (Options-Case-Insensitive Search) toggles it for you or run toggle-case-fold-search . If the arguments to a replace command are in lower case, it preserves case when it makes a replacement. If upper-case letters are used in the second argument, they remain upper case every time that argument is inserted. If upper-case letters are used in the first argument, the second argument is always substituted exactly as given, with no case conversion. Likewise, if the variable case-replace is set to nil, replacement is done without case conversion. If case-fold-search is set to nil, case is significant in matching occurrences of "foo" to replace; this also inhibits case conversion of the replacement string. specials strings in replacement string:
|
|
C-s, C-S | isearch-forward, isearch-backward . Repeatedly searches forward multiple times. backward search oryginally is C-r, but viper us thisIn Search mode: |
M-s w | isearch-forward-word - "fuzzy-find" matches in the code. It cleverly ignores things like punctuation as it looks for whole words instead. Super-duper Useful. |
M-b C-s C-w .. C-s | Pro tip: search for the word under the point. The combination means: backward-word isearch select word isearch. Good about. |
C-s C-s | Search for most recently searched item |
C-s M-p, C-s M-n | Previous item in search history / Next item in search history |
C-M-s, C-u C-s | isearch-forward-regexp If you type SPC in incremental regexp search, it matches any sequence of whitespace characters, including newlines. If you want to match just a space, type C-q SPC. |
re-search-forward | Nonincremental search for a regexp |
M-p, M-n | isearch-forward-regexp |
replace-string | Unconditional search and replace |
M-% | query-replace - replace with confirmation |
M-C-% | query-replace-regexp |
occure REGEXP | Show all lines in the current buffer containing a match for REGEXP |
imenu item | search for item in file (where item is a entity in current model, eg: function) |
M-x flush-lines RET regexp RET | Delete each line that follows point and contains a match for regexp. |
M-x keep-lines RET regexp RET | Delete each line that follows point and does not contain a match for regexp. |
REGULAR EXPRESSIONS | |
very good manual is at EmacsWiki | |
COMPILE | |
Emacs gives you a lot of the raw power of tools you already know how to use— your compiler, grep, etc. — and then it augments them with super-powers. For example, when you run make using M-x compile , Emacs displays the compiler output in a new window. Emacs highlights compile errors and notes their line numbers. Pressing C-x ` (M-x next-error) will jump directly to the line in your source code which caused the first error; press C-x ` repeatedly to jump to successive errors. (You can also click on the entries in the compilation output buffer.) You can go forwards and backwards through the list of errors using M-g n and M-g p (next-error and previous-error respectively).This facility is general enough that you can use the same keys to jump to line numbers that appear in the output of M-x grep or M-x occur . In short, there is really no reason for you to have to explicitly note filenames and line numbers in program output, because Emacs can jump directly to them for you.More information about "compilation mode". |
|
GREP | |
grep |
Invokes grep and prints results in a new buffer. When you click on a match Emacs opens the correct file and takes you to the matching line. |
lgrep |
interactive, preconfigured grep command, which searches in the current directory |
rgrep |
interactive, preconfigured grep command, which searches in the current directory tree. rgrep understend version control system so it can avoid searching its control directories |
grep-buffers |
Function from grep-buffers.el. It make preconfigured grep on buffers associated with some files in current window. |
M-g in dired+ mode | diredp-do-grep , lets you 'grep' only the marked files in a Dired buffer - or the next N files if you use a prefix arg. This applies even if the buffer contains inserted subdirectories: all marked files are grepped. Or right-click ('mouse-3') and choose Grep from the menu to grep just the file you clicked. |
grep-a-lot.el grep-a-lot is a package which keep grep buffers (instead overwrting them), so we can easily go to the previous grep searches. |
|
M-g ] / M-g [ | Go to next / previous search results buffer, restore its current search context |
M-g - | Pop to previous search results buffer (kills top search results buffer) |
M-g _ | Clear the search results stack (kills all grep-a-lot buffers!) |
M-g = | Restore buffer and position where current search started |
ADDITIONAL MODIFICATORS AND SEARCHERS | |
M-n, M-p | going to next/ previous history content releated to command (eg, C-x C-f M-p set in minibufer previous enered filename to find ) |
ABBREV | |
Abbrevs are use to automaticly expand shortcuts from expressions. We can Map some sequence to other sequence, to function, and to skeleton | |
C-x a g | add-global-abbrev. After adding some abbrevations we can save current abbrevs to file |
C-x a l | add-local-abbrev |
C-x a i g, C-x a - | inverse-add-global-abbrev . Adds abbrev for this (previous) abbrev (string) |
C-x a i l | inverse-add-local-abbrev . Adds abbrev for this (previous) abbrev (string) for local buffer only |
C-x a e | expand-abbrev . Explicitly expand previous string (abbrev) |
edit-abbrevs |
|
abbrev-mode |
when enabled expanding are done automatcly from previous word |
unexpand-abbrev |
Undo the last word abbreviation |
others command | list-abbrevs, kill-all-abbrevs |
M-' | abbrev-prefix-mark . For example: when we have abbrevs: em=ElektroMech, and bn=BioMech; then when we put: emM-'bn we get ElektroMechBioMech |
AUTOCOMPLETE | |
TAB | complete-at-point. Now I'm using company-mode! |
C-TAB | company-complete initiates completion manually.
Caution: C-TAB doesn't work in tty.
When the completion candidates are shown, press:
|
C-c TAB | company-filter-candidates |
M-/ | dabbrev-expand Expands to the most recent, preceding word for which this is a prefix.
If no suitable preceding word is found, words following point are
considered. If still no suitable word is found, then look in the
buffers accepted by the function... |
M-SPC | hippie-expand Try to expand text before point, using multiple methods.
The expansion functions in `hippie-expand-try-functions-list'. |
M-[ [ | my-ido-hippie-expand - like hippie-expand,
but uses ido menu for completition |
M-[ ] | comint-dynamic-complete-filename |
f11 TAB, C-M-i | complete-symbol Perform completion on the text around point.
The completion method is determined by `completion-at-point-functions'
(it uses completion-at-point function) |
C-c y | autocomplete for yasnippets |
IDO - interactive do - switches between buffers and opens files and
directories with a minimum of keystrokes. Check [wiki](http://emacswiki.org/emacs/InteractivelyDoThings)
for interesting key strokes. The documentation for functions are available in C-h f ido-find-file RET .
Examples after running C-x C-f (ido-find-file )
|
|
C-SPC (C-@) | after typing some characters appearing in the buffer/file name(say .cpp),
type C-SPC (C-@) . Then Continue as normal with a list containing only the filtered names |
M-p / M-n | (or M-UP and M-DOWN) to change to previous/next directories from the history |
M-s | search for a file matching your input |
M-k | remove the current directory from the history |
Dynamic abbrevs looks at the "word" to the left of point and try to expand that word by looking for text in the current buffer, and if not found there, in all open buffers (e.g. /usr/share/dict/words) :) | |
M-/ | dabbrev-expand expands to the most recent preceding word |
C-M-/, M-? | dabbrev-completion - looks in whole buffer, not preceding |
M-SPC | hippie-expand helpful function which goes throught hippie-expand-try-functions-list and shows completitions. It is Omnicompletion in VIM. |
M-[ [ | my-ido-hippie-expand hippie expand with ido presentation |
M-[ ] | complete filename |
M-TAB, F11-TAB, ESC-TAB, C-\ TAB |
completition for programming mode |
C-RET | nxml-complete |
Imenu produces menus for accessing locations in documents, typically in the current buffer. You can access the locations using an ordinary menu (menu bar or other) or using minibuffer completion.
A typical use of Imenu shows a menu-bar menu that is an index or table of contents for the current buffer. For a source-code buffer it is typical to index definitions of functions, variables, and so on. In my configuration imenu is open by default throught |
|
C-mouse3 | opens imenubar |
C-c m | idomenu switch to a buffer-local tag from Imenu via Ido. |
UNICODE codes, NEW LINE | |
C-q char | quoted-insert insert the next character char literally. Eg: C-q C-m will insert ^M |
^M | ascii = 13 = \r, new line on Mac |
^J | ascii = 10 = \n, new line on UNIX |
^M^J | new line on Windows |
\u013 | typing unicode character |
^I | Tab character |
C-S-u | prefix key to enter to my-unicode-keymap which groups some predefined unicode character. To gets some of this type: C-S-u char where char is:
|
C-x RET c | universla-coding-system-argument . Execute an I/O command using the specified coding-system |
C-x RET f | set-buffer-file-coding-system converts coding page of the file, and line ending from different OS, with value of "unix", "mac", "dos", "undecided-unix"To convert dos new lines to linux press: M-x set-buffer-file-coding-system RET unix and M-x replace-regexp C-q C-m $ More on http://xahlee.org/emacs/emacs_line_ending_char.html |
C-x RET r | revert-buffer-with-coding-system - reload current buffer using specified coding system |
C-\ | toggle-input-method - Enable or disable multilingual text input method for the current buffer |
set-input-method |
C-x RET C-\ "input_method_name" RET - change input mehod. Some input method examples:
|
C-x 8 RET | ucs-insert ask for unicode character and isnsert it |
C-x 8 + ['""`_] "letter" | insert unicode char based on punctacion mark (',`,...) and letter.
Eg: C-x 8 _ a gives ªMore about C-x 8 command family: http://xahlee.org/emacs/emacs_n_unicode.html |
C-h v buffer-file-coding-system | describe-value, which newline convention is used by emacs for the current file |
describe-char | quickly find out what ASCII char is |
help functions: | menu -> options -> Mule -> set coding system |
NEW LINES, INDENTATIONS | |
M-RET | auto-indent-key-for-end-of-line-then-newline |
C-j | newline-and-indent |
M-^ | delete-indentation == join-line Merge two lines |
C-c >, C-c < | shift left, right in programming language mode |
<<, >> | vimpulse-shift-left, vimpulse-shift-right |
indetn-according-to-mode | indent line in proper way for current major mode |
C-M-\ | indent-region reindent several lines, eg: C-x h M-C-\ (reindent whole file) |
whitespace-mode | oznacza spacje, taby, trailing spacje/taby |
C-o | Insert a line break, leaving the point before the break. Only in emacs mode in vimpulse is vimpulse-jump-backward |
C-M-o | split-line Split line at point; text on the line after point becomes a new line indented to the same column that it now starts in |
C-i | The TAB key ;) |
C-x TAB, C-x C-i | indent-rigidly Rigidly indents the region by as many characters (columns) as you provide as a numeric argument (default is 1 column). To shift left use negative number |
M-i | tab-to-tab-stop Indent from point to the next prespecified tab stop column |
indent-relative Indent from point to the next prespecified tab stop column. It is default in text-mode for TAB |
|
:untabify, :tabify | mark the whole buffer using C-x h and use M-x untabify |
C-x a r | align-regexp Select a region you want to align text within, M-x align-regexp , and type a regexp representing the alignment delimiter. |
C-x a R | align Select a code and align using predefined rules |
C-x C-o | delete-blank-lines |
delete-trailing-whitespace | |
M-\ | Delete the spaces and tabs around the point. |
SHORTCUTS | |
C-h b | List all shortcuts |
C-x C-h | List shortcuts with prefix C-x |
C-c C-h | List user-defined shortcuts |
SPECIALS | |
stop terminal iterpreting M- commands | In 'Keyboard Shortcuts' uncheck the 'Enable menu access keys (such as Alt+F to open the File menu)' |
set-variable | set variable by keyboard, type |
C-x = | what-current-position - shows info about current position |
M-= | Display the number of lines, words, and characters that are present in the region (count-words-region). |
count-words | Display the number of lines, words, and characters that are present in the buffer. |
C-u NUM, C-NUM, M-NUM | repeat next commnad NUM of times. Eg: delete next char 10 times: C-1 C-0 C-d |
C--, M-- | negative-argument inverts the operation the command would otherwise carry out. Eg: M-- M-c will capitalize the last word you just typed |
eshell |
opens eshell terminal. It is not a bash/zsh on top of emacs, but separate shell written in elisp, which works great with emacs ecosystem |
shell |
opens shell terminal. bash/zsh on top of emacs, which works great with emacs ecosystem |
term, ansi-term |
shell emulator (zsh/bash on top of emacs). ansi-term will render colors |
man |
Displays man pages. |
customize-group |
configuration on some group |
C-u M-x apropos-variable RET -mode-map$ RET | show all mode hooks known to Emacs, including their docstring description. If you don’t see your mode it may be because Emacs hasn’t loaded it outright or it lacks the autoload keyword. |
C-x z | Repeat last command. Read more at emacs repeating. |
C-x M-:, C-x M-ESC, C-x ESC ESC | Repeat a complex command - typed by M-x some-command. Proposed: bind to C-. |
sorting | sort-lines, sort-paragraphs |
sort-fields, sort-numeric-fileds, sort-regexp-fields |
sort lines by specified field in line as a additional argument. The fields are a gruop of characters divided by whitespace |
transpose-.. |
transpose function family, eg: transpose-word, transpose-char |
M-t | transpose-word |
C-t | transpose-chars |
C-x C-t | transpose-lines |
C-S-up / down | (local function).move-line-up / down . Current line is transposed up / down. |
M-c | capitalize-wrod |
M-u; M-l | uppcase-word, downcase-word |
C-x C-l, C-x C-u | downcase-region, uppcase-region . Convert the entire region to lowercase / uppercase. This command is disabled by default. |
delete-trailing-whitespace |
|
how-may RET char |
count char in buffer, eg how-many RET \< count words in buffer |
C-x l | prints in minibufer the number of lines in buffer |
C-u M-= | counts lines/words/characters in the entire buffer |
find-library |
|
load-file |
load with makro, configuration eg: M-x load-file RET ~/.emacs RET |
byte-compile-file |
Other possibilities: emacs -batch -f batch-byte-compile filename.el Directory names may also be given as arguments. batch-byte-compile uses all the remaining command-line arguments as file or directory names, then kills the Emacs process.byte-recompile-directory is invoked (in effect) on each such directory. C-u 0 M-x byte-recompile-directory will compile all the .el files in the directory and in all subdirectories below without checking if file have a .elc counterpart (C-u 0). More here |
desktop-save | save the desktop (buffers, their file names, major modes, buffer positions ...) state (session). Use desktop-revert to revert session.If you turn on desktop-save-mode in your init file, then when Emacs starts, it looks for a saved desktop in the current directory. (More precisely, it looks in the directories specified by desktop-path, and uses the first desktop it finds.). More.
|
M-! | shell-command . Executes a command and displays the output in a new buffer. |
M-| | shell-command-on-region . Executes a command, piping in the current region as input; displays the output in a new buffer. |
calendar, calculator, phases-fo-moon, tetris, hanoi, doctor |
|
F* KEY MAPS | |
F1 | speedbar. Use sr-speedbar (separate package) to open speedbar in current frame. |
F5 / S-F5 | paste current buffer / directory name |
C-S-F5 | paste current file name (with directory name) |
M-F5 | make-hippie-expand-function |
F9 | next-error |
S-F9 | previous-error |
F10 | flycheck-show-error-at-point print error/warning information |
S-F10 | menu-bar-open |
SPELL CHECK | |
Default programm to make spelling in emacs is ispell. But the emacs wrapperr can be configured using other spell check programs like aspell, hunspell. For more info look at EmacsWiki documment | |
ispell-* |
it is all family for spelling commands |
flyspell-mode |
minor mode to make on the fly spell checking |
MENU BAR | |
M-~ | open menubar |
COMMENTS | |
C-x ; | Set the comment column |
M-; | comment-dwim Insert or realign comment on current line; alternatively, comment or uncomment the region |
C-u M-; | comment-kill |
C-x ; | comment-set-column |
M-j | comment-indent-new-line Like <RET> followed by inserting and aligning a comment |
C-c C-c | in c like mode - Add or remove comment delimiters on all the lines in the region. |
WINDOWS | |
C-x 1, C-x 0 | only current window, close current window |
C-x 2, C-x 3 | split window vertical/horizontal |
C-x o | change window |
C-x + | balance-windows |
C-x ^ | enlarge-window |
C-x { / C-x } | shrink-window-horizontally enlarge-window-horizontally . Combine with C-u num to shrink/enlarge by different value |
shrink-window |
Make the current window smaller. |
winner-mode |
global minor mode to remember windows and buffers content. It helps to udno, and redo changes in window configuration with key commands: C-c left, C-c right |
BUFFERS | |
C-x k | kill buffer |
C-x b, C-x C-b | change buffer, open buffer interactive list |
C-left, C-rigth | next / previous buffer |
KEYBOARD MACROS | |
In Emacs, if you know how to perform some task on the keyboard, then it takes just a couple of extra keystrokes to repeat it as many times as you like— no programming needed! To record a macro, press F3, do whatever it is you want to be recorded, and press F4. Then press F4 F4 F4 ... to replay as many times as you like. If your macro does some sort of transformation on a single line and moves to the next line, then M-0 F4 causes Emacs to do that transformation on all lines until it has reached the last line Counters let you insert a different number every time a macro is run. Useful for, among other things, making consecutively (or non-consecutively!) numbered lists. More information about macros |
|
C-x (, F3 | begin recording |
C-x ), F4 | end recording |
C-x e, F4 (after end recording) | execute macro, eg C-u 50 C-x e - execute the macro 50 times |
name-last-kbd-macro |
Name the last macro before saving it. |
insert-last-keyboard-macro |
Insert the macro you made into a file. |
C-x q | kbd-macro-query . Insert a query into a keyboard macro. |
DOCUMENTATION, FUNCTION ARGUMENTS Discovery | |
eldoc-mode |
mode which prints functions parametetrs in minibuffer. off by default |
info... |
einfo docummentation for emacs and other info files installed in system (througth install-info) like python ... |
C-c f | python-describe-symbol prints some documentation |
C-h i d m [menu item] | go to menu item in help InfoMode |
apropos |
allows you to find out which functions in emacs match a regular expression. Eg: M-x apropos RET hook$\|functions$ RET list of Hooks all finish with either hook or functions |
SKELETONS | |
C-h i d m Autotype RET | explains skeletons |
describe-function skeleton-insert |
useful info about skeleton |
FILL MODE | |
auto-fill-mode |
function, toggle fill-mode |
fci-mode |
Fill Column Indicator mode. Graphically indicate the location of the fill column by drawing a thin line |
wrap-to-fill-column-mode | Activates auto wrap mode. |
fill-region |
Fills, i.e., justifies with a ragged right margin, all the paragraphs within the region. |
M-q | fill-paragraph-or-region indents the current paragraph or region based on the first line of the paragraph. It will also wrap lines |
C-x f | set column for wrap-to-fill-column-mode |
C-u 20 C-x f | set-fill-prefix set the fill prefix to 20 (enter in whatever on earth you want to be the prefix for your lines) |
M-q | will re-"soft newline" the current paragraph, inserting the fill character as prefix. i.e. just type the comment as all one paragraph, then ESC-q will re-format, leading each line with the right number of tabs and the comment sign |
HIDESHOW MODE | |
Hideshow is an build in emacs minor mode which hides and shows blocks of text. In particular, it hides balanced-expression code blocks and multi-line comment blocks.
Additionaly there is hideshowvis minor mode and hideshow-org minor mode.
More information about key bindings are in emacs menu. |
|
z c, C-c @ C-h (in edit mode) | when placed in a block will hide it |
OUTLINE, ORG MODE | |
Outline is an build in emacs major and minor mode which hides and shows different header levels and the plain text. It is like Wiki editing tool to move around headings and fold them. The standard heading is marked by (*), and sub headings by more asterisk marks (**, ***...) The NEWS file can bee use to experiment/watch outline mode (to get NEWS file type: C-h n) more about outline mode on wiki pages
OutlineMinorMode can be used in other main modes to navigate and hide in the file
AllOut is also emacs build in minor mode which extends default outline mode. AllOut outline mode provides extensive outline formatting and manipulation beyond standard emacs outline mode. It provides for structured editing of outlines, as well as navigation and exposure. It also provides for syntax-sensitive text like programming languages. (For an example, see the allout code itself, which is organized in an allout outline framework.).
Org-mode is part of Emacs 22 and 23. |
|
outline-minor-mode |
Enable outline minor mode |
C-c C-a | show all content |
C-c C-t | show only the headings |
C-c C-s | show subtree at cursor location |
C-c C-d | hide subtree at cursor location |
NXML- emacs related commands | |
C-M-n, C-M-p | nxml-forward-element, nxml-backward-element |
C-M-u, C-M-d | nxml-backward-up-element, nxml-down-element |
: |
nxml-forward-balanced-item this is equivalent of 'forward-sexp' for XMLnxml-backward-balanced-item this is equivalent of 'backward-sexp' for XML
|
nxml-back-to-section-start |
|
C-c C-n, C-c C-n | rng-next-errorm rng-previous-error |
C-RET | nxml-complete help complete tag and attributes names |
C-c C-f | nxml-finish-element insert an end tag matching the nearest start tag earlier in the buffer |
C-c C-b | nxml-balanced-close-start-tag-block can be run instead of writing the ">" in the start tag. This will close the start tag, place the point indented on the next line, and insert the end tag on the line below the point. |
C-c C-i, C-c TAB | nxml-balanced-close-start-tag-inline can be run instead of writing the ">" in the start tag. It writes the end tag right of the point. |
NXHTML- emacs related commands | |
nxhtml is a HTML major mode for emacs based on NXML. It contains great N-Back game which can be run by n-back-game
|
|
web-mode | |
web-mode emacs mode for HTML/CSS/Templates/JS. It provides:
|
|
C-c C-n | Navigate to the begin/end of element |
C-c C-f | fold paragraph / code |
C-c C-s | snippet insertion (auto indented, aware of text selection) |
C-c C-m | clever selection and expansion |
C-c C-w | suspicious whitespaces detection |
M-q | filling |
C-c C-d | show tag mismatch |
C-c C-i | indent entire buffer |
C-c C-r | replace HTML entities |
C-c / | HTML element close |
C-c C-w | suspicious whitespaces detection |
C-c C-w | suspicious whitespaces detection |
BROWSE HTML, W3M | |
C-x w, C-c C-v, C-x m | browse-url-of-buffer the second only in html-mode, third in dired mode |
C-x m | browse-url-at-point opens default (emacs, defined by browse-url-browse-function ) www browser at url at the point |
C-c m | browse-url-xdg-open opens default (system wide) www browser at url at the point |
u | w3m-view-parent-page if browsing a file, then w3m opesn special dired mode |
browse functions | browse-url, browse-url-of-file, browse-url-of-buffer |
w3m functions | w3m-browse-url, w3m-antenna, w3m-antenna-add-current-url, w3m-goto-url, w3m-next-buffer, w3m-switch-buffer, |
copy-url-at-point | my function. Copy url at point to kill-ring |
VERSION CONTROL | |
Emacs helps you manipulate and edit files stored in version control. Emacs supports CVS, Subversion, bzr, git, hg, sccs, arch, monotone and other systems, but it offers a uniform interface, called VC (- Version Control), regardless of the version control system you are using. Emacs automatically detects when a file you're editing is under version control, and displays something like this in the mode line: CVS-1.14 to indicate the version control system in use, and the current version. The easiest way to operate on revision is to use *vc-dir* which opens version status buffer. Then go to emacs mode (if you are in evil) and type ? to open a help. You can enter the command throught status buffer or directly from versioned file. Most of the commands are prefixed with For git there is a git.el plugin shipped with git system package. It is a frontend for vc with git friendly commands. To use it just Also take a look at how to integrate git with ediff for diftool and mergetool |
|
C-x v d | show repository status buffer (directory). It is the eases way to opearate on repository. |
+ | vc-update - make an update (like git pull) |
= | vc-diff for the file under the cursor. |
v | vc-next-action - perform the next logical control operation on file. When commit you can close the msg window with C-c C-c |
? | help |
S | searches the marked files |
Q | does a query replace on the marked files |
C-x v c | |
C-x v u | vc-revert-buffer |
C-x v g | vc-annotate - *blame*. Show when each line in a tracked file was added and by whom. On any line you can press L to view the log message for that commit or D to view the associated diff. |
C-s v l | Displays a log of previous changes to the file. When the cursor is on a particular log entry, you can press d to view the diff associated with that change or f to view that version of the file. |
vc-resolve-conflicts | Pop up an ediff-merge session on a file with conflict markers |
(info "(emacs)Version Control") |
|
VIPER - emacs related commands | |
more keys and commnads here vim-emacs cheatsheet |
|
C-\ | 1Meta character (when unable to push meta). Note: Emacs binds C-\ to a function that offers to change the keyboard input method in the multilingual environment. Viper overrides this binding. However, it is still possible to switch the input method by typing \ C-\ in the Vi command state and C-z \ C-\ in the Insert state. Or you can use the MULE menu on the menubar. |
C-z | In Insert and Replace states, prepare Viper to accept the next command and execute it as if Viper was in Vi state. Then return to Insert state. In Vi state, switch to Emacs state; in Emacs state, switch to Vi state.
Changing viper-toggle-key in order to use C-z as undo (setq viper-toggle-key "\C-q") (define-key viper-vi-global-user-map "\C-z" 'undo) (set-global-key "\C-z" 'undo) |
C-c \ | Switches to Vi state for the duration of a single command. Then goes back to the original Viper state. |
. | viper-repeat . repeat last operation |
C-o | vimpulse-jump-backward . Go to older position in jump list. To go the other way, press TAB. |
C-i = TAB | vimpulse-jump-forward . Go to newer position in jump list. To go the other way, press C-o . |
C-w (h|j|k|l) | windowmove-(left|down|up|right) |
ge | vimpulse-end-of-previous-word |
gd | vimpulse-goto-definition . Go to definition or first occurrence of symbol under cursor. |
gq lub gw | vimpulse-fill . Fill text |
gu | vimpulse-downcase . Convert text to lower case. |
gU | vimpulse-uppcase . Convert text to upper case. |
g~ | vimpulse-invert-case |
g? | command vimpulse-rot13 |
+ | viper-next-line-at-bol . Next line at beginning of line. If point is on a widget or a button, simulate clicking on that widget/button. |
- | viper-previous-line-at-bol . Previous line at beginning of line. |
" | in normal mode vimpulse-read-register |
Modal keybinding functions: vimpulse-map, vimpulse-imap, vimpulse-vmap, vimpulse-omap, vimpulse-global-set-key, vimpulse-local-set-key, vimpulse-define-key |
|
SQL | |
Good introduction is the [Setup Emacs as an SQL Database client](https://truongtx.me/2014/08/23/setup-emacs-as-an-sql-database-client/) blog post. | |
C-c C-r | sql-send-region |
C-c M-r / C-c M-s | comint-previous-matching-input-from-input / comint-next-matching-input-from-input
- traverse through the input history. |
PYTHON | |
Emacs has a great support for Python environemt. There are two python modes: build-in python.el (which I prefer as it is internally supported by emacs, which also merges https://github.com/fgallina/python.el since Emacs 24.2), and python-mode.el developed by python community. Althought two python modes there are two python setup for emacs:
|
|
GO | |
There is outstanding go-mode major Emacs mode. It is shipped with standard Go package. The main repository is the one linked before, but there is other repository, which is provided by main maintainer of this mode: go-mode.
go-mode integrates greatly with other tools. Better description you can find at Writing go in emacs post and its continuation. There is also support for simple syntax checker using gofmt tool. More about this on Emacs on fly syntax checking for Go. Go Oracle. Some details: configure emacs errcheck checks that you checked errors. go-direx prints your project structure in direx window. go-stacktracer mode for go shell window - allows to jump over go stack traces easily. gorename is a new tool for automatic and sound renaming of Go identifiers.
It reports all declaration and reference conflicts so that, given a well-typed Go program as input, it will either report an informative error, or transform the program to another well-typed and semantically equivalent* Go program.
go get -u -v golang.org/x/tools/cmd/... honnef.co/go/tools/... github.com/mdempsky/gocode github.com/jstemmer/gotags github.com/rogpeppe/godef golang.org/x/tools/cmd/guru github.com/derekparker/delve/cmd/dlv github.com/lukehoban/go-outline
|
|
C-c C-a | go-import-add , prefix with C-u to make an alias for package |
C-c C-d | godef-describe describe symbol at the point |
C-c C-j | godef-jump jump to the definition of a symbol at the point |
HASKELL | |
- Thats it!. | |
haskell-navigate-imports | jump to your import list |
C-c C-. | haskell-mode-format-imports |
haskell-sort-imports | haskell-sort-imports |
autoformatting | https://github.com/haskell/haskell-mode/wiki/Autoformatting Check also :align and :align-regexp |
C-c C-c | haskell-compile |
C-c t | hdevtools/show-type-info |
Clojure | |
C-x C-e | cider-eval-last-expression . Type C-u C-x C-e to print the result of the evaluation after point. |
C-c M-n | cider-repl-set-ns , sets the namespace to the namespace listed at the top of current file |
M-. | cider-find-var - jump to the source code of symbol under the point |
M-, | cider-pop-back - return to original buffer and position |
C-c C-d C-a | cider-apropos , search for arbitrary text across function names and documentation |
ROPE | |
Rope and Ropemacs Rope is a general (non-emacs specific) Python IDE library. It has awesome support for multiple refactoring methods and code introspection. Inside Emacs, this gives us:
|
|
additional keys not available in menu | |
M-/, C-c r a / | rope-code-assist |
C-c g, C-c r a g | rope-goto-definition |
C-c d, C-c r a d | rope-show-doc |
C-c f, C-c r a f | rope-find-occurences |
M-?, C-c r a ? | rope-lucky-assist |
C-c r a j | rope-jump-to-global |
C-c r a c | rope-show-calltip |
rope-autoimport | |
rope-generate-autoimport-cache | |
FLYCHECK | |
“flymake done right”. Flycheck provides on-the-fly syntax checking for GNU Emacs 24. Flycheck simplifies configuration and adding checkers for Emacs. Adding new checker is as simply as defining short configuration variable. Instead of Flymake, which performs checking based on file-name pattern, Flycheck provides major-mode based checkers. For most popular major-mode Flycheck already provides checker setups. Flycheck works by running syntax check tool (the compiler for C++ files, perl for perl files, pylint for python etc.) in the background, passing it a temporary copy of the current buffer and parses the output for known error/warning message patterns. More info about Flycheck usage on project site If you can't use Emacs >= 24, then you can choose Flymake instead Flycheck. If you have a mode that flymake does not support (and you can’t/won’t add flymake support for it), then you can use lmcompile.el/linemark.el from the CEDET tools. more |
|
flycheck-describe-checker | Describe given checker with a command it uses to perform syntax checking |
flycheck-select-checker | select appropriate checker |
F10 | flycheck-show-error-at-point print error/warning information |
ECB | |
ECB stands for "Emacs Code Browser". While Emacs already has good editing support for many modes, its browsing support is somewhat lacking. That's where ECB comes in: it displays a number of informational windows that allow for easy source code navigation and overview, like:
|