Vim modes explained: Normal, Insert, Visual and Command
| Vim |
Vim is a modal editor: its behavior depends on the "mode" you're in. Understanding and mastering the four basic modes — Normal, Insert, Visual and Command — is the key to editing text quickly and efficiently.
Quick summary
- Normal: the default mode for navigating and editing with commands (without inserting text directly).
- Insert: for typing text literally (like in a traditional editor).
- Visual: for selecting text (characters, words or lines) and then operating on the selection.
- Command (command-line): to run complex commands, save, quit, replace, search, etc.
Normal mode
What it is
- It's the mode for navigating, deleting, copying, pasting and running most Vim commands.
How to enter
- When you open Vim you're already in Normal. If you come from Insert, press
EscorCtrl-[to return to Normal.
Useful commands (Normal mode)
- h, j, k, l — move the cursor (left, down, up, right).
- w, b, e — move by words (next, previous, end of word).
- 0 (zero) and $ — go to the beginning and end of the line.
- dd — delete the line (and copy it into the register).
- yy — yank (copy) the line.
- p — paste after the cursor.
- u — undo.
- Ctrl-r — redo.
- /text — search forward;
nfor next,Nfor previous.
Examples
5j— move down 5 lines.3dw— delete 3 words from the cursor.
Tips
- Combine numbers with commands:
10jmoves down 10 lines,2dddeletes two lines.
Insert mode
What it is
- The mode for inserting text literally.
How to enter
- Press
i(insert before the cursor),I(at the start of the line),a(insert after the cursor),A(at the end of the line),o(open a new line below),O(open a new line above).
How to exit Insert
EscorCtrl-[to return to Normal mode.
Quick tips
- Use
Ctrl-ofrom Insert to run a single Normal command and return to Insert.
Visual mode
What it is
- Used to select text and then apply commands (delete, copy, change, etc.). There are three sub-modes: characterwise visual, linewise visual and blockwise visual.
How to enter
v— characterwise visual.V— linewise visual.Ctrl-v— blockwise visual (rectangular selection).
Useful commands inside Visual
y— yank (copy selection).d— delete the selection.>and<— indent selection right/left.:s/pattern/repl/— you can run substitutions on the selection (press:after selecting and you'll see:'<,'>in the command line).
Examples
- Select a word: place the cursor on the word and press
v+iw(inner word) or useviwdirectly from Normal. - Select 3 lines:
V2jand thenyto copy.
Command mode (command-line)
What it is
- Also called Ex mode or command-line mode. It's used to save, quit, search and replace with more advanced syntax.
How to enter
- From Normal press
:to open the command-line at the bottom.
Common commands
:w— write (save).:q— quit.:wqor:x— save and quit.:q!— quit without saving.:e file— open/edit another file.:%s/old/new/g— replace throughout the file (global).:set number— show line numbers;:set nonumberto hide them.
Search and replace
:/patternstarts a search; often/patternfrom Normal is more convenient.- Replacement with confirmation:
:%s/old/new/gc(asks before each replacement).
Typical workflow and shortcuts to be more efficient
- Navigate in Normal (use
w,b,f,t,}and{to move quickly). - Enter Insert (
iora) to type or edit text. - Return to Normal (
Esc) and use Visual to select if you need to move/change blocks. - Use the command-line (
:) to save, search or run complex substitutions.
Speed-up shortcuts
.— repeat the last command (very powerful).ciw— change (delete + enter Insert) the inner word.ci{orci(— change the inner content of a block between braces/parentheses.
Practical exercises (5–10 minutes each)
- Open a text file with several lines. In Normal, use
:set numberand practice moving the cursor with10j,5k,0and$. - Insert a new line below the current one with
o, type text, and return to Normal withEsc. Repeat 5 times and then useddto delete three of those lines. - Copy 2 lines with
yyor2yyand paste them after withp. - Select a word with
viwand replace it by typingc+ new text +Esc. - Do a safe global substitution:
:%s/foo/bar/gcand answer the confirmations.
Common mistakes and how to avoid them
- Staying in Insert and pressing key combinations thinking they are shortcuts: remember to get back to Normal with
Esc. - Forgetting that
ddandyystore content in registers; if you paste something unexpected, you might have yanked something else. - Using
:wqwhen you only wanted to quit without saving: use:q!to discard changes.
Quick resources to learn more
- Run
vimtutorin the terminal for an interactive tutorial (highly recommended). - Look for "vim tips" guides and cheatsheets (for movements, operators, text objects).
If you want, I can:
- Add GIFs or images that show the keys and effects.
- Include advanced practical examples (macros, registers, useful plugins).
- Create an exercises page with solutions or adapt this into a short interactive tutorial.
Tell me which option you prefer and I'll add it.