Reading Assignment: All of Programming Ch36 Emacs
Why emacs or vim?
- Stay In The Zone
- Other productivity enhancing features
- syntax highlighting
- automatic indentation according to the structure of the language
- The ability to interact with the debugger, the compilation/build tools, and revision control system.
- a lot of flexibility
Emacs vocabulary
Buffer
“an open file”
Frame
What you would think of as a “window”
Window
A frame can be divided into several windows, each of which can display a different buffer.
Point
where the text cursor is.
Mark
One location per buffer which, when set by the user, Emacs remembers until changed or cleared by the user. Commands which operate on regions of the buffer typically act on the region between the point and the mark.
C-(key)
C-X
= hold Control
key while pressing x
M-(key)
M-
stands for Meta
ESC
: press, release, hit other keyalt
: hold down while press other key
Kill
Cut(as in cut-and-paste)
Yank
Paste
extended-comman
RET
Return, Enter
Minibuffer
The line below status bar.
For example, when you go to open a file, Emacs prompts you for the file name in the Minibuffer, and you type your answer there.
Major Mode
It defines its current behavior in these ways.
Minor Mode
Provide additional features or change functionality.
For example, a buffer for editing LaTeX source may be in LaTeX major mode, but may have the Flyspell minor mode, to provide spell checking as you type.
Balanced Expression
A region of text which typically has balanced delimiters(parenthesis, braces, etc).
Modeline
The status line at the bottom of the frame, just above the Minibuffer.
Running Emacs
1 | emacs # may call GUI emacs |
Files and Buffers
Command | shortcut |
---|---|
Open (“visit”) file | C-x C-f |
Save current buffer | C-x C-s |
Kill(close) current buffer | C-x k |
Insert contents of another file | C-x i |
Save As [another name] | C-x C-w |
Recover file from autosave information | M-x recover-file |
Revert to last saved copy | M-x revert-buffer |
Quit Emacs | C-x C-c |
Suspend Emacs(to shell) Resume emacs after suspend | C-z fg[at bash prompt] |
C-x C-c
is the way to close emacs, it will prompt you to save unsaved files before exiting.
C-z
is the way to suspend many UNIX programs, including emacs, you can run fg
to bring it back.
Cancel and Undo
Command | Combination |
---|---|
Cancel | C-g |
Undo | C-_ C-x u C-/ |
Resume undoing | M-x undo-only |
Undo in selected region only | C-u C-_ |
If you entered a command incorrectly(including if you have entered a full command key combination, but it is prompting you for input, you can hit C-g
to cancel it.
Resume Undoing means un-undo, often called redo. If you triggered undoing accidentally, you will be able to get things back by run M-x undo-only
Cut, Copy and Paste
Command | Combination |
---|---|
Kill(cut) to end of line | C-k |
Set Mark(start selecting) | C-Space |
Copy selected region | M-w |
Kill(cut) selected region | C-w |
Kill to next occurrence of(char) | M-z(char) |
Kill next balanced expression | C-M-k |
Kill forwards word | M-d |
Kill backwards word | M-DEL |
Append next kill to previous | C-M-w |
Multiple Buffers
Command | Combination |
---|---|
Change to other(open) buffer [then select buffer to change to] | C-x b |
Split window horizontally | C-x 2 |
Split window vertivally | C-x 3 |
Move between split window | C-x o |
Un-split all windows | C-x 1 |
Remove current split window | C-x 0 |
Make current split window taller | C-x ^ |
Search and Replace
Command | Combination |
---|---|
Incremental Search Forward | C-s |
Incremental Search Backwords > To repeat the search(find next/prev), press C-s or C-r again |
C-r |
Search and Replace | M-x replace-string |
Query Replace | M-% |
Search and Replace Regexp | M-x replace-regexp |
Query Replace Regexp | C-M-% |
Programming Commands
Command | Combination | comment |
---|---|---|
Compile | M-x comile | The author recommend binging this to C-c C-v |
Go to next error | M-g n C-x ‘ | |
Go to previous error | M-g p | |
Complete current word > Replace completion with next choice | M-/ M-/(two times) | |
Show semantic completion | C-c SPACE | Semantic |
Show details of completions | C-c l | Semantic |
Jump to function def(this file) | C-c j | Semantic |
Jump to function def(any file) | C-c J | Semantic |
Goto Line Number | M-x goto-line | |
Indent Selected Region | M-x indent-region C-M-/ | |
Comment DWIM | M-; |
Advanced Movement
Command | Combination |
---|---|
Move to the start of the line | C-a |
Move to the end of line | C-e |
Move to start of buffer | M-< |
Move to end of buffer | M-> |
Forward by a word | M-f |
Backward by a word | M-b |
Return to mark(where you set it) | C-u C-space |
Forward by a balanced expression | M-C-f |
Backward by a balanced expression | M-C-b |
Start of line, past indentation | M-m |
Start of current function | M-C-a |
End of current function | M-C-e |
Keyboard Marcos
Command | Combination |
---|---|
Start Defining Keyboard Macro | C-x ( |
Finish Defining Keyboard Macro | C-x ) |
Execute Macro | C-x e |
> Repeat Execution of Macro | e[right after executing it] |
Do macro to each line in a region | M-x apply-macro-to-region-lines |
Name last macro | M-x name-last-kbd-macro |
macro: a sequence of commands
Writing Text or LaTeX
Command | Combination |
---|---|
Spell check word | M-$ |
Spell check buffer interactively | M-x ispell-buffer |
Spell check buffer by coloring words | M-x flyspell-buffer |
Automatically color mis-spelled words | M-x flyspell-mode |
Questions
Undo/Redo
Undo in region