Master Vim: Essential Commands for Efficient Text Editing
This guide introduces Vim, a powerful command‑line text editor, and walks through essential cursor‑movement shortcuts, deletion, undo/redo, copy‑paste, visual mode, searching, replacing, line shifting, accessing man pages, insert mode commands, Ex‑mode substitutions, shell execution, split‑window techniques, and basic configuration files for turning Vim into an IDE.
Introduction
Vim is a text‑based editor that operates entirely through commands, without graphical menus.
Command‑line mode commands
Cursor movement : h (left), j (down), k (up), l (right), gg (file start), G (file end), 0 (line start), $ (line end), 123G (go to line 123).
Deletion : x (delete character after cursor), X (delete character before cursor), dw (delete word), d0 (delete to line start), D or d$ (delete to line end), dd (delete whole line), ndd (delete n lines). Deletions are actually cuts.
Undo/redo : u (undo), Ctrl‑r (redo).
Copy & paste : yy (yank current line), nyy (yank n lines), p (paste below cursor), P (paste above cursor).
Visual mode : v (characterwise visual), combine with h/j/k/l to select, y to yank selection.
Search : /pattern (forward), ?pattern (backward), n (next), N (previous), # (search word under cursor).
Replace : r (replace single character).
Line shifting : >> (indent right), << (indent left).
Man page lookup : Place cursor on a function name and press Shift‑k to view its manual entry; 3Shift‑k shows the third section.
Text (Insert) mode commands
i: insert before cursor. I: insert at line start. a: insert after cursor. A: insert at line end. o: open a new line below and enter insert mode. O: open a new line above and enter insert mode. s: delete character under cursor and enter insert mode. S: delete current line and enter insert mode.
Ex (Command) mode commands
Line jump: :123 moves to line 123.
Substitution examples:
Replace first occurrence on the current line: :s/abc/123 Replace all occurrences on the current line: :s/abc/123/g Replace first occurrence in the whole file: :%s/abc/123 Replace all occurrences in the whole file: :%s/abc/123/g Replace in a range (lines 10‑30): :10,30s/abc/123/g Execute a shell command: type ! followed by the command in Ex mode.
Split‑window operations
Horizontal split: sp Vertical split: vsp Split with a file: sp filename or vsp filename Close all windows and save: wqall Save and close current window: wq Toggle between windows:
Ctrl‑wwTurning Vim into an IDE
System‑wide configuration file: /etc/vim/vimrc. User‑specific configuration file: ~/.vim/vimrc (or ~/.vimrc). Edit these files to customize key mappings, plugins, and other IDE‑like features.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
