Fundamentals 10 min read

Master Vim: Essential Commands, Shortcuts, and Tips to Boost Your Coding Efficiency

This article honors Vim creator Bram Moolenaar and provides a comprehensive, practical guide to Vim’s most useful commands, cursor movements, editing operations, search/replace patterns, copy‑paste techniques, and configuration options, helping developers work faster and more effectively with this powerful open‑source editor.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Vim: Essential Commands, Shortcuts, and Tips to Boost Your Coding Efficiency

Essential Vim Commands

Editing

i

, a, r – insert before cursor, append after cursor, or replace the character under the cursor. O, o – open a new empty line above ( O) or below ( o) the current line and enter Insert mode. cw, dw – change ( c) or delete ( d) the word under the cursor. x, d$, dd – delete a single character ( x), delete from cursor to end of line ( d$), or delete the whole line ( dd).

Cursor Movement

h

, j, k, l – move left, down, up, right. Ctrl+f, Ctrl+b – page forward and backward. nG – jump to line number n. w, b – move forward or backward by a word. ma, mb, mc – set marks a, b, c for later jumps with `a, etc. 0 and $ – move to the beginning or end of the current line. H, M, L – move to the top, middle, or bottom of the screen.

Deletion

ndw

or ndW – delete n words starting at the cursor. do – delete to the beginning of the line. d$ – delete to the end of the line. ndd – delete n consecutive lines. x / X – delete the character after or before the cursor. Ctrl+u – clear text entered in Insert mode. n1,n2d – delete lines n1 through n2. %d or 1,$d – delete the entire file.

Search

/pattern

– search forward for pattern. ?pattern – search backward for pattern. /\/pattern – search for a literal slash‑containing pattern (escape the slash). n – repeat the last search in the same direction. N – repeat the last search in the opposite direction.

Replace

s/old/new/

– replace the first occurrence of old on the current line with new. s/old/new/g – replace all occurrences on the current line. n,$s/old/new/ – replace the first old from line n to the end of the file. n,$s/old/new/g – replace all old from line n to the end. %s/old/new/g – replace every old in the whole file. s#old#new# – use # as delimiter to avoid escaping slashes. n1,n2s/p1/p2/g – replace p1 with p2 in the line range n1n2. g/p1/s//p2/g – replace all p1 with p2 in the entire file.

Copy & Paste

yy

– yank (copy) the current line. nyy – yank n lines starting from the current line.

Press v, move the cursor to select a visual region, then press y to yank. dd – cut (delete) the current line. p – paste below the cursor; P – paste above. n1,n2co n3 – copy lines n1n2 to after line n3. n1,n2m n3 – move lines n1n2 to after line n3.

Common Options

Editor Settings

set number

– display line numbers. set number! – toggle line numbers off. set all – list all option values. set ignorecase – ignore case in searches. set list – show tabs (as ^I) and end‑of‑line markers. set warn – warn when switching files with unsaved changes. set nowrapscan – stop search at file boundaries instead of wrapping. set mesg – allow messages from other users (e.g., write notifications).

Saving Files

:wq

– write (save) and quit. :q! – quit without saving. :w – write changes without quitting. U – undo all changes on the current line (or use u for incremental undo). Ctrl+r – redo changes undone by u.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Tutorialtext editorshortcutscommandsBram Moolenaar
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.