C.W.K.
Stream
Lesson 05 of 08 · published

Insert Mode — Entering Text

~10 min · vim, insert-mode, basics

Level 0Trapped
0 XP0/35 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

Eight ways to enter Insert mode, each with a job

Vim doesn't have one "start typing" key — it has a small family of them, each placing your cursor at a different position. The difference between i and a looks trivial; over a year of editing it adds up to thousands of saved motions.

The eight entries

  • i — insert before the cursor.
  • a — insert after the cursor ("append").
  • I — insert at the first non-blank character of the line.
  • A — insert at the end of the line.
  • o — open a new line below and start inserting.
  • O — open a new line above and start inserting.
  • s — delete the character under the cursor and start inserting.
  • S — delete the entire line and start inserting.

Returning to Normal mode

The classic exit is Esc. Ctrl-[ does exactly the same thing and is closer to the home row on most layouts. Ctrl-c also exits but skips abbreviation expansion — useful when you've defined Insert-mode abbreviations and you want to not trigger them.

Most-loved remap: map jj or jk in Insert mode to Esc. Two adjacent home-row keys instead of a stretch to the corner. You almost never type jj in real code, so the false-positive rate is near zero.

Why this matters more than it sounds

The difference between A; and $a; is one keystroke. The difference between o and $a<Enter> is two. These savings happen thousands of times a day. Vim feels fast not because of any one trick, but because every common operation has a one-key entry path designed in.

Code

Insert variants — practice each by deliberately picking one·vim
i    " Insert before cursor
a    " Insert after cursor
I    " Insert at start of line (first non-blank)
A    " Insert at end of line
o    " Open line below + insert
O    " Open line above + insert
s    " Substitute character (delete one + insert)
S    " Substitute line (delete line + insert)
Three ways to leave Insert mode·vim
Esc       " the canonical exit
Ctrl-[    " identical to Esc, easier to reach
Ctrl-c    " exits without expanding abbreviations or autocmds
The classic jk → Esc remap·vim
" Vimscript — add to ~/.vimrc
inoremap jj <Esc>
inoremap jk <Esc>
The same remap in Lua (Neovim)·lua
-- Add to ~/.config/nvim/init.lua
vim.keymap.set("i", "jj", "<Esc>")
vim.keymap.set("i", "jk", "<Esc>")

External links

Exercise

Take any source file. Without using arrow keys or the mouse, do these three edits using a single Insert-mode entry each: (1) add // TODO at the end of any line, (2) insert a blank line between two existing lines, (3) replace the first character of any word with a capital. The point isn't speed — it's picking the right insert variant on the first try.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.