Vim Essential Commands and Tricks
Master these lesser-known, yet powerful, Vim commands to dramatically speed up your text editing workflow.
1. Quick Exits
Save precious seconds when closing files.
| Action | Command | Description |
|---|---|---|
| Save and Quit | ZZ |
Two capital Zs. A quick way to write changes and exit. |
| Quit without saving | ZQ |
Capital Z, then Q. Quits without saving, similar to :q!. |
2. Smart Text Selection & Modification (Inner Blocks)
Use the “inner block” motion (i) combined with block type to quickly target content within delimiters.
| Action | Command | Description |
|---|---|---|
Select inside parentheses () |
vib |
visual inner block (or ‘b’ for balanced symbols). |
Select inside curly braces {} |
viB |
visual inner BRACE (capital B). |
Change inside quotes "" |
ci" |
change inner quote. Works with '' and \` too. |
Change inside parentheses () |
cib |
Quickly deletes and puts you in insert mode. |
3. Visual Block Mode for Multi-Line Edits
Perform operations on blocks of text across multiple lines.
| Action | Command | Description |
|---|---|---|
| Enter Block Mode | Ctrl+v |
Use this before selecting lines. |
| Insert at Start of Block | I |
While in Visual Block mode, press capital I to insert text that appears on every selected line after pressing Esc. |
| Append at End of Block | A |
After selecting the block (and pressing $), press capital A to append text to the end of every selected line after pressing Esc. |
| Re-select Last Block | gv |
Jumps you back into Visual Block mode with the last block selected. |
4. Navigation & Structure
Fluidly move around and clean up your code.
| Action | Command | Description |
|---|---|---|
| Re-indent the whole file | gg=G |
Go to top (gg), apply auto-indent (=), go to bottom (G). |
| Jump between matching pairs | % |
Place the cursor on a (, {, [, or similar symbol and jump to its match. |
| Jump to specific line number | 42G |
Type the line number, then capital G. |
| Join lines with a space | J |
Capital J joins the current line and the next with one space between them. |
| Join lines without a space | gJ |
gJ joins the lines without adding a space. |
5. Toggle Case
| Action | Command | Description |
|---|---|---|
| Toggle character case | ~ |
In Normal mode, toggle the case of the character under the cursor. |
| Toggle word case | g~w |
Toggle case for the current word. |
| Toggle case in a tag | g~it |
Toggle case for text inner tag. |
6. Sessions, URLs, and Files
Quickly interact with your environment.
| Action | Command | Description |
|---|---|---|
| Suspend Vim to terminal | Ctrl+z |
Temporarily pauses Vim and returns you to the shell. |
| Return Vim to foreground | fg |
Type fg in the terminal to resume your session. |
| Open URL under cursor | gx |
Opens the web link under the cursor in your default browser. |
| Open file path under cursor | gf |
Opens the file path under the cursor (if it exists in the Vim path). |
7. Advanced Bookmarks (Marks)
Marks allow you to quickly jump between locations.
| Action | Command | Description |
|---|---|---|
| Set Mark (Current File) | m followed by a lowercase letter (e.g., ma). |
Mark is only valid within the current file. |
| Jump to Mark (Current File) | ' followed by the lowercase letter (e.g., 'a). |
Jumps to the marked line and column. |
| Set Mark (Across Files) | m followed by an uppercase letter (e.g., mA). |
Mark is valid across files and persists until Vim closes. |
| Jump to Mark (Across Files) | ' followed by the uppercase letter (e.g., 'A). |
Jumps to the correct file and line. |