Master Vim’s Three Modes and Essential Commands for Efficient Editing
This guide explains Vim’s three core modes—command, insert, and Ex command mode—detailing common key commands, address ranges, search/replace syntax, configuration options, navigation shortcuts, visual selection, and window management to help users edit text more efficiently.
Vim’s Three Modes
1. Command mode
When Vim starts you are in command mode, where you can move the cursor, delete, copy and paste text. Common commands include:
i : switch to Insert mode<br/>x : delete character under cursor<br/>: : enter Ex command line<br/>dd : delete current line<br/>yy : yank (copy) current line<br/>:w : write file<br/>:q : quit Vim<br/>:e! : reload file discarding changes2. Insert mode
Press i in command mode to enter Insert mode and type freely. Press Esc to return to command mode.
3. Ex (extended) command mode
Press : in command mode to enter the command‑line. Frequently used commands:
w : write file<br/>q : quit Vim<br/>wq : write and quit<br>q! : force quit without saving<br>x : write and quit<br>X : encrypt<br>5,10r file.txt : read file.txt into lines 5‑10<br>r!command : execute command and read its outputAddress Ranges and Operations
Examples of address specifications:
# : specific line number<br/>#,# : range from line # to line #<br/>#,+# : from line # to line #+<br/>. : current line<br/>.,$-1 : current line to second‑last line<br/>% : whole file<br/>d : delete (e.g., 3,5d)<br/>y : yank (e.g., 3,7y) then p or P to paste<br/>r : read (e.g., 3r)Search and Replace
Search pattern:
/pattern/ : find pattern<br/>/pat1/,/pat2/ : range from pat1 to pat2<br/>#,/pat/ : from line # to pat<br/>/pat/,$ : from pat to end of fileSubstitution:
s/find/replace/flags (flags: i – ignore case, g – global, gc – confirm each)Vim Settings
Common options (use set):
nu : show line numbers<br/>nonu : hide line numbers<br/>ic : ignore case<br/>noic : case‑sensitive<br/>ai : auto‑indent<br/>noai : disable auto‑indent<br/>paste : enable paste mode<br/>nopaste : disable paste mode<br/>list : show invisible characters<br/>nolist : hide them<br/>hlsearch : highlight search results<br/>nohlsearch : disable highlighting<br/>syntax on : enable syntax highlighting<br/>syntax off : disable syntax highlighting<br/>fileformat=dos : use Windows line endings<br/>fileformat=unix : use Unix line endings<br/>et : expand tabs to spaces<br/>noet : keep tabs<br/>ts=4 : set tabstop to 4 spaces<br/>shiftwidth=4: set indentation width<br/>textwidth=80: wrap lines at 80 columns<br/>cul : highlight current line<br/>nocul : disable current line highlight<br/>key=passwd : set encryption keyFile‑Opening Options
+# : open file with cursor at line #<br/>+/#PATTERN : open file with cursor at first match of PATTERN<br/>-b file : open file in binary mode<br/>-d file1 file2 : diff two files<br/>-m file : open read‑only<br/>-e file : start in Ex modeCommand‑Mode Navigation
Cursor movement
h : left<br/>j : down<br/>k : up<br/>l : rightWord movement
b : back to beginning of previous word<br/>w : forward to beginning of next word<br/>e : end of current/next wordLine movement
0 : beginning of line<br/>$ : end of line<br/>gg: top of file<br/>G : bottom of fileScreen movement
Ctrl+f : page down<br/>Ctrl+b : page up<br/>Ctrl+d : half‑page down<br/>Ctrl+u : half‑page upEditing Commands
Character editing
rx : replace character under cursor with x<br/>x : delete character under cursor<br/>X : delete character before cursor<br/>dw : delete word forward<br/>db : delete word backward<br/>d$ : delete to end of lineChange commands
cw : change word<br/>c$ : change to end of line and enter Insert modeCopy & paste
yy : yank line<br/>p : paste after cursor<br/>P : paste before cursorUndo/redo
u : undo<br/>Ctrl+r: redoVisual Mode
Enter visual selections:
v : characterwise visual mode<br/>V : linewise visual mode<br/>Ctrl+v : blockwise visual modeWhile in visual mode you can move the cursor, then use y to yank, d to delete, or p / P to paste.
Window Management
:split : horizontal split<br/>:vsplit : vertical split<br/>Ctrl+w w : cycle focus<br/>:q : close window<br/>:only : close other windows<br/>Ctrl+w + / - : adjust height<br/>Ctrl+w > / < : adjust width<br/>:set scrollbind : sync scrolling<br/>:set noscrollbind : stop sync<br/>Ctrl+w r : toggle layout<br/>:tabedit : new tab<br/>:tabclose: close tabSigned-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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
