Essential Vim Commands for Enhanced Productivity

Command Mode Fundamentals

Vim's efficiency stems from its ability to execute commands with repetitions and precise movements. In command mode, prefixing a command with a number repeats it that many times. Movement commands can be combined with editing operations for rapid navigation and modification.

Basic Movement

Mastering cursor movement is crucial. Use h, j, k, l for left, down, up, and right. For word navigation, w moves forward and b backward. Jump to line start with 0 or ^ (first non-blank), and line end with $. Use gg for file top, G for bottom, and numberG or :number to go to a specific line. Screen navigation includes Ctrl+b (page up), Ctrl+f (page down), H (top), M (middle), and L (bottom).

Programmatic Movement

Navigate paragraphs with { (previous) and } (next). Match parentheses, brackets, or braces with %. Use marks for quick jumps: mx sets mark x (a–z or A–Z), and 'x jumps to it.

Visual Mode and Selection

Enter visual mode to select text: v for character-wise, V for line-wise, and Ctrl+v for block-wise. Combine with movements, e.g., ggVG selects entire file.

Undo and Redo

Reverse actions with u (undo) and restore them with Ctrl+r (redo).

Deletion Operations

Delete characters with x, or combine d with motions: dw deletes word, d0 to line start, d} to paragraph end, dd deletes line, and ndd removes n lines. D deletes to line end.

Copy and Paste

Yank text with y plus motion or yy for a line. Use p to paste. Note: Vim's buffer is separate from the system clipboard; use edit mode or mouse to paste external content.

Replacement Commands

Replace characters: r replaces current, R enters replace mode for subsequent chaarcters until Esc.

Indentation and Repetition

Indent right with >>, left with <<. Repeat last command with ..

Search and Replace

Find text with /pattern, then n (next) or N (previous). Match word under cursor with * (forward) and # (backward).

In ex mode, replace globally: :%s/old/new/g, in visual area: :s/old/new/g, or confirm each: :%s/old/new/gc with prompts (y/n/a/q/l).

Insertion Modes

Enter insert mode: i before cursor, I at line start, a after cursor, A at line end, o below line, O above line.

Split Screen Management

Split horizontally with :sp [file] and vertically with :vsp [file]. Navigate splits: Ctrl+w w cycles, Ctrl+w r swaps, Ctrl+w c closes current, Ctrl+w q exits, Ctrl+w o keeps only current.

File and Ex Mode Operations

Save with :w, quit with :q, force quit with :q!, save and quit with :wq or :x. Browse files with :e ., create new with :n filename, save as with :w filename.

Practical Tips

Open file at line: vim filename +line. Handle swap files after crash by deleting when prompted. Disable input methods for reliable key presses. On Mac with Touch Bar, use Ctrl+[ instead of Esc.

Tags: Vim Productivity text-editor command-line Tutorial

Posted on Thu, 18 Jun 2026 17:25:44 +0000 by Base