Lesson 5 of 29 ↓
- 1.Rhel 9 Administration Guide
- 2.Ubuntu Boot Process Guide
- 3.Linux Basic Commands Guide
- 4.Comprehensive Unix Shells Guide
- 5.Mastering Vim Deep & Practical Guide
- 6.Magic Numbers in Linux Deep Systems Guide
- 7.Wildcards & Globbing in Linux Deep Cli Guide
- 8.Linux Users & Groups Deep Administration Guide
- 9.Journaling in Linux Filesystems Deep Systems Guide
- 10.Getopt & Getoptlong Deep System-level Option Parsing Guide
- 11.Su Command in Linux Complete Guide with Environment Variables
- 12.Linux File Permissions and Ownership Complete Practical Guide
- 13.Ubuntu Package Management Apt Complete Guide
- 14.Bash Scripting Basics
- 15.Linux File System Essentials
- 16.Process and Thread Management
- 17.Session 10 : Introduction to Networking & the Application Layer
- 18.Linux Networking Cli & Introduction to Yocto for Machine Routing
- 19.Comprehensive Guide to Ssh (secure Shell)
- 20.Logical Volume Management (lvm) Guide
- 21.C Build Process & Libraries Guide
- 22.Archiving and Compression in Linux
- 23.Linux Package Managers: a Detailed Guide
- 24.Misra-c Guidelines Detailed Cheat Sheet
- 25.Mqtt Server Setup (pc as Server)
- 26.Detailed Explanation of Tty and Pts in Linux
- 27.Vim Cheat Sheet
- 28.Difference Between apt and apt-get
- 29.Difference Between apt Upgrade and apt Full-upgrade
6 min read
Mastering Vim Deep & Practical Guide
A complete, opinionated, and production-grade guide to Vim—from fundamentals to elite workflows. This document fills in all missing mental models, advanced mechanics, real-world patterns, and professional practices used by power users.
Philosophy of Vim
Vim is not a text editor in the traditional sense. It is a language for manipulating text.
Key ideas:
-
You describe what to edit, not how
-
Editing is faster than thinking
-
The keyboard is the primary interface
"Vim rewards thinking in motions and transformations, not keystrokes."
Vim Mental Model
Vim Grammar
[count] + operator + motion = editExamples:
-
dw→ delete word -
3j→ move down 3 lines -
ci(→ change inside parentheses
This composability is Vim's true power.
Modes in Depth
| Mode | Purpose |
|---|---|
| Normal | Navigation + commands |
| Insert | Text input |
| Visual | Selection |
| Command | Ex commands (:) |
| Replace | Overwrite mode |
| Terminal | Embedded shell |
Mode switching is deliberate—not accidental.
Motions, Operators & Text Objects
Motions (navigation)
-
w,b,e→ Jump by words (forward, backward, end of word). -
%→ Jump between matching pairs (like( )or{ }).
Inline Jumps (Simplified):
-
f<char>(Find): Pressfthen type any letter. The cursor will jump and land directly on the next matching letter on the same line. (Example: Pressfthenx-> jumps exactly to the next 'x'). -
t<char>(Till): Presstthen type any letter. The cursor will jump and land just before the next matching letter. (Example: Presstthenx-> jumps right before the next 'x').
Operators (actions)
-
d→ delete (cut) -
y→ yank (copy) -
c→ change (delete and enter Insert mode) -
>,<→ indent / un-indent
Text Objects (context)
-
iw,aw→ inner word, around word -
i(,i{,i"→ inside parentheses, braces, quotes
Example Combos:
ci" " Change inside quotes
di( " Delete inside parentheses
yap " Yank (copy) around paragraphCounts & Composability
Everything is repeatable by typing a number first:
10dd " Delete 10 lines
5>> " Indent 5 lines
3ciw " Change the next 3 wordsVim scales with file size effortlessly.
Undo Tree & Time Travel
Vim has a non-linear undo tree, meaning you never truly lose your edit history.
Key commands (Simplified):
-
u→ Undo: Pressuto undo the last action. -
<C-r>→ Redo: Press and holdCtrland then pressr. This redoes the action you just undid. -
:undolist→ View the branches of your undo history.
Persist undo history across restarts (add to .vimrc):
set undofile
set undodir=~/.vim/undoInsert Mode Power
-
ctrl/<C-p>→ Auto-completion (Next/Previous match) (Ctrl+n, Ctrl+p). -
<C-r>0→ Paste from register0while in insert mode (Ctrl+r, then 0). -
<C-o>→ Execute a single Normal mode command and immediately return to Insert mode.
Rule of thumb: Avoid staying in Insert mode unless you are actively typing new text.
Visual Mode Mastery
| Mode | Key | Action |
|---|---|---|
| Visual | v |
Select character by character |
| Line Visual | V |
Select whole lines |
| Block Visual | <C-v> |
Select a rectangular block of text (Ctrl+v) |
Block editing example (Comment out multiple lines):
<C-v>jjI// <Esc>(Select block downwards with jj, press I to insert, type // , then hit Esc to apply to all selected lines).
Advanced Navigation
-
:jumps→ Show jump list -
:changes→ Show change list -
gg=G→ Re-indent the entire file automatically -
zz,zt,zb→ Scroll screen so cursor is in the Middle (zz), Top (zt), or Bottom (zb) of the viewport.
Search, Replace & Regex
Global replace:
:%s/foo/bar/gc(Search for 'foo', replace with 'bar', g = global on line, c = ask for confirmation).
Regex groups:
:%s/\(foo\)/[\1]/gVery magic mode (Simplified Regex):
:%s\v(foo|bar)/baz/gBuffers, Windows & Tabs
| Concept | Meaning |
|---|---|
| Buffer | The actual file loaded in memory. |
| Window | A viewport showing a buffer (split screen). |
| Tab | A collection of window layouts. |
Golden rule: Buffers are files; windows are views; tabs are workspaces.
Split Window Workflow
Navigation:
<C-w> h j k l " Move cursor Left, Down, Up, Right between splits(Ctrl+w) then any one of them.
<C-w> = " Equalize all split sizesResize:
<C-w> + " Increase height
<C-w> < " Decrease widthVimdiff (professional Use)
Great for:
-
Conflict resolution (Git merges)
-
Configuration comparison
-
Code reviews
Diff modes commands:
:diffget " Pull changes from the other window
:diffput " Push changes to the other windowRegisters (all of Them)
Registers are like multiple clipboards.
| Register | Purpose |
|---|---|
" |
Default (unnamed) register |
0 |
Last yank (copy) - extremely useful! |
1-9 |
Delete history |
_ |
Black hole register (deleting here doesn't overwrite your clipboard) |
+ |
System clipboard (Ctrl+C / Ctrl+V in other apps) |
Clipboard Internals
Never destroy your clipboard when deleting:
"_dd " Deletes the line into the black hole registerRecommended setting to sync Vim with OS clipboard:
set clipboard=unnamedplusMarks, Jumps & Change Lists
Power commands:
-
mA→ Create a global mark named 'A' -
'avs`a→ Jump to line of mark 'a' vs jump to exact line AND column. -
<C-i>/<C-o>→ Navigate forward/backward through your jump history (Ctrl+i / Ctrl+o).
Macros at Scale
Record reusable logic to automate repetitive tasks:
qa " Start recording macro into register 'a'
... " (do your edits)
q " Stop recording
10@a " Execute macro 'a' 10 timesEditable macros:
:let @a='ddj'Command-line Mode Power
Command History Window:
q:Shell access from inside Vim:
:!gcc % " Compile current file
:r !date " Read output of 'date' command and paste it into bufferVimscript Fundamentals
Basic structure:
let g:var = 1
if g:var == 1
echo "Hello Vim"
endifCustom Commands & Functions
command! Build make
function! Run()
echo "Running..."
endfunctionPlugin Ecosystem
Principles:
-
Minimal plugins (Keep it fast)
-
Learn native ways before installing a plugin
Must-know plugins:
-
vim-fugitive(Git integration) -
fzf.vim(Fuzzy file finder) -
vim-surround(Easily change quotes, brackets, tags)
Lsp & Ide Power
With coc.nvim or nvim-lsp (Neovim), Vim becomes a full IDE:
-
Go-to-definition
-
Refactoring
-
Diagnostics & Linting
Git & Build Integration
:Git status " Requires vim-fugitive
:make " Run your build tool
:copen " Open quickfix window to see errorsPerformance
Speed tips:
-
Disable syntax highlighting for massive files.
-
Lazy-load plugins so they only start when needed.
Security
-
Avoid executing modelines from unknown files.
-
Always read scripts/plugins before sourcing them.
Learning Path
-
Motions & operators (The grammar)
-
Text objects (The context)
-
Macros (Automation)
-
Registers (Memory)
-
Vimscript (Customization)
Mastery comes from editing, not reading.
✅ This guide is designed for Linux admins, embedded engineers, developers, and Vim power users.
Happy Vimming 🚀
Comments
Loading the discussion…