Vim Cheat Sheet
Motions
Shortcut | Action |
---|---|
0g | Go to beginning of file |
G | Go to end of file |
^ | Go to beginning of line |
$ | Go to end of line |
J | (Visual) - move selection down |
K | (Visual) - move selection up |
A | Move to end of line and insert |
<C-d> | Half page jump down |
<C-u> | Half page jump up |
Project
Shortcut | Action |
---|---|
<leader>pv | Nav to netrw |
<leader>pf | Project find (telescope) |
<C-p> | Find files only tracked in git |
<leader>ps | Search project files with grep |
:e path/to/file.txt | (netrw) - Create file in specified path |
External Commands
Shortcut | Action |
---|---|
:! | Type a command after the bang to execute in the shell |
:! ls | Execute ls in the current working tree. |
:r <file> | Retrieves the specified file and places contents below cursor |
:r !ls | Retrieves the output of the external command and places contents below cursor |
Workspace
Shortcut | Action |
---|---|
<C-w><C-w> | Jump between windows |
<C-w>h | Move split window on the left |
<C-w>j | Move split window on the down |
<C-w>k | Move split window on the up |
<C-w>l | Move split window on the right |
Editing
Shortcut | Action |
---|---|
:%s/Search/Replace/CommandFlag | Search and replace all occurances |
:s/Search/Replace/CommandFlag | Search and replace current line |
o | Insert line below cursor |
O | Insert line above cursor |
a | Insert text AFTER the cursor |
A | Insert text at the end of the line |
:e! | Discard current edit buffer and re-read current file |
r<char> | Replace under cursor with <char> |
R | Enter replace mode. <Esc> to exit |
c | Change operator |
ce | Change from cursor to end of current word |
o<C-r>" | Insert new line and then paste from " register |
Fighting One-Eyed Kirby
Example Code Block
use("folke/zen-mode.nvim")
use("github/copilot.vim")
<shift>V
Visual Linej
motion down for selection:s
Enter command mode
Regex search/replace
:'<,'>s/use(\(".*"\).*/\1
Result Code Block
"folke/zen-mode.nvim"
"github/copilot.vim"
Explanation
:s
Search and replace/
Start patternuse(\
Search for string literal(".*"\)
Regex to capture everything and place into capture group 1.*
Regex to capture everything after the first capture group/
Substitute section\1
Escape and then replace with capture group 1
Spell Check
Shortcut | Action |
---|---|
]s | Move cursor to next misspelled word |
[s | Move cursor to previous misspelled word |
z= | Open list of spelling suggestions for word under cursor |
zg | Add word to dictionary |
zw | Mark word as incorrect |
LSP
Shortcut | Action |
---|---|
<C-p> | select previous item |
<C-n> | select next item |
<C-y> | confirm selection |
<C-Space> | complete |
Harpoon
Shortcut | Action |
---|---|
C-e | Toggle harpoon menu |
<leader>a | Add file |
C-h | Nav to file 1 |
C-j | Nav to file 2 |
C-k | Nav to file 3 |
C-l | Nav to file 4 |
Fugitive (Git)
Shortcut | Action |
---|---|
<leader>gs | git status |
cc | git commit |
ca | git --amend |
dd | git diff |
q | Close git status |
r | Reload git status |
<leader>p | git push |
<leader>P | git pull --rebase |
<leader>t | git push -u origin |