Learn Vim

Modal, keyboard-driven text editor available on almost every Unix machine

18 lessons · 3 hours · 4 levels · covers Vim 9.1

Vim is a modal text editor: instead of holding modifier keys, you switch between modes and compose short commands like 'delete inside quotes'. It is installed on nearly every server, its keybindings are available in most IDEs, and fluent Vim users edit text remarkably fast.

How deep do you want to go?

1. EssentialsRead and write simple code, do the everyday basics6 lessons · 52 min in total
2. PracticalUse it productively at work, with the usual idioms12 lessons · 2 hours in total
3. AdvancedThe less common features, performance and trade-offs15 lessons · 2 hours in total
4. ExpertInternals and the edge cases experts know18 lessons · 3 hours in total

The Vim tree

VimModes: insert, normal and quittingModes: insert,normal and quittingBasic motions: hjkl, words, linesBasic motions: hjkl,words, linesEntering insert mode the right wayEntering insert modethe right wayOperators: delete, change, yank, putOperators: delete,change, yank, putUndo, redo and the dot commandUndo, redo and thedot commandSearching with / and ?Searching with / and?Text objects: iw, i", a(, itText objects: iw, i",a(, itIn-line jumps: f, t and %In-line jumps: f, t and%Visual mode and block editingVisual mode andblock editingSubstitute: :s and rangesSubstitute: :s andrangesBuffers, windows and tabsBuffers, windows andtabsThe vimrc: options and mappingsThe vimrc: optionsand mappings
Essentials and Practical shown (12 of 18 lessons); the full list is below. Click a lesson to read it.

All 18 lessons, in order

Getting started

  1. Modes: insert, normal and quitting · Essentials · 8 min

    Vim starts in Normal mode where keys are commands; you press i to type text and Esc to get back.

Moving around

  1. Basic motions: hjkl, words, lines · Essentials · 10 min

    Move by character, word, line and file with single keys, optionally prefixed with a count.

  2. In-line jumps: f, t and % · Practical · 7 min

    Jump to a character on the current line with f/t, repeat with ; and , and bounce between brackets with %.

Editing text

  1. Entering insert mode the right way · Essentials · 6 min

    i, a, I, A, o and O enter Insert mode at different positions, saving a motion each time.

  2. Operators: delete, change, yank, put · Essentials · 12 min

    Commands like d, c and y take a motion: dw deletes a word, c$ changes to end of line, yy copies a line.

  3. Undo, redo and the dot command · Essentials · 8 min

    u undoes, Ctrl-r redoes, and . repeats your last change anywhere you move the cursor.

  4. Text objects: iw, i", a(, it · Practical · 10 min

    Operate on structured chunks like a word, a quoted string or a parenthesised block without moving the cursor to its start.

  5. Visual mode and block editing · Practical · 10 min

    Select characters, lines or a rectangular block, then apply any operator; Ctrl-v lets you edit many lines at once.

Search and replace

  1. Searching with / and ? · Essentials · 8 min

    Search forward with /pattern, backward with ?pattern, jump with n and N, and search the word under the cursor with *.

  2. Substitute: :s and ranges · Practical · 12 min

    Replace text with :s/old/new/flags over a line, a range or the whole file, optionally confirming each match.

  3. Vim regex: very magic, \zs and expressions · Expert · 15 min

    Write readable patterns with \v, trim matches with \zs and \ze, and compute replacements with \=.

Buffers, windows and tabs

  1. Buffers, windows and tabs · Practical · 12 min

    A buffer is a file in memory, a window is a view onto a buffer, and a tab page is a layout of windows.

Configuration and scripting

  1. The vimrc: options and mappings · Practical · 12 min

    Configure Vim with set options and your own key mappings in ~/.vimrc, using noremap and a leader key.

  2. Runtimepath, packages and autocommands · Expert · 15 min

    Understand where Vim loads scripts from, install plugins as packages, and react to events with autocommands.

  3. Vim9 script basics · Expert · 15 min

    Vim9 script is Vim 9's compiled, typed scripting language for faster, saner plugins and configuration.

Registers, macros and :global

  1. Registers: named, yank and system clipboard · Advanced · 10 min

    Vim stores yanked and deleted text in registers; choose one with "x, and use "+ for the system clipboard.

  2. Recording and replaying macros · Advanced · 12 min

    Record keystrokes into a register with q, replay them with @, and apply them to many lines at once.

  3. The :global command · Advanced · 10 min

    :g/pattern/cmd runs an Ex command on every line matching a pattern; :v does it on non-matching lines.