My editors:
- Neovim
- Helix
And Zellij for a smooth and stable terminal experience.
- Many useful keys are already provided by vim, check vim/neovim's docs before you install a new plugin / reinvent the wheel.
- After using Emacs/Neovim more skillfully, I strongly recommend that you read the official
documentation of Neovim/vim:
- https://vimhelp.org/: The official vim documentation.
- https://neovim.io/doc/user/: Neovim's official user documentation.
- Use Zellij for terminal related operations, and use Neovim/Helix for editing.
- As for Emacs, Use its GUI version & terminal emulator
vtermfor terminal related operations. - Two powerful file search & jump tools:
- Tree-view plugins are beginner-friendly and intuitive, but they're not very efficient.
- Search by the file path: Useful when you're familiar with the project structure, especially on a large project.
- Search by the content: Useful when you're familiar with the code.
Type :tutor(:Tutor in Neovim) to learn the basics usage of vim/neovim.
Here only record my commonly used keys, to see a more comprehensive cheetsheet: https://vimhelp.org/quickref.txt.html
Both Emacs-Evil & Neovim are compatible with vim, sothe key-bindings described here are common in both Emacs-Evil, Neovim & vim.
I mainly use Zellij for terminal related operations, here is its 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 |
| Execute a command | !xxx |
| 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 |
| Edit a file | :e filename(or :e <TAB> to show a file list) |
| Browse the file list | :Ex or :e . |
| Discard changes and reread the file | :e! |
| Action | Command |
|---|---|
| Move to the start/end of the buffer | gg/G |
| Move the line number 5 | 5gg / 5G |
| Move left/down/up/right | h/j/k/l or 5h/5j/5k/5l or Ctr-n/Ctrl-p |
Move to the matchpairs, default to (), {}, [] |
% |
| Move to the start/end of the line | 0 / $ |
| Move a sentence forward/backward | ( / ) |
| Move a paragraph forward/backward | { / } |
| Move a section forward/backward | [[ / ]] |
| Jump to various positions | ' + some other keys(neovim has prompt) |
Text Objects:
- sentence: text ending at a '.', '!' or '?' followed by either the end of a line, or by a space or tab.
- paragraph: text ending at a blank line.
- section: text starting with a section header and ending at the start of the next section
header (or at the end of the file). - The "
]]" and "[[" commands stop at the '{' in the first column. This is useful to find the start of a function in a C/Go/Java/... program.
Basics:
| Action | |
|---|---|
| Delete the current character | x |
| Paste the copied text | p |
| Delete the selection | d |
| Undo the last word | CTRL-w(in insert mode) |
| Undo the last line | CTRL-u(in insert mode) |
| Undo the last change | u |
| Redo the last change | Ctrl + r |
| Inserts the text of the previous insert | Ctrl + a |
| Repeat the last command | . |
| Toggle text's case | ~ |
| Convert to uppercase | U (visual mode) |
| Convert to lowercase | u (visual mode) |
| Align the selected content | :center/:left/:right |
Misc:
| 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 |
| Action | |
|---|---|
| Sort the selected lines | :sort |
| Join Selection of Lines With Space | :join or J |
| Join without spaces | :join! |
| 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 |
Advance Techs:
-
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
- Execublock:
-
Delete the last char of multivle lines:
:normal $x- Execute
$xon each line - visual mode(v)
$moves cursor to the end of linexdeletes the character under the cursor
- Execute
-
Delete the last word of multiple lines:
:normal $bD- Execute
$bDon each line - visual mode(v)
$moves cursor to the end of linebmoves cursor to the beginning of the last word
- Execute
| Action | Command |
|---|---|
| Search forward/backword for a pattern | / / ? |
| Repeat the last search in the same/opposite direction | n / N |
| Action | Command |
|---|---|
| Replace in selected area | :s/old/new/g |
| Replace in current line | Same as above |
| Replace all the lines | :% s/old/new/g |
| Replace all the lines with regex | :% s@\vhttp://(\w+)@https://\1@gc |
\vmeans means that in the regex pattern after it can be used without backslash escaping(similar to python's raw string).\1means the first matched group in the pattern.
| 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 |
| Remove the trailing spaces | :% s/\s\+$//g |
The postfix(flags) in the above commands:
gmeans replace all the matched strings in the current line/file.cmeans ask for confirmation before replacing.imeans ignore case.
- 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 |
|---|---|
| Split the window horizontally | :sp[lit] or :sp filename |
| Split the window horizontally | :vs[plit] or :vs filename |
| Switch to the next/previous window | Ctrl-w + w or Ctrl-w + h/j/k/l |
| Show all buffers | :ls |
| show next/previous buffer | ]b/[b or :bn[ext] / bp[rev] |
| New Tab(New Workspace in DoomEmacs) | :tabnew |
| Next/Previews Tab | gt/gy |
| Action | Command |
|---|---|
| Show the command history | q: |
| Show the search history | q/ |