Skip to content

Instantly share code, notes, and snippets.

@DaniSancas
Last active December 5, 2024 15:29
Show Gist options
  • Save DaniSancas/6bd2ec0547cb80c541543c0d2e262ec9 to your computer and use it in GitHub Desktop.
Save DaniSancas/6bd2ec0547cb80c541543c0d2e262ec9 to your computer and use it in GitHub Desktop.
Vim motions cheatsheet

Basics

Action Key Tip
Move left h
Move below j
Move above k
Move right l
Action Key Tip
Jump to next cursor position <C-i>
Jump to previous cursor position <C-o>
Action Key Tip
Leader <Space>

Horizontal movement

Action Key Tip
Move to the beginning of line 0
Move to the first non-space character of line ^ or _
Move to the EOL $
Action Key Tip
Forward word w Think of "word"
Forward word (incl. punctuation) W
Backwards word b Think of "backwards"
Backwards word (incl. punctuation) B
End of word e Think of "end"
Action Key Tip
Move to the next specified character f Think of "find"
Move to the next (backwards) specified character F
Move to before specified character t Think as "till"
Move to before (backwards) specified character T
Repeat (find or till) motions forward ;
Repeat (find or till) motions backwards ,

Examples:

  • f( moves to the nearest ( forward in the line
  • if then ; is pressed, it moves to the next ( in the line

Vertical movement

Action Key Tip
Move to first line gg
Move to last line G
Move to line x :x
Move to previous paragraph {
Move to next paragraph }
Action Key Tip
Move forward full screen <C-f> Think of "move forward"
Move backwards full screen <C-b> Think of "move backwards"
Move forward half screen <C-d> Think of "move down"
Move backwards half screen <C-u> Think of "move up"
Move to the top of the screen H
Move to the middle of the screen M
Move to the bottom of the screen L
Action Key Tip
Position cursor on center of the screen zz
Position cursor on top of the screen zt Think of "top"
Position cursor on bottom of the screen zb Think of "bottom"
Action Key Tip
Jump to previous class/function definition [[
Jump to next class/function definition ]]
Jump to previous diagnostic [d
Jump to next diagnostic ]d

Insert mode

Action Key Tip
Insert before cursor i Think of "insert"
Insert at beginning of line I
Insert after cursor a Think of "append"
Insert at EOL A
Add a line below and insert cursor o Think of "open"
Add a line above and insert cursor O
Action Key Tip
Yank (copy) y Think of "copy"
Yank line yy
Delete (cut) d Think of "cut"
Delete line dd
Delete char x
Replace char r
Change c Think of "delete + insert"
Change line cc
Paste after the cursor p
Paste before the cursor P
Action Key Tip
Undo u

Examples:

  • d3j: Delete 3 lines
  • ci{: Change inside the {}
  • 5k: Move 5 lines above
  • 6yy: Yank 6 lines

Visual mode

Action Key Tip
Enter visual mode v
Enter visual mode + select current line V
Action Key Tip
Selected text to uppercase U
Selected text to lowercase u
Selected text toggle case ~
Add tabulation to selected text >
Substract tabulation from selected text <

Examples:

  • 6jVD: Advance 6 lines, select and delete the whole line
  • <C-v> + 3j + I# + <Esc>: Apply a vertical change, 3 lines with # at the beginning of line

Buffers

Action Key Tip
List buffers :ls or <leader><leader>
Edit file in new buffer :e file
Go to next buffer :bn or <leader>bn Think of "buffer next"
Go to previous buffer :bp or <leader>bp Think of "buffer previous"
Close buffer :bd or <leader>bd Think of "buffer delete"

Note: In case the same buffer is present in several windows, it will close all of them.

Action Key Tip
Open current buffer in horizontal split <C-w>s Think of "window + split"
Open current buffer in vertical split <C-w>v Think of "window + vertical"
Close current window <C-w>q Think of "window + quit"
Close all other windows <C-w>o Think of "window + (quit) others"
Action Key Tip
Move cursor to left window <C-h>
Move cursor to below window <C-j>
Move cursor to above window <C-k>
Move cursor to right window <C-l>

Others

Action Key Tip
Open file/link <leader>gx
Repeat last command .

LSP (Language Server Protocol)

Action Key Tip
Go to definition <leader>gd
Go to references <leader>gr
Go to implementation <leader>gI
Show hover information <leader>gg
Type definition <leader>D Jump to the type of the word under cursor (definition of the type, not where it was defined)
Document symbols <leader>ds Fuzzy find symbols (vars, functions, types...) in current file
Workspace symbols <leader>ws Fuzzy find symbols (vars, functions, types...) in entire project
Rename variable <leader>rn
Code action <leader>ca Cursor must be at an error or suggestion

DAP (Debug Adapter Protocol)

Action Key Tip
Toggle breakpoint <leader>bb
Remove all breakpoints <leader>br
Start/continue debug <leader>dc
Debug step into <leader>di
Debug step over <leader>dv
Debug step out <leader>do
Debug step back <leader>db
Debug terminate <leader>dt
Debug restart <leader>dr
Debug show hover information <leader>?

Testing (neotest)

Action Key Tip
Run nearest test <leader>tr
Run last test <leader>tl
Run file tests <leader>tf
Run all tests <leader>ta
Action Key Tip
Debug nearest test <leader>tR
Debug last test <leader>tL
Debug file tests <leader>tF
Debug all tests <leader>tA
Action Key Tip
Toggle test summary <leader>ts
Toggle test output window <leader>to
Stop test <leader>tS
Attach to test <leader>tA

Git (gitsigns)

Action Key Tip
Toggle line blame <leader>tb
Toggle buffer blame <leader>tB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment