#202206121637 has a complicated set of keybindings that user could take advantage of to manipulate lines, buffers, files etc. We can customise the keybindings in respect to our own preference by defining them in Emacs #lisp. Additionally, it can be recorded using 202208061214# to execute complicated keystrokes combination for several times.
Take note to the following shorthand:
-
C
refers to the Ctrl key -
M
refers to the Meta key, usually means the Alt key
Note: If the alphabet is in capital (A, B, C …), Shift key is involved.
Editor Itself
We can minimise the editor with C-z
and exit by the keybind C-x
C-c
.
Command Cancellation
We can cancel an undesired command or keybind by using the keybind C-g
.
Repeat
C-u {number} {keybind/command/character}
or M-{number}
can be used execute the keybind or command or write character for number
times. For example, when used with C-f
, we can move to the next number
character forward. If used with character such as *
, Emacs will type in number
of *
.
Horizontal Movement
Keybind | Function |
---|---|
C-f | Move to the next character |
C-b | Move to the previous one character |
M-f | Move to the next word |
M-b | Move to the previous word |
C-a | Move to the beginning of the current line |
C-e | Move to the end of the current line |
M-a | Move to/backward to the beginning of the sentence |
M-e | Move to/forward to the end of the sentence |
Vertical Movement
Keybind | Function |
---|---|
C-n | Move to the next line |
C-p | Move to the previous line |
C-v | Scroll to the next page |
M-v | Scroll to the previous page |
C-l | Change view |
M-< | Move to the beginning of the file |
M-> | Move to the end of the file |
Note: C-l
will first recenter the view of the file. If C-l
is executed for a second time, the view will changed to top. Third time, it will changed to bottom.
Line Manipulation
Emacs distinguishes between kill and delete. Kill means putting character or line into an iteratable 202112031154 (the kill ring). Deleted character or line in the other hand can’t be pasted (yank) from the kill ring since the ring doesn’t record deleted objects.
Keybind | Function |
---|---|
C-d | Kill the next character |
M-d | Kill the next word |
C-k | Kill until the end of the current line |
M-k | Kill until the end of the current/next sentence |
C-y | Yank recently killed line or from clipboard |
M-y | Iterate over previous killed lines |
M-q | Re-fill or realign the paragraph |
Note: C-y
needs to be executed first before M-y
.
Note: If there is no content for the current line, that is there is only whitespaces and/or next line character, C-k
will kill the line instead.
Note: If C-k
is executed several time in row (without interruption), killed texts will concatenated together.
Select
C-<SPC>
will start highlighting minor mode. From there on, we can include more characters, lines or sentences by using either #Horizontal Movement and #Vertical Movement. Several keybindings can be used to manipulate the selected or highlighted section.
Keybind | Function |
---|---|
C-w | Kill highlighted region |
M-w | Copy highlighted region |
Search and Replace
In Emacs, searches are done incrementally. This means that Emacs will always try to find the first occurrence based on the character(s) that you have already typed in. To replace it, we can use the command replace-string#
Keybind | Function |
---|---|
C-s | Do a forward search |
C-r | Do a reverse search |
Note: If searching is already happen, both C-s
and C-r
will simply move to the next occurrence in order or in reverse respectively.
Undo Redo
Keybind | Function |
---|---|
C-/ | Undo |
File Related
Keybind | Function |
---|---|
C-x C-f | Finds files, if not found, then create it |
C-x C-s | Saves file |
Buffers
Keybind | Function |
---|---|
C-x C-b | List buffers |
C-x b | Switch buffer |
C-x s | Prompt to save files in unsaved buffers |
C-x k | Kill buffer |
Windows
Keybind | Function |
---|---|
C-x 1 | Delete all windows except current one |
C-x 2 | Split the current window horizontally |
C-x 3 | Split the current window vertically |
C-x 4 C-f | Find files and open it in a horizontal split |
C-M-v | Scroll to the next page in other window, similar to C-v |
C-M-V | Scroll to the previous page in other window, similar to M-v |
C-x o | Switch to other window |
Help
One could call help from Emacs. This can be done by executing C-h
with a consequent character which will bring up a help #Windows.
Consequent Character after C-h | Function |
---|---|
? | Help menu to access other help windows |
k | Help for a keybinding |
c | Brief for a keybinding |
x | Describe a command |
v | Help for a variable |
m | Help for current major mode |
a | Search for commands based on given keyword |
i | Open manuals |
r | Open Emacs manual |