Vim is a modal editor built for speed and precision. Once you grasp its modes, motion-centric editing, and a few power features, you can navigate and transform text faster than most GUI editors.
Core concepts
- Modal editing: Normal (commands), Insert (typing), Visual (select), Command-line (: commands).
- Composability: Operator + motion = action (e.g.,
d+w= delete word). - Buffers/Windows/Tabs: Buffer = an open file; Window = a view on a buffer; Tab = a collection of windows.
Modes and essentials
- Normal: ESC (default). Navigate, edit with commands.
- Insert:
i(insert),a(append),o/O(new line below/above). ESC to return to Normal. - Visual:
v(char),V(line),Ctrl+v(block). Then apply operators (yank, delete, indent). - Command-line:
:for ex commands,/for search,?for reverse search.
Movement (be fast here)
- Basic:
h j k l(left/down/up/right),w/b(word fwd/back),0/$(line start/end). - Sentences/paragraphs:
(/),{/}. - File:
gg(top),G(bottom),:{n}(go to line). - Find on line:
f{char}/F(back),t{char}/T(till),;/,to repeat. - Marks:
ma(set mark a),'a(jump to it).``to jump back.
Editing with operators
- Delete:
d{motion}(e.g.,dw,d$,di"to delete inside quotes). - Change:
c{motion}(delete + go to Insert).ciw= change inner word. - Yank/Paste:
y{motion},p/Pto paste. - Indent:
>/<with motions or Visual selections. - Repeat:
.repeats the last change—huge productivity win.
Text objects (power feature)
- Inside/around:
i/a+w(word),p(paragraph),",',(,{,[,<. - Examples:
ci"(change inside quotes),da((delete around parentheses),vip(select inner paragraph).
Search, replace, and navigation
- Search:
/pattern,n/Nto move;*/#to search word under cursor. - Substitute (line):
:s/old/new/g. Whole file::%s/old/new/gc(cto confirm). - Split windows:
:sp(horizontal),:vsp(vertical); move withCtrl+w+h/j/k/l. - Buffers:
:lsto list,:b {num}to jump,:bdto close buffer.
Registers, undo, macros
- Registers:
"{reg}yto yank into a register (e.g.,"ayw),"{reg}pto paste."*and"+for clipboard (if enabled). - Undo/redo:
u(undo),Ctrl+r(redo). Undo tree exists; navigate withg-/g+. - Macros:
q{reg}to start recording, do actions,qto stop,@{reg}to replay,@@to repeat last macro.
Visual block superpowers
Ctrl+vto enter block mode; select a column; thenI(insert) orA(append) to edit multiple lines at once.- Use block mode to prepend/append text, align columns, or comment/uncomment blocks.
Config and plugins
- .vimrc/init.vim basics:
set number,set relativenumber,set expandtab,set shiftwidth=2,set tabstop=2,set smartindent,set ignorecase smartcase,set incsearch,set hlsearch. - Plugins: Use a plugin manager (vim-plug, packer.nvim). Common picks: file explorer (netrw built-in, or NERDTree), fuzzy finder (fzf), LSP client (built-in for Neovim), treesitter for better syntax.
- Mappings: Create leader shortcuts, e.g.,
let mapleader=","thennnoremap <leader>f :Files<CR>(with fzf).
Everyday workflows
- Open files:
vim file1 file2; switch buffers with:bnext/:bprev. - Split and compare:
:vsp file, then usedo/dpfor diff or:diffthis/:diffoff. - Indent/format:
gg=Gto auto-indent whole file; language servers/formatters via LSP or:%!formatter. - Save/quit:
:w,:q,:wq,:q!.
Muscle-memory tips
- Use motions more than arrow keys:
w,b,f/t,{/}. - Always try the operator + motion pattern before reaching for the mouse.
- Lean on
.to repeat edits and@macros for repetitive work.
Master the modes, motions, and operator+motion mindset first. Then layer in searches, macros, splits, and a small set of configs. Vim rewards a few core habits with huge speed gains.