Master Vim: Essential Commands, Modes, and Customizations Explained
This comprehensive guide walks you through Vim’s history, core editing modes, essential commands for navigation, editing, searching, and file management, as well as advanced features like visual mode, split windows, and configuration options, providing a solid foundation for efficient text editing.
1. Vim History
Vim (Vi IMproved) evolved from the original vi editor; it is a modal text editor used for creating and viewing plain‑text files. Text files contain only character data without formatting, typically in formats such as ASCII, MIME, or .txt. Common text editors include line editors like sed and full‑screen editors like nano , vi , and vim .
2. Basic Operations
Modes
Normal (command) mode
Insert mode
Ex (last‑line) mode
Opening Files
# vim [OPTION]... FILE... +#– open file and place cursor at line # +/PATTERN – open file and jump to first line matching PATTERN
Mode Switching
i– insert before cursor a – append after cursor o – open a new line below cursor I – insert at start of line A – insert at end of line O – open a new line above cursor ESC – return to normal mode : – enter Ex mode
Exiting and Saving
:q– quit :! – force quit without saving :wq or :x – write and quit :w /PATH/TO/SOMEWHERE – write current buffer to another file ZZ – write and quit
Cursor Movement
Characterwise: h left, l right, k up, j down
Wordwise: w next word start, e next word end, b previous word start
Line start/end: ^ first non‑blank, 0 absolute start, $ end
Line navigation: #G go to line #, G last line, 1G or gg first line
Sentence: ) next, ( previous
Paragraph: } next, { previous
Editing Commands
Delete: x delete character, #x delete # characters, dd delete line, #dd delete # lines
Replace: r replace single character
Copy (yank): y, yy copy line, #yy copy # lines
Paste: p paste after cursor, P paste before cursor
Change: c change text, cc change whole line
3. Other Editing Operations
Visual Mode
v– characterwise visual selection V – linewise visual selection
Undo/Redo
u– undo #u – undo # times
Ctrl+r – redo . – repeat last change
4. Screen Operations
Ctrl+f– page forward Ctrl+b – page backward Ctrl+d – half‑page forward Ctrl+u – half‑page backward vimtutor – start built‑in tutorial
5. Ex Mode Features
Address ranges: : start , end (e.g., 1,5)
Search: /PATTERN forward, ?PATTERN backward, n / N repeat
Substitute: s/old/new/flags where flags include i (ignore case) and g (global)
6. File Management
Multiple Files
:next, :prev, :first, :last – switch buffers :wall – write all :qall – quit all
Window Splits
vim -o FILE1 FILE2– horizontal split vim -O FILE1 FILE2 – vertical split
Switch windows: Ctrl+w + Arrow
Split current window: Ctrl+w s (horizontal), Ctrl+w v (vertical)
Configuration
Global config: /etc/vimrc User config: ~/.vimrc Set options in Ex mode, e.g., set number (show line numbers), set noai (disable auto‑indent), set hlsearch (highlight search), syntax on (enable syntax highlighting), set ic (ignore case)
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.
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.
