askesis

Vim essentials: 50 cards on modes, motions, operators and macros

Learn Vim from the keyboard up: modes, motions, operators and text objects, search and :s substitutions, registers, macros, visual mode and windows.

IT & DevOpsBeginner50 cardsFree

Practice now

Study without an account

0 of 50 seen0 graduated
Vim’s main modes

Scheduled with the default Askesis timings. Progress is saved in this browser.

All 50 cards

  1. 1
    Vim’s main modes
    Normal mode for commands and moving around, Insert mode for typing text, Visual mode for selecting, and Command-line mode for : commands
    Vim starts in Normal mode.
  2. 2
    How do you get back to Normal mode?
    Press Esc (or Ctrl-[)
  3. 3
    i vs a
    i starts inserting before the cursor; a starts inserting (appending) after it
  4. 4
    Start inserting at the beginning or the end of the line
    I inserts before the first non-blank character of the line; A appends at the end of the line
  5. 5
    o vs O
    o opens a new line below the cursor and enters Insert mode; O opens one above
  6. 6
    :w, :q, :wq and :q!
    Write (save); quit; write and quit; quit and throw away unsaved changes
    ZZ (like :x) saves only if there are changes, then quits.
  7. 7
    Quit every window at once, discarding all changes
    :qa!
    :wqa saves every changed buffer and quits instead.
  8. 8
    h, j, k, l
    Move left, down, up and right
  9. 9
    w, b, e
    w moves to the start of the next word, b back to the start of the current or previous word, and e to the end of the current or next word
  10. 10
    w vs W
    w moves by words, where a run of punctuation counts as a separate word; W moves by WORDs, which are any characters up to the next whitespace
    On foo.bar(x), w stops at ., then bar, then (, while W jumps past all of it.
  11. 11
    0, ^ and $
    The first column of the line, the first non-blank character, and the end of the line
  12. 12
    gg and G
    gg goes to the first line and G to the last; 42G or :42 goes to line 42
  13. 13
    f vs t
    fx moves onto the next x on the line; tx stops just before it. F and T search backward
    ; repeats the last f/t search and , repeats it in the opposite direction.
  14. 14
    What does % do?
    Jumps to the matching bracket: ( and ), [ and ], or { and }
  15. 15
    How do counts work with motions?
    A number before a motion repeats it: 3w moves three words and 5j five lines down
    Counts work with operators too: d3w deletes three words.
  16. 16
    Ctrl-d and Ctrl-u
    Scroll half a screen down and half a screen up
    Ctrl-f and Ctrl-b scroll a full screen forward and back.
  17. 17
    How do operators combine with motions?
    An operator such as d (delete), c (change) or y (yank, which copies) followed by a motion acts on the text the motion covers: dw deletes to the next word, c$ changes to the end of the line
  18. 18
    dd, cc and yy
    Doubling an operator makes it act on the whole line: delete the line, change the line, copy the line
  19. 19
    D and C
    Delete or change from the cursor to the end of the line, the same as d$ and c$
  20. 20
    x vs r
    x deletes the character under the cursor; r followed by a character replaces it without leaving Normal mode
  21. 21
    p vs P
    p puts (pastes) after the cursor, or below the line for whole lines; P puts before the cursor, or above the line
  22. 22
    Swap the current line with the one below
    ddp: delete the line, then put it below the next one
  23. 23
    What does dt, do?
    Deletes from the cursor up to, but not including, the next comma on the line
  24. 24
    Undo and redo
    u undoes the last change; Ctrl-r redoes it
  25. 25
    What does . do?
    Repeats the last change, such as a dw, a ciw with what you typed, or an A;
    Combined with n it gives a quick search-and-change loop: change once, then n. to repeat.
  26. 26
    What are text objects?
    Selections you use after an operator or in Visual mode: i (inner) takes just the contents, a (“a”) includes the surrounding whitespace, quotes or brackets
  27. 27
    ciw vs caw
    ciw changes the word under the cursor; caw also takes the whitespace around it, usually the space after the word
    Both work anywhere in the word, unlike cw, which starts at the cursor.
  28. 28
    What does ci" do?
    Changes the text between the double quotes and keeps the quotes; if the cursor is before them, it uses the next quoted string on the line
  29. 29
    Delete everything inside the curly braces around the cursor
    di{ (or di})
    da{ deletes the braces too. The same works with (, [ and <.
  30. 30
    What does cit do?
    Changes the text inside the HTML or XML tag around the cursor, keeping the tags
  31. 31
    What does dap do?
    Deletes the paragraph around the cursor, together with the blank lines after it
  32. 32
    /pattern vs ?pattern
    / searches forward and ? backward; n jumps to the next match in the same direction, N in the opposite one
  33. 33
    * and #
    Search forward or backward for the whole word under the cursor
  34. 34
    Search without matching case
    Add \c to the pattern for one search, as in /\cerror, or run :set ignorecase smartcase to ignore case unless the pattern contains a capital letter
  35. 35
    Replace every “foo” with “bar” in the whole file
    :%s/foo/bar/g
    % is the range for every line; without g only the first match on each line is replaced.
  36. 36
    The g, c and i flags of :s
    g replaces every match on a line, c asks you to confirm each one, i ignores case
  37. 37
    Limit a substitution to some lines
    :s/a/b/ changes only the current line, :5,10s/a/b/g lines 5 to 10, and :'<,'>s/a/b/g the lines of the last Visual selection
    Pressing : in Visual mode types :'<,'> for you.
  38. 38
    What is the unnamed register ""?
    Where d, c, y and x put text by default, and where p puts it from
  39. 39
    You yanked a word, then deleted a line. How do you paste the yanked word?
    "0p: register 0 holds the last yank, and deletes don’t overwrite it
  40. 40
    Yank a line into register a and paste it
    "ayy, then "ap
    An uppercase name appends instead: "Ayy adds the line to register a.
  41. 41
    Copy to the system clipboard
    "+y, for example "+yy for the current line; paste from it with "+p
    Needs a Vim built with clipboard support. On X11, "* is the primary selection.
  42. 42
    Record and play a macro
    qa starts recording into register a, q stops, and @a plays it back
    @@ repeats the last macro you played and 10@a runs it ten times.
  43. 43
    List what’s in every register
    :registers (or :reg)
  44. 44
    v, V and Ctrl-v
    Visual mode by character, by line, and by block (a rectangle of columns)
  45. 45
    Add the same text at the start of several lines
    Press Ctrl-v, extend down with j, press I, type the text, then Esc
    The text appears on every selected line once you press Esc.
  46. 46
    Buffer vs window vs tab page
    A buffer is a file loaded in memory, a window is a view onto a buffer, and a tab page is a layout of windows
  47. 47
    Open another file and switch between buffers
    :e file opens a file, :ls lists buffers, :b 2 switches to buffer 2, and :bn and :bp go to the next and previous buffer
  48. 48
    Split the window and move between the splits
    :split (Ctrl-w s) splits horizontally and :vsplit (Ctrl-w v) vertically; Ctrl-w w cycles through windows and Ctrl-w h, j, k, l move in a direction
  49. 49
    Get Vim’s built-in help on a command
    :help followed by the topic, for example :help dd or :help :s
    Run vimtutor from the shell for an interactive lesson.
  50. 50
    Keep settings across sessions
    Put them in ~/.vimrc (or ~/.vim/vimrc), one per line, usually without the leading colon
    vim
    set number
    set relativenumber
    set ignorecase smartcase

Frequently asked questions

Does this deck work for Neovim?

Yes. Neovim keeps Vim’s modes, motions, operators, registers and commands, so the keys on these cards work the same. Its config file lives in ~/.config/nvim/init.vim or init.lua instead of ~/.vimrc.

How do I get out of Vim?

Press Esc to get to Normal mode, then type :q and press Enter. Use :wq to save first, or :q! to throw your changes away.

How should I practice alongside the cards?

Run vimtutor, which comes with Vim, for a hands-on lesson of about half an hour. Then use one new motion or text object a day in real editing until it becomes a habit.

Intermediate

Linux command line

Linux commands and files for sysadmins and LPIC-1 candidates: find and grep, permissions and special bits, fstab, systemd targets, package managers, users, cron and more.

50 cards
Beginner

Linux filesystem basics

Learn the Linux directory tree: what /etc, /var, /usr, /proc and /dev are for, plus passwd, shadow, fstab and hosts. Free flashcards, no signup.

50 cards
Intermediate

Intermediate Linux filesystem

Linux paths admins use daily: /usr/local, /var/lib, /run, /sys, /etc/skel, sudoers, Bash startup files, SSH keys, resolv.conf and /proc. Free flashcards.

50 cards
Advanced

Advanced Linux filesystem

Deeper Linux files for LPIC-1: profile.d, sudoers.d, systemd units, GRUB config, nsswitch.conf, ld.so.conf, distro logs and /lib/modules. Free flashcards.

50 cards
Beginner

Bash scripting

Bash scripting flashcards: shebangs, quoting, exit codes, tests, loops, functions, arrays, parameter expansion, redirection, set -euo pipefail and traps.

50 cards
Beginner

Networking

Computer networking fundamentals: OSI and TCP/IP layers, TCP vs UDP, common port numbers, subnetting and CIDR, DNS, DHCP and ARP, and IPv6 basics.

50 cards
Beginner

Cyber security

Cyber security flashcards: the CIA triad, phishing, XSS, CSRF, SQL injection, MITM, hashing vs encryption, TLS, MFA, least privilege, OWASP and zero trust.

50 cards
Beginner

Docker

Learn Docker from images and layers to multi-stage builds, volumes, networks and Compose, with the commands and best practices you use daily.

50 cards
Intermediate

Kubernetes

Kubernetes fundamentals for developers and CKA or CKAD candidates: Pods, Deployments, Services, storage, probes, resources and scheduling, plus the kubectl commands you use daily.

50 cards
Beginner

AWS

AWS flashcards: regions and AZs, EC2, S3 storage classes, IAM users, roles and policies, VPC networking, RDS, Lambda, CloudWatch and Route 53.

50 cards
Beginner

Terraform

Terraform flashcards: HCL, providers, resources, variables and outputs, state and remote backends, plan and apply, modules, count, for_each, drift and import.

50 cards