Files
nix-config/home/base/desktop/editors/emacs
2024-01-05 12:37:56 +08:00
..
2024-01-05 12:37:56 +08:00

Emacs Editor

Install or Update

After deploying this nix flake, run the following command to install or update emacs:

doom sync

when in doubt, run doom sync!

Why emacs?

  1. Explore the unknown, just for fun!
  2. Better support for Lisp-like Languages.
  3. Org Mode

Structured editing of S-expression data

https://wikemacs.org/wiki/Lisp_editing

zellij provides a more powerful and stable terminal experience, so here is zellij's terminal shortcuts I use frequently now:

Action Zellij's Shortcut
Floating Terminal Ctrl + <p> + <w>
Horizontal Split Terminal Ctrl + <p> + <d>
Vertical Split Terminal Ctrl + <p> + <n>
Open file tree sidebar SPC + o + p
Exit M-x C-c

Visual Modes

The same as neovim/vim:

Action Shortcut
Toggle visual mode v
Toggle visual block mode <Ctrl> + v (select a block vertically)

Text Manipulation

  • Add at the end of multiple lines: :normal A<text>

    • Execublock: :A<text>

    • visual block mode(ctrl + v)

    • Append text at the end of each line in the selected block

    • If position exceeds line end, neovim adds spaces automatically

  • Delete the last char of multivle lines: :normal $x

    • Execute $x on each line
    • visual mode(v)
    • $ moves cursor to the end of line
    • x deletes the character under the cursor
  • Delete the last word of multiple lines: :normal $bD

    • Execute $bD on each line
    • visual mode(v)
    • $ moves cursor to the end of line
    • b moves cursor to the beginning of the last word
  • D deletes from cursor to the end of line

Window Navigation

Action Shortcut
split a window vertically and horizontally SPC w v/s
move to a window in a specific direction Ctrl-w + h/j/k/l
move a window to a specific direction Ctrl-w + H/J/K/L
move to the next window SPC w w
Resize Treemacs's window M - > & M - <
Close the current window SPC w q
rebalance all windows SPC w =
set window's width(columns) 80 SPC w | (the Vertical line is escaped due to markdown's limits)
set window's height 30 SPC w _

Splitting and Buffers

Action Shortcut
Next Buffer (Tab) ]b
Previous Buffer (Tab) [b
Buffer List <Space> + ,
Save all buffers(Tab) <Space> + b + S
Kill the current buffer <Space> + b + k
Kill all buffers <Space> + b + K

Editing and Formatting

Action Shortcut
Format Document <Space> + cf
Code Actions <Space> + ca
Rename <Space> + cr
Opening LSP symbols <Space> + cS
Show all LSP Errors <Space> + c + x/X
Show infinite undo history(really useful!) <Space> + s + u
Fold the current code block zc
Unfold the current code block zo
Jump to Definition gd
Jump to References gD
(Un)Comment the selected context gc
(Un)Comment the current line gcc
Open filepath/URL at cursor gf
Find files by keyword in path <Space> + <Space>
Grep string in files (vertico + ripgrep) <Space> + sd

Text Manipulation

Action
Join Selection of Lines With Space J

Search & replace

SPC s p foo C-; E C-c C-p :%s/foo/bar/g RET Z Z
  1. SPC s p: search in project
  2. foo: the keyword to search
  3. C-; E: exports what youre looking at into a new buffer in grep-mode
  4. C-c C-p to run wgrep-change-to-wgrep-mode to make the search results writable.
  5. :%s/foo/bar/g RET: replace in the current buffer(just like neovim/vim)
  6. Z Z: to write all the changes to their respective files