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:

Ways to Enter Insert Mode#

Vim provides many commands to enter Insert mode, each placing your cursor differently:

Basic Insert Commands#

CommandActionMnemonic
iInsert before cursorinsert
aInsert after cursorappend
IInsert at beginning of lineInsert at start
AInsert at end of lineAppend to line

Opening New Lines#

CommandActionMnemonic
oOpen line below, enter Insertopen below
OOpen line above, enter InsertOpen above

Replacing Text#

CommandAction
sDelete character, enter Insert (substitute)
SDelete line, enter Insert (substitute line)
c{motion}Delete motion, enter Insert (change)
CDelete 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:

CommandAction
Arrow keysMove cursor
Ctrl-hDelete character before cursor (backspace)
Ctrl-wDelete word before cursor
Ctrl-uDelete to start of line

Special Insertions#

CommandAction
Ctrl-r {reg}Insert contents of register
Ctrl-r =Insert result of expression
Ctrl-aInsert previously inserted text
Ctrl-tIndent current line
Ctrl-dUnindent current line

Exiting Insert Mode#

CommandAction
EscReturn to Normal mode
Ctrl-[Return to Normal mode (same as Esc)
Ctrl-cReturn to Normal mode (may skip abbreviations)
Ctrl-oExecute 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:

  1. Press Ctrl-o
  2. Type :w and press Enter
  3. Youโ€™re still in Insert mode!

Example: Youโ€™re typing and need to scroll:

  1. Press Ctrl-o
  2. Press Ctrl-d to scroll down
  3. 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:

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:

  1. Exit to Normal mode
  2. Navigate to the new location
  3. 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#

  1. Create a file with several lines of text
  2. Practice using i, a, I, A to insert text at different positions
  3. Use o and O to add new lines

Exercise 2: The Change Operator#

  1. Write a sentence: The quick brown fox
  2. Position on โ€œquickโ€, press cw, type โ€œslowโ€
  3. Position on โ€œbrownโ€, press ciw, type โ€œredโ€
  4. Notice the difference between cw and ciw

Exercise 3: Ctrl-o#

  1. Enter Insert mode and start typing
  2. Press Ctrl-o then 0 to jump to line start (still in Insert mode)
  3. Press Ctrl-o then $ to jump to line end
  4. Continue typing

Exercise 4: Substitute Commands#

  1. Position cursor on a character
  2. Press s and type a replacement
  3. On a line, press S to replace the entire line

Common Insert Mode Patterns#

Adding to End of Multiple Lines#

  1. Ctrl-v to enter Visual Block mode
  2. Select the lines
  3. $ to extend to end of each line
  4. A to append
  5. Type your text
  6. Esc โ€” text appears on all lines

Inserting the Same Text Multiple Times#

Use a count before entering Insert mode:

  1. 3i โ€” enter Insert mode with count 3
  2. Type โ€œhello โ€
  3. Esc โ€” โ€œhello hello hello โ€ appears

Summary#

CommandAction
i / aInsert before/after cursor
I / AInsert at start/end of line
o / OOpen line below/above
s / SSubstitute character/line
c{motion}Change (delete + insert)
EscReturn to Normal mode
Ctrl-oExecute one Normal command

Remember: Insert mode is for inserting text. Everything else belongs in Normal mode.