1.2 โ Insert Mode โ Entering Text
1.2 โ Insert Mode โ Entering Text#
Insert mode is where you actually type text, just like in any other editor. But Vim gives you multiple ways to enter Insert mode, each optimized for different situations.
What is Insert Mode?#
Insert mode is the mode where keystrokes insert characters into the buffer. Itโs the closest Vim gets to a โnormalโ text editor.
When youโre in Insert mode:
-- INSERT --appears at the bottom of the screen- Characters you type appear in the document
- The cursor is typically a vertical line (depends on terminal)
Ways to Enter Insert Mode#
Vim provides many commands to enter Insert mode, each placing your cursor differently:
Basic Insert Commands#
| Command | Action | Mnemonic |
|---|---|---|
i | Insert before cursor | insert |
a | Insert after cursor | append |
I | Insert at beginning of line | Insert at start |
A | Insert at end of line | Append to line |
Opening New Lines#
| Command | Action | Mnemonic |
|---|---|---|
o | Open line below, enter Insert | open below |
O | Open line above, enter Insert | Open above |
Replacing Text#
| Command | Action |
|---|---|
s | Delete character, enter Insert (substitute) |
S | Delete line, enter Insert (substitute line) |
c{motion} | Delete motion, enter Insert (change) |
C | Delete to end of line, enter Insert |
Choosing the Right Entry Point#
The key to efficient Vim usage is choosing the right command to enter Insert mode.
Scenario: Add text at the end of a line#
Inefficient: $ then a
Efficient: A
Scenario: Add a new line of code below#
Inefficient: $ then a then Enter
Efficient: o
Scenario: Replace a word#
Inefficient: dw then i
Efficient: cw (or ciw for the whole word)
Scenario: Fix a typo in the middle of a word#
Efficient: Navigate to the character, press s, type the correction
Insert Mode Commands#
While in Insert mode, you have some special commands:
Navigation (Limited)#
| Command | Action |
|---|---|
| Arrow keys | Move cursor |
Ctrl-h | Delete character before cursor (backspace) |
Ctrl-w | Delete word before cursor |
Ctrl-u | Delete to start of line |
Special Insertions#
| Command | Action |
|---|---|
Ctrl-r {reg} | Insert contents of register |
Ctrl-r = | Insert result of expression |
Ctrl-a | Insert previously inserted text |
Ctrl-t | Indent current line |
Ctrl-d | Unindent current line |
Exiting Insert Mode#
| Command | Action |
|---|---|
Esc | Return to Normal mode |
Ctrl-[ | Return to Normal mode (same as Esc) |
Ctrl-c | Return to Normal mode (may skip abbreviations) |
Ctrl-o | Execute one Normal mode command, return to Insert |
The Ctrl-o Trick#
Ctrl-o is incredibly useful. It lets you execute a single Normal mode command without leaving Insert mode.
Example: Youโre typing and need to save:
- Press
Ctrl-o - Type
:wand press Enter - Youโre still in Insert mode!
Example: Youโre typing and need to scroll:
- Press
Ctrl-o - Press
Ctrl-dto scroll down - Continue typing
Insert Mode Best Practices#
Keep Insertions Atomic#
Each time you enter Insert mode, make a single logical change, then return to Normal mode. This:
- Makes undo more useful (undo one logical change, not individual characters)
- Makes the dot command more powerful
- Keeps your edit history clean
Bad: Enter Insert mode, type a paragraph, make corrections, type more
Good: Enter Insert mode, type a sentence, exit. Repeat.
Use the Right Entry Command#
Donโt navigate in Insert mode. Instead:
- Exit to Normal mode
- Navigate to the new location
- Enter Insert mode with the appropriate command
Leverage Change Commands#
The c (change) operator combines deletion with entering Insert mode:
ci" โ Change inside quotes
ciw โ Change inner word
ci( โ Change inside parentheses
ct, โ Change until comma
Practice Exercises#
Exercise 1: Entry Points#
- Create a file with several lines of text
- Practice using
i,a,I,Ato insert text at different positions - Use
oandOto add new lines
Exercise 2: The Change Operator#
- Write a sentence:
The quick brown fox - Position on โquickโ, press
cw, type โslowโ - Position on โbrownโ, press
ciw, type โredโ - Notice the difference between
cwandciw
Exercise 3: Ctrl-o#
- Enter Insert mode and start typing
- Press
Ctrl-othen0to jump to line start (still in Insert mode) - Press
Ctrl-othen$to jump to line end - Continue typing
Exercise 4: Substitute Commands#
- Position cursor on a character
- Press
sand type a replacement - On a line, press
Sto replace the entire line
Common Insert Mode Patterns#
Adding to End of Multiple Lines#
Ctrl-vto enter Visual Block mode- Select the lines
$to extend to end of each lineAto append- Type your text
Escโ text appears on all lines
Inserting the Same Text Multiple Times#
Use a count before entering Insert mode:
3iโ enter Insert mode with count 3- Type โhello โ
Escโ โhello hello hello โ appears
Summary#
| Command | Action |
|---|---|
i / a | Insert before/after cursor |
I / A | Insert at start/end of line |
o / O | Open line below/above |
s / S | Substitute character/line |
c{motion} | Change (delete + insert) |
Esc | Return to Normal mode |
Ctrl-o | Execute one Normal command |
Remember: Insert mode is for inserting text. Everything else belongs in Normal mode.