mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-07-09 22:22:40 +02:00
feat: emacs - objd + word-wrap + docs
This commit is contained in:
@@ -0,0 +1,61 @@
|
|||||||
|
# Editors Glossary
|
||||||
|
|
||||||
|
### LSP - Language Server Protocol
|
||||||
|
|
||||||
|
> https://en.wikipedia.org/wiki/Language_Server_Protocol
|
||||||
|
|
||||||
|
> https://langserver.org/
|
||||||
|
|
||||||
|
The Language Server Protocol (LSP) is an open, JSON-RPC-based protocol for use between source code editors or integrated development environments (IDEs) and servers that provide programming language-specific features like:
|
||||||
|
|
||||||
|
- **code completion**
|
||||||
|
- **marking of warnings and errors**
|
||||||
|
- **refactoring routines**
|
||||||
|
- syntax highlighting (use Tree-sitter instead)
|
||||||
|
- code formatting (use a dedicated formatter instead)
|
||||||
|
|
||||||
|
The goal of the protocol is to allow programming language support to be implemented and distributed independently of any given editor or IDE.
|
||||||
|
|
||||||
|
LSP was originally developed for Microsoft Visual Studio Code and is now an open standard.
|
||||||
|
In the early 2020s LSP quickly became a "norm" for language intelligence tools providers.
|
||||||
|
|
||||||
|
### Tree-sitter
|
||||||
|
|
||||||
|
> https://tree-sitter.github.io/tree-sitter/
|
||||||
|
|
||||||
|
> https://www.reddit.com/r/neovim/comments/1109wgr/treesitter_vs_lsp_differences_ans_overlap/
|
||||||
|
|
||||||
|
Tree-sitter is a parser generator tool and an **incremental parsing** library. It can build a concrete syntax tree for a source file and efficiently update the syntax tree as the source file is edited.
|
||||||
|
|
||||||
|
It is used by many editors and IDEs to provide:
|
||||||
|
|
||||||
|
- **syntax highlighting**
|
||||||
|
- **indentation**
|
||||||
|
- **creating foldable code regions**
|
||||||
|
- **Incremental selection**
|
||||||
|
- **simple refactoring in a single file**
|
||||||
|
- such as join/split lines, structural editing, cursor motion, etc.
|
||||||
|
|
||||||
|
**Treesitter process each file independently**, and it is not aware of the semantics of your code.
|
||||||
|
For example, it does not know does a function/variable really exist, or what is the type/return-type of a variable. This is where LSP comes in.
|
||||||
|
|
||||||
|
The LSP server parses the code much more deeply and it **not only parses a single file but your whole project**.
|
||||||
|
So, the LSP server will know whether a function/variable does exist with the same type/return-type. If it does not, it will mark it as an error.
|
||||||
|
|
||||||
|
**LSP does understand the code semantically, while Treesitter only cares about correct syntax**.
|
||||||
|
|
||||||
|
#### LSP vs Tree-sitter
|
||||||
|
|
||||||
|
- Tree-sitter: lightweight, fast, but limited knowledge of your code. mainly used for **syntax highlighting, indentation, and folding/refactoring in a single file**.
|
||||||
|
- LSP: heavy and slow on large projects, but it has a deep understanding of your code. mainly used for **code completion, refactoring in the projects, errors/warnings, and other semantic-aware features**.
|
||||||
|
|
||||||
|
### Formatter vs Linter
|
||||||
|
|
||||||
|
Linting is distinct from Formatting because:
|
||||||
|
|
||||||
|
1. **formatting** only restructures how code appears.
|
||||||
|
1. `prettier` is a popular formatter.
|
||||||
|
1. **linting** analyzes how the code runs and detects errors, it may also suggest improvements such as replace `var` with `let` or `const`.
|
||||||
|
|
||||||
|
Formatters and Linters process each file independently, they do not need to know about other files in the project.
|
||||||
|
* [ ]
|
||||||
@@ -1,64 +1,147 @@
|
|||||||
# Editors
|
# Editors
|
||||||
|
|
||||||
## Glossary
|
My editors:
|
||||||
|
|
||||||
### LSP - Language Server Protocol
|
1. Neovim
|
||||||
|
2. Emacs
|
||||||
|
3. Helix
|
||||||
|
|
||||||
> https://en.wikipedia.org/wiki/Language_Server_Protocol
|
And `Zellij` for a smooth and stable terminal experience.
|
||||||
|
|
||||||
> https://langserver.org/
|
## Tutorial
|
||||||
|
|
||||||
The Language Server Protocol (LSP) is an open, JSON-RPC-based protocol for use between source code editors or integrated development environments (IDEs) and servers that provide programming language-specific features like:
|
Type `:tutor`(`:Tutor` in Neovim) to learn the basics usage of vim/neovim.
|
||||||
|
|
||||||
- **code completion**
|
## VIM's Cheetsheet
|
||||||
- **marking of warnings and errors**
|
|
||||||
- **refactoring routines**
|
|
||||||
- syntax highlighting (use Tree-sitter instead)
|
|
||||||
- code formatting (use a dedicated formatter instead)
|
|
||||||
|
|
||||||
The goal of the protocol is to allow programming language support to be implemented and distributed independently of any given editor or IDE.
|
Both Emacs-Evil & Neovim are compatible with vim, sothe key-bindings described here are common in both Emacs-Evil, Neovim & vim.
|
||||||
|
|
||||||
LSP was originally developed for Microsoft Visual Studio Code and is now an open standard.
|
### Terminal Related
|
||||||
In the early 2020s LSP quickly became a "norm" for language intelligence tools providers.
|
|
||||||
|
|
||||||
### Tree-sitter
|
I mainly use Zellij for terminal related operations, here is its terminal shortcuts I use frequently now:
|
||||||
|
|
||||||
> https://tree-sitter.github.io/tree-sitter/
|
| Action | Zellij's Shortcut |
|
||||||
|
| ------------------------- | ----------------- |
|
||||||
|
| Floating Terminal | `Ctrl + p + w` |
|
||||||
|
| Horizontal Split Terminal | `Ctrl + p + d` |
|
||||||
|
| Vertical Split Terminal | `Ctrl + p + n` |
|
||||||
|
|
||||||
> https://www.reddit.com/r/neovim/comments/1109wgr/treesitter_vs_lsp_differences_ans_overlap/
|
### File Management
|
||||||
|
|
||||||
Tree-sitter is a parser generator tool and an **incremental parsing** library. It can build a concrete syntax tree for a source file and efficiently update the syntax tree as the source file is edited.
|
|
||||||
|
|
||||||
It is used by many editors and IDEs to provide:
|
| Action | |
|
||||||
|
| --------------------------------- | -------------------------------------------- |
|
||||||
|
| Save selected text to a file | `:w filename` (Will show `:'<,'>w filename`) |
|
||||||
|
| Save and close the current buffer | `:wq` |
|
||||||
|
| Save all buffers | `:wa` |
|
||||||
|
| Save and close all buffers | `:wqa` |
|
||||||
|
|
||||||
- **syntax highlighting**
|
### Text Manipulation
|
||||||
- **indentation**
|
|
||||||
- **creating foldable code regions**
|
|
||||||
- **Incremental selection**
|
|
||||||
- **simple refactoring in a single file**
|
|
||||||
- such as join/split lines, structural editing, cursor motion, etc.
|
|
||||||
|
|
||||||
**Treesitter process each file independently**, and it is not aware of the semantics of your code.
|
Basics:
|
||||||
For example, it does not know does a function/variable really exist, or what is the type/return-type of a variable. This is where LSP comes in.
|
|
||||||
|
|
||||||
The LSP server parses the code much more deeply and it **not only parses a single file but your whole project**.
|
| Action | |
|
||||||
So, the LSP server will know whether a function/variable does exist with the same type/return-type. If it does not, it will mark it as an error.
|
| ----------------------------------- | ------------------------------ |
|
||||||
|
| Move to the start/end of the buffer | `gg`/`G` |
|
||||||
|
| Move the line number 5 | `5G` |
|
||||||
|
| Move left/down/up/right | h/j/k/l or `5h`/`5j`/`5k`/`5l` |
|
||||||
|
| Delete the current character | `x` |
|
||||||
|
| Delete the selection | `d` |
|
||||||
|
| Undo the last change | `u` |
|
||||||
|
| Redo the last change | `Ctrl + r` |
|
||||||
|
|
||||||
**LSP does understand the code semantically, while Treesitter only cares about correct syntax**.
|
Convert Text Cases:
|
||||||
|
|
||||||
#### LSP vs Tree-sitter
|
| Toggle text's case | `~` |
|
||||||
|
| Convert to uppercase | `U` |
|
||||||
|
| Convert to lowercase | `u` |
|
||||||
|
|
||||||
- Tree-sitter: lightweight, fast, but limited knowledge of your code. mainly used for **syntax highlighting, indentation, and folding/refactoring in a single file**.
|
Misc:
|
||||||
- LSP: heavy and slow on large projects, but it has a deep understanding of your code. mainly used for **code completion, refactoring in the projects, errors/warnings, and other semantic-aware features**.
|
|
||||||
|
|
||||||
### Formatter vs Linter
|
| Action | Shortcut |
|
||||||
|
| ----------------------------- | ---------------------------------------- |
|
||||||
|
| Toggle visual mode | `v` (lower case v) |
|
||||||
|
| Select the current line | `V` (upper case v) |
|
||||||
|
| Toggle visual block mode | `<Ctrl> + v` (select a block vertically) |
|
||||||
|
| Fold the current code block | `zc` |
|
||||||
|
| Unfold the current code block | `zo` |
|
||||||
|
| Jump to Definition | `gd` |
|
||||||
|
| Jump to References | `gD` |
|
||||||
|
| (Un)Comment the current line | `gcc` |
|
||||||
|
|
||||||
Linting is distinct from Formatting because:
|
| Action | |
|
||||||
|
| ------------------------------------------------------------------------- | -------------- |
|
||||||
|
| Join Selection of Lines With Space | `:join` or `J` |
|
||||||
|
| Join without spaces | `:join!` |
|
||||||
|
| Move to the start/end of the line | `0` / `$` |
|
||||||
|
| Enter Insert mode at the start/end of the line | `I` / `A` |
|
||||||
|
| Delete from the cursor to the end of the line | `D` |
|
||||||
|
| Delete from the cursor to the end of the line, and then enter insert mode | `C` |
|
||||||
|
|
||||||
1. **formatting** only restructures how code appears.
|
Advance Techs:
|
||||||
1. `prettier` is a popular formatter.
|
|
||||||
1. **linting** analyzes how the code runs and detects errors, it may also suggest improvements such as replace `var` with `let` or `const`.
|
|
||||||
|
|
||||||
Formatters and Linters process each file independently, they do not need to know about other files in the project.
|
- 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
|
||||||
|
|
||||||
|
### Search
|
||||||
|
|
||||||
|
| Action | Command |
|
||||||
|
| ----------------------------------------------------- | --------- |
|
||||||
|
| Search forward/backword for a pattern | `/` / `?` |
|
||||||
|
| Repeat the last search in the same/opposite direction | `n` / `N` |
|
||||||
|
|
||||||
|
### Find and Replace
|
||||||
|
|
||||||
|
| Action | Command |
|
||||||
|
| ------------------------ | ----------------------------------- |
|
||||||
|
| Replace in selected area | `:s/old/new/g` |
|
||||||
|
| Replace in current line | Same as above |
|
||||||
|
| Replace in whole file | `:% s/old/new/g` |
|
||||||
|
| Replace with regex | `:% s@\vhttp://(\w+)@https://\1@gc` |
|
||||||
|
|
||||||
|
1. `\v` means means that in the regex pattern after it can be used without backslash escaping(similar to python's raw string).
|
||||||
|
2. `\1` means the first matched group in the pattern.
|
||||||
|
|
||||||
|
### Replace in the specific lines
|
||||||
|
|
||||||
|
| Action | Command |
|
||||||
|
| ----------------------------------------- | -------------------------------------- |
|
||||||
|
| From the 10th line to the end of the file | `:10,$ s/old/new/g` or `:10,$ s@^@#@g` |
|
||||||
|
| From the 10th line to the 20th line | `:10,20 s/old/new/g` |
|
||||||
|
|
||||||
|
The postfix(flags) in the above commands:
|
||||||
|
|
||||||
|
1. `g` means replace all the matched strings in the current line/file.
|
||||||
|
2. `c` means ask for confirmation before replacing.
|
||||||
|
3. `i` means ignore case.
|
||||||
|
|
||||||
|
### Buffers, Windows and Tabs
|
||||||
|
|
||||||
|
- A buffer is the in-memory text of a file.
|
||||||
|
- A window is a viewport on a buffer.
|
||||||
|
- A tab page is a collection of windows.
|
||||||
|
|
||||||
|
| Action | Command |
|
||||||
|
| ----------------------------------- | ------------------------------- |
|
||||||
|
| Show all buffers | `:ls` |
|
||||||
|
| show next/previous buffer | `]b`/`[b` or `:bnext` / `bprev` |
|
||||||
|
| Split the window horizontally | `:sp` |
|
||||||
|
| Split the window horizontally | `:vsp` |
|
||||||
|
| New Tab(New Workspace in DoomEmacs) | `:tabnew` |
|
||||||
|
| Next/Previews Tab | `gt`/`gT` |
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ doom sync
|
|||||||
|
|
||||||
when in doubt, run `doom sync`!
|
when in doubt, run `doom sync`!
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
1. we can run any emacs command via `M-x`(Alt + x).
|
||||||
|
|
||||||
## Why emacs?
|
## Why emacs?
|
||||||
|
|
||||||
1. Explore the unknown, just for fun!
|
1. Explore the unknown, just for fun!
|
||||||
@@ -37,79 +41,68 @@ when in doubt, run `doom sync`!
|
|||||||
- [evil-smartparens](https://github.com/expez/evil-smartparens): simple and useful.
|
- [evil-smartparens](https://github.com/expez/evil-smartparens): simple and useful.
|
||||||
- [parinfer](https://github.com/doomemacs/doomemacs/tree/master/modules/editor/parinfer): simple and useful, but works not well with some other completion plugins.
|
- [parinfer](https://github.com/doomemacs/doomemacs/tree/master/modules/editor/parinfer): simple and useful, but works not well with some other completion plugins.
|
||||||
|
|
||||||
## Terminal Related
|
## Cheetsheet
|
||||||
|
|
||||||
zellij provides a more powerful and stable terminal experience, so here is zellij's terminal shortcuts I use frequently now:
|
Here is the cheetsheet related to my DoomEmacs configs. Please read vim's common cheetsheet at [../README.md](../README.md) before reading the following.
|
||||||
|
|
||||||
| Action | Zellij's Shortcut |
|
### Terminal Related
|
||||||
| ------------------------- | ------------------ |
|
|
||||||
| 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
|
| Action | Shortcut |
|
||||||
|
| ---------------------- | ------------- |
|
||||||
|
| Open file tree sidebar | `SPC + o + p` |
|
||||||
|
| Exit | `M-x C-c` |
|
||||||
|
|
||||||
The same as neovim/vim:
|
### Window Navigation
|
||||||
|
|
||||||
| 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 |
|
| Action | Shortcut |
|
||||||
| ------------------------------------------ | --------------------------------------------------------------------- |
|
| ------------------------------------------ | --------------------------------------------------------------------- |
|
||||||
| split a window vertically and horizontally | `SPC w v/s` |
|
| 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 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 a window to a specific direction | `Ctrl-w + H/J/K/L` |
|
||||||
| move to the next window | `SPC w w` |
|
| Move to the next window | `SPC w w` |
|
||||||
| Resize Treemacs's window | `M - >` & `M - <` |
|
|
||||||
| Close the current window | `SPC w q` |
|
| Close the current window | `SPC w q` |
|
||||||
| rebalance all windows | `SPC w =` |
|
| 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 width(columns) | `80 SPC w \|` (the Vertical line is escaped due to markdown's limits) |
|
||||||
| set window's height | `30 SPC w _ ` |
|
| Set window's height | `30 SPC w _ ` |
|
||||||
|
|
||||||
|
### File Tree
|
||||||
|
|
||||||
|
- treemacs: <https://github.com/Alexander-Miller/treemacs/blob/master/src/elisp/treemacs-mode.el>
|
||||||
|
- treemacs-evil: <https://github.com/Alexander-Miller/treemacs/blob/master/src/extra/treemacs-evil.el>
|
||||||
|
|
||||||
## Splitting and Buffers
|
| Action | Shortcut |
|
||||||
|
| ------------------------------------- | --------- |
|
||||||
|
| Resize Treemacs's window | `>` & `<` |
|
||||||
|
| Extra Wide Window | `W` |
|
||||||
|
| Rename | `R` |
|
||||||
|
| Delete File/Direcoty | `d` |
|
||||||
|
| New File | `cf` |
|
||||||
|
| New Directory | `cd` |
|
||||||
|
| Go to parent | `u` |
|
||||||
|
| Run shell command in for current node | `!` |
|
||||||
|
| Refresh file tree | `gr` |
|
||||||
|
| Copy project-path into pasteboard | `yp` |
|
||||||
|
| Copy absolute-path into pasteboard | `ya` |
|
||||||
|
| Copy relative-path into pasteboard | `yr` |
|
||||||
|
| Copy file to another location | `yf` |
|
||||||
|
| Move file to another location | `m` |
|
||||||
|
| quit | `q` |
|
||||||
|
|
||||||
|
And bookmarks:
|
||||||
|
|
||||||
|
- Add bookmarks in treemacs: `b`
|
||||||
|
- Show Bookmark List: `SPC s m`
|
||||||
|
|
||||||
|
### Splitting and Buffers
|
||||||
|
|
||||||
| Action | Shortcut |
|
| Action | Shortcut |
|
||||||
| ----------------------- | ----------------- |
|
| ----------------------- | ----------------- |
|
||||||
| Next Buffer (Tab) | `]b` |
|
|
||||||
| Previous Buffer (Tab) | `[b` |
|
|
||||||
| Buffer List | `<Space> + ,` |
|
| Buffer List | `<Space> + ,` |
|
||||||
| Save all buffers(Tab) | `<Space> + b + S` |
|
| Save all buffers(Tab) | `<Space> + b + S` |
|
||||||
| Kill the current buffer | `<Space> + b + k` |
|
| Kill the current buffer | `<Space> + b + k` |
|
||||||
| Kill all buffers | `<Space> + b + K` |
|
| Kill all buffers | `<Space> + b + K` |
|
||||||
|
|
||||||
## Editing and Formatting
|
### Editing and Formatting
|
||||||
|
|
||||||
| Action | Shortcut |
|
| Action | Shortcut |
|
||||||
| ------------------------------------------ | ------------------- |
|
| ------------------------------------------ | ------------------- |
|
||||||
@@ -119,23 +112,11 @@ The same as neovim/vim:
|
|||||||
| Opening LSP symbols | `<Space> + cS` |
|
| Opening LSP symbols | `<Space> + cS` |
|
||||||
| Show all LSP Errors | `<Space> + c + x/X` |
|
| Show all LSP Errors | `<Space> + c + x/X` |
|
||||||
| Show infinite undo history(really useful!) | `<Space> + s + u` |
|
| 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` |
|
| Open filepath/URL at cursor | `gf` |
|
||||||
| Find files by keyword in path | `<Space> + <Space>` |
|
| Find files by keyword in path | `<Space> + <Space>` |
|
||||||
| Grep string in files (vertico + ripgrep) | `<Space> + sd` |
|
| Grep string in files (vertico + ripgrep) | `<Space> + sd` |
|
||||||
|
|
||||||
## Text Manipulation
|
### Search & replace
|
||||||
|
|
||||||
| Action | |
|
|
||||||
| ---------------------------------- | --- |
|
|
||||||
| Join Selection of Lines With Space | `J` |
|
|
||||||
|
|
||||||
## Search & replace
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
SPC s p foo C-; E C-c C-p :%s/foo/bar/g RET Z Z
|
SPC s p foo C-; E C-c C-p :%s/foo/bar/g RET Z Z
|
||||||
@@ -147,3 +128,25 @@ SPC s p foo C-; E C-c C-p :%s/foo/bar/g RET Z Z
|
|||||||
1. `C-c C-p` to run wgrep-change-to-wgrep-mode to make the search results writable.
|
1. `C-c C-p` to run wgrep-change-to-wgrep-mode to make the search results writable.
|
||||||
1. `:%s/foo/bar/g RET`: replace in the current buffer(just like neovim/vim)
|
1. `:%s/foo/bar/g RET`: replace in the current buffer(just like neovim/vim)
|
||||||
1. `Z Z`: to write all the changes to their respective files
|
1. `Z Z`: to write all the changes to their respective files
|
||||||
|
|
||||||
|
### Projects
|
||||||
|
|
||||||
|
> easily switch between projects without exit emacs!
|
||||||
|
|
||||||
|
| Action | |
|
||||||
|
| -------------------------- | ------------- |
|
||||||
|
| Switch between projects | `SPC + p + p` |
|
||||||
|
| Browse the current project | `SPC + p + .` |
|
||||||
|
| Add new project | `SPC + p + a` |
|
||||||
|
|
||||||
|
### Workspaces
|
||||||
|
|
||||||
|
> Very useful when run emacs in daemon/client modes
|
||||||
|
|
||||||
|
| Action | |
|
||||||
|
| --------------------------- | --------------------------- |
|
||||||
|
| Switch between workspaces | `M-1/2/3/...`(Alt-1/2/3/..) |
|
||||||
|
| New Workspace | `SPC + TAB + n` |
|
||||||
|
| New Named Workspace | `SPC + TAB + N` |
|
||||||
|
| Delete Workspace | `SPC + TAB + d` |
|
||||||
|
| Display Workspaces bar blow | `SPC + TAB + TAB` |
|
||||||
|
|||||||
@@ -60,12 +60,12 @@
|
|||||||
fold ; (nigh) universal code folding
|
fold ; (nigh) universal code folding
|
||||||
(format +onsave)
|
(format +onsave)
|
||||||
; automated prettiness
|
; automated prettiness
|
||||||
multiple-cursors ; editing in many places at once
|
;; multiple-cursors ; editing in many places at once
|
||||||
;;objed ; text object editing for the innocent
|
objed ; text object editing for the innocent
|
||||||
;; parinfer ; turn lisp into python, sort of
|
;; parinfer ; turn lisp into python, sort of
|
||||||
;;rotate-text ; cycle region at point between text candidates
|
;;rotate-text ; cycle region at point between text candidates
|
||||||
snippets ; my elves. They type so I don't have to
|
snippets ; my elves. They type so I don't have to
|
||||||
;;word-wrap ; soft wrapping with language-aware indent
|
word-wrap ; soft wrapping with language-aware indent
|
||||||
|
|
||||||
:emacs
|
:emacs
|
||||||
dired ; making dired pretty [functional]
|
dired ; making dired pretty [functional]
|
||||||
|
|||||||
@@ -33,27 +33,11 @@ Remove all unused plugins:
|
|||||||

|

|
||||||

|

|
||||||
|
|
||||||
## Terminal Related
|
## Cheetsheet
|
||||||
|
|
||||||
I used to use Neovim's terminal related shortcuts frequently, but now **I switched my daily terminal environment to zellij**,
|
Here is the cheetsheet related to my Neovim configs. Please read vim's common cheetsheet at [../README.md](../README.md) before reading the following.
|
||||||
which provides a more powerful and stable terminal experience, so I don't use neovim's terminal feature anymore.
|
|
||||||
|
|
||||||
So here is zellij's terminal shortcuts I use frequently now:
|
### Incremental Selection
|
||||||
|
|
||||||
| Action | Zellij's Shortcut |
|
|
||||||
| ------------------------- | ------------------ |
|
|
||||||
| Floating Terminal | `Ctrl + <p> + <w>` |
|
|
||||||
| Horizontal Split Terminal | `Ctrl + <p> + <d>` |
|
|
||||||
| Vertical Split Terminal | `Ctrl + <p> + <n>` |
|
|
||||||
|
|
||||||
## Visual Modes
|
|
||||||
|
|
||||||
| Action | Shortcut |
|
|
||||||
| ------------------------ | ---------------------------------------- |
|
|
||||||
| Toggle visual mode | `v` |
|
|
||||||
| Toggle visual block mode | `<Ctrl> + v` (select a block vertically) |
|
|
||||||
|
|
||||||
## Incremental Selection
|
|
||||||
|
|
||||||
Provided by nvim-treesitter.
|
Provided by nvim-treesitter.
|
||||||
|
|
||||||
@@ -64,7 +48,7 @@ Provided by nvim-treesitter.
|
|||||||
| scope incremental | `<Alt-Space>` |
|
| scope incremental | `<Alt-Space>` |
|
||||||
| node decremental | `Backspace` |
|
| node decremental | `Backspace` |
|
||||||
|
|
||||||
## Search and Jump
|
### Search and Jump
|
||||||
|
|
||||||
Provided by [flash.nvim](https://github.com/folke/flash.nvim), it's a intelligent search and jump plugin.
|
Provided by [flash.nvim](https://github.com/folke/flash.nvim), it's a intelligent search and jump plugin.
|
||||||
|
|
||||||
@@ -76,61 +60,34 @@ Provided by [flash.nvim](https://github.com/folke/flash.nvim), it's a intelligen
|
|||||||
| Treesitter Search | `yR`,`dR`, `cR`, `vR`, `ctrl+v+R`(arround your matches, all the surrounding Treesitter nodes will be labeled) |
|
| Treesitter Search | `yR`,`dR`, `cR`, `vR`, `ctrl+v+R`(arround your matches, all the surrounding Treesitter nodes will be labeled) |
|
||||||
| Remote Flash | `yr`, `dr`, `cr`, (arround your matches, all the surrounding Treesitter nodes will be labeled) |
|
| Remote Flash | `yr`, `dr`, `cr`, (arround your matches, all the surrounding Treesitter nodes will be labeled) |
|
||||||
|
|
||||||
## Text Manipulation
|
### Commands & Shortcuts
|
||||||
|
|
||||||
- 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
|
|
||||||
|
|
||||||
## Commands & Shortcuts
|
|
||||||
|
|
||||||
| Action | Shortcut |
|
| Action | Shortcut |
|
||||||
| ----------------------------- | -------------- |
|
| ----------------------------- | -------------- |
|
||||||
| Learn Neovim's Basics | `:Tutor` |
|
|
||||||
| Open file explorer | `<Space> + e` |
|
| Open file explorer | `<Space> + e` |
|
||||||
| Focus Neotree to current file | `<Space> + o` |
|
| Focus Neotree to current file | `<Space> + o` |
|
||||||
| Toggle line wrap | `<Space> + uw` |
|
| Toggle line wrap | `<Space> + uw` |
|
||||||
| Show line diagnostics | `gl` |
|
| Show line diagnostics | `gl` |
|
||||||
| Show function/variable info | `K` |
|
| Show function/variable info | `K` |
|
||||||
| Go to definition | `gd` |
|
|
||||||
| References of a symbol | `gr` |
|
| References of a symbol | `gr` |
|
||||||
|
|
||||||
## Window Navigation
|
### Window Navigation
|
||||||
|
|
||||||
- Switch between windows: `<Ctrl> + h/j/k/l`
|
- Switch between windows: `<Ctrl> + h/j/k/l`
|
||||||
- Resize windows: `<Ctrl> + Up/Down/Left/Right`
|
- Resize windows: `<Ctrl> + Up/Down/Left/Right`
|
||||||
- Note: On macOS, conflicts with system shortcuts
|
- Note: On macOS, conflicts with system shortcuts
|
||||||
- Disable in System Preferences -> Keyboard -> Shortcuts -> Mission Control
|
- Disable in System Preferences -> Keyboard -> Shortcuts -> Mission Control
|
||||||
|
|
||||||
## Splitting and Buffers
|
### Splitting and Buffers
|
||||||
|
|
||||||
| Action | Shortcut |
|
|
|
||||||
|
| Action | Shortcut |
|
||||||
| --------------------- | ------------- |
|
| --------------------- | ------------- |
|
||||||
| Horizontal Split | `\` |
|
| Horizontal Split | `\` |
|
||||||
| Vertical Split | `\|` |
|
| Vertical Split | `\|` |
|
||||||
| Next Buffer (Tab) | `]b` |
|
| Close Buffer | `<Space> + c` |
|
||||||
| Previous Buffer (Tab) | `[b` |
|
|
||||||
| Close Buffer | `<Space> + c` |
|
|
||||||
|
|
||||||
## Editing and Formatting
|
### Editing and Formatting
|
||||||
|
|
||||||
| Action | Shortcut |
|
| Action | Shortcut |
|
||||||
| ----------------------------------------------------- | -------------- |
|
| ----------------------------------------------------- | -------------- |
|
||||||
@@ -144,7 +101,7 @@ Provided by [flash.nvim](https://github.com/folke/flash.nvim), it's a intelligen
|
|||||||
| Find files by name (fzf) | `<Space> + ff` |
|
| Find files by name (fzf) | `<Space> + ff` |
|
||||||
| Grep string in files (ripgrep) | `<Space> + fw` |
|
| Grep string in files (ripgrep) | `<Space> + fw` |
|
||||||
|
|
||||||
## Sessions
|
### Sessions
|
||||||
|
|
||||||
| Action | Shortcut |
|
| Action | Shortcut |
|
||||||
| ------------------------------ | -------------- |
|
| ------------------------------ | -------------- |
|
||||||
@@ -154,43 +111,18 @@ Provided by [flash.nvim](https://github.com/folke/flash.nvim), it's a intelligen
|
|||||||
| Search Session | `<Space> + Sf` |
|
| Search Session | `<Space> + Sf` |
|
||||||
| Load Current Directory Session | `<Space> + S.` |
|
| Load Current Directory Session | `<Space> + S.` |
|
||||||
|
|
||||||
## Debugging
|
### Debugging
|
||||||
|
|
||||||
Press `<Space> + D` to view available bindings and options.
|
Press `<Space> + D` to view available bindings and options.
|
||||||
|
|
||||||
## Find and Replace
|
### Search and Replace Globally
|
||||||
|
|
||||||
| Action | Command |
|
|
||||||
| ------------------------ | ----------------------------------- |
|
|
||||||
| Replace in selected area | `:s/old/new/g` |
|
|
||||||
| Replace in current line | Same as above |
|
|
||||||
| Replace in whole file | `:% s/old/new/g` |
|
|
||||||
| Replace with regex | `:% s@\vhttp://(\w+)@https://\1@gc` |
|
|
||||||
|
|
||||||
1. `\v` means means that in the regex pattern after it can be used without backslash escaping(similar to python's raw string).
|
|
||||||
2. `\1` means the first matched group in the pattern.
|
|
||||||
|
|
||||||
## Replace in the specific lines
|
|
||||||
|
|
||||||
| Action | Command |
|
|
||||||
| ----------------------------------------- | -------------------------------------- |
|
|
||||||
| From the 10th line to the end of the file | `:10,$ s/old/new/g` or `:10,$ s@^@#@g` |
|
|
||||||
| From the 10th line to the 20th line | `:10,20 s/old/new/g` |
|
|
||||||
|
|
||||||
The postfix(flags) in the above commands:
|
|
||||||
|
|
||||||
1. `g` means replace all the matched strings in the current line/file.
|
|
||||||
2. `c` means ask for confirmation before replacing.
|
|
||||||
3. `i` means ignore case.
|
|
||||||
|
|
||||||
## Search and Replace Globally
|
|
||||||
|
|
||||||
| Description | Shortcut |
|
| Description | Shortcut |
|
||||||
| ------------------------------------------------------------ | ---------------------------------------------------------------- |
|
| ------------------------------------------------------------ | ---------------------------------------------------------------- |
|
||||||
| Open spectre.nvim search and replace panel | `<Space> + ss` |
|
| Open spectre.nvim search and replace panel | `<Space> + ss` |
|
||||||
| Search and replace in command line(need install `sad` first) | `find -name "*.nix" \| sad '<pattern>' '<replacement>' \| delta` |
|
| Search and replace in command line(need install `sad` first) | `find -name "*.nix" \| sad '<pattern>' '<replacement>' \| delta` |
|
||||||
|
|
||||||
## Surrounding Characters
|
### Surrounding Characters
|
||||||
|
|
||||||
Provided by mini.surround plugin.
|
Provided by mini.surround plugin.
|
||||||
|
|
||||||
@@ -203,30 +135,19 @@ Provided by mini.surround plugin.
|
|||||||
| Replace surrounding characters | `gzr'"` | Replace `'` by `"` around the word under cursor |
|
| Replace surrounding characters | `gzr'"` | Replace `'` by `"` around the word under cursor |
|
||||||
| Highlight surrounding | `gzh'` | Highlight `'` around the word under cursor |
|
| Highlight surrounding | `gzh'` | Highlight `'` around the word under cursor |
|
||||||
|
|
||||||
## Text Manipulation
|
### Text Manipulation
|
||||||
|
|
||||||
| Action | |
|
| Action | |
|
||||||
| -------------------------------------- | ------------- |
|
| -------------------------------------- | ------------- |
|
||||||
| Join Selection of Lines With Space | `:join` |
|
|
||||||
| Join without spaces | `:join!` |
|
|
||||||
| Join with LSP intelligence(treesj) | `<Space> + j` |
|
| Join with LSP intelligence(treesj) | `<Space> + j` |
|
||||||
| Split Line into Multiple Lines(treesj) | `<Space> + s` |
|
| Split Line into Multiple Lines(treesj) | `<Space> + s` |
|
||||||
|
|
||||||
## Convert Text Case
|
### Miscellaneous
|
||||||
|
|
||||||
| Action | |
|
| Action | |
|
||||||
| -------------------- | --- |
|
| --------------------- | --------------- |
|
||||||
| Toggle text's case | `~` |
|
| Show all Yank History | `:<Space> + yh` |
|
||||||
| Convert to uppercase | `U` |
|
| Show undo history | `:<Space> + uh` |
|
||||||
| Convert to lowercase | `u` |
|
|
||||||
|
|
||||||
## Miscellaneous
|
|
||||||
|
|
||||||
| Action | |
|
|
||||||
| ---------------------------- | -------------------------------------------- |
|
|
||||||
| Save selected text to a file | `:w filename` (Will show `:'<,'>w filename`) |
|
|
||||||
| Show all Yank History | `:<Space> + yh` |
|
|
||||||
| Show undo history | `:<Space> + uh` |
|
|
||||||
|
|
||||||
## Additional Resources
|
## Additional Resources
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user