Emacs Keybinding

#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

KeybindFunction
C-fMove to the next character
C-bMove to the previous one character
M-fMove to the next word
M-bMove to the previous word
C-aMove to the beginning of the current line
C-eMove to the end of the current line
M-aMove to/backward to the beginning of the sentence
M-eMove to/forward to the end of the sentence

Vertical Movement

KeybindFunction
C-nMove to the next line
C-pMove to the previous line
C-vScroll to the next page
M-vScroll to the previous page
C-lChange 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.

KeybindFunction
C-dKill the next character
M-dKill the next word
C-kKill until the end of the current line
M-kKill until the end of the current/next sentence
C-yYank recently killed line or from clipboard
M-yIterate over previous killed lines
M-qRe-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.

KeybindFunction
C-wKill highlighted region
M-wCopy 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#

KeybindFunction
C-sDo a forward search
C-rDo 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

KeybindFunction
C-/Undo
KeybindFunction
C-x C-fFinds files, if not found, then create it
C-x C-sSaves file

Buffers

KeybindFunction
C-x C-bList buffers
C-x bSwitch buffer
C-x sPrompt to save files in unsaved buffers
C-x kKill buffer

Windows

KeybindFunction
C-x 1Delete all windows except current one
C-x 2Split the current window horizontally
C-x 3Split the current window vertically
C-x 4 C-fFind files and open it in a horizontal split
C-M-vScroll to the next page in other window, similar to C-v
C-M-VScroll to the previous page in other window, similar to M-v
C-x oSwitch 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-hFunction
?Help menu to access other help windows
kHelp for a keybinding
cBrief for a keybinding
xDescribe a command
vHelp for a variable
mHelp for current major mode
aSearch for commands based on given keyword
iOpen manuals
rOpen Emacs manual
Links to this page
  • Emacs Keyboard Macro

    We can record #keystrokes combination into a single macro and to be called later in #202206121637. Emacs store macros recorded into a single ring, much like the kill ring. However, the macro ring will only be available for its corresponding buffer, meaning it can’t be called in other windows or buffers.

  • Emacs

    Emacs is a free and open source editor which is part of the GNU project. We can customise almost every aspect of the editor in its Lisp variant (Emacs Lisp, with the extension .el) such as 202206121523#, 202206131443# and 202206151006#. It consists of buffer, mode line and echo area by default.

#emacs #lisp #Horizontal #Vertical #Windows