How the analyser finds a shorter route
Par is a clean route using what you've learned so far, the one someone fluent in Vim would type. Before the site is published, every route is replayed in this site's editor and checked against the rules for a clean route, and a search looks for a shorter clean route with those commands.
In a practice set, in challenges and on your own text, the analyser also takes each edit you made and tries c and d with fourteen text objects from where your cursor was. It names one only if it gives exactly the same text in at least three fewer keys.
How keys are counted
Every key you press in the editor counts once. Text you type in Insert mode counts one key per character, spaces included. Esc, Enter and a Ctrl combination count as one key each. Shift does not count on its own, so A is one key.
On your own text, pasted text is not counted and is left out of the comparison.
Par is a clean route with what you've been taught
Every lesson exercise has a reference route, written with the lesson. Every practice task has one too, made by the task generator. It takes the cheapest of a fixed set of ways to reach the place, then adds the edit. Each way starts with j or k with a count, a line number and G, or a short / search, then uses f, t, F, w, e, b, 0, ^ or $.
Before the site is built, each route is replayed in the editor the pages load, which is CodeMirror with its Vim mode. A route that does not produce the desired result stops the build. Par is the number of keys in the route that passed.
On a lesson exercise, a checkpoint, a combined edit and a module boss, par's route must be clean. It changes whole words, names, strings or lines, it searches for at least three characters or a whole word, it counts at most four words at a time (six before f and / are taught), and it doesn't count h or l presses outside the lessons about them. A route that keeps part of a word to save keys, or lands somewhere by chance, isn't par even when it's shorter.
Then a search tries clean routes made only of the commands taught by that point: moves like f, w, counts, a / search and n, and edits like c or d with a motion or a text object, x, r and the dot. On a module boss, a combined edit or a checkpoint, a shorter clean route that uses the task's technique stops the build until a person makes it par or writes down why nobody would type it. A puzzle's par is the fewest keys, tricks included, so any shorter route stops the build there. A checkpoint keeps its first route as another way to do it.
Beating par with a clean route is a bonus. You get gold, and the result says how many keys under par you were.
A lesson exercise that teaches one technique keeps that technique's route as par, even when other commands are shorter there. If you find a shorter way with a command the course teaches later, you finish under par, and the result says which command that was.
Example: par on a lesson exercise
This exercise is from the lesson “Edit a whole word”. The cursor starts on the l of color. Here's the task. This setting is called theme now. Rename color to theme.
«// Settings the storefront reads when it starts. export const settings = { currency: "EUR", pageSize: 24, color: "dark", showReviews: true, supportEmail: "help@northwind.shop", };», cursor on «l», column 5
«// Settings the storefront reads when it starts. export const settings = { currency: "EUR", pageSize: 24, theme: "dark", showReviews: true, supportEmail: "help@northwind.shop", };»
| Route | Keys | Count |
|---|---|---|
| Reference route (par) | ciwtype themeEsc | 9 |
| A longer way | bdwitype themeEsc | 10 |
What the lesson's result card says if you take the longer way
Solved in 10 keys. Par 9.
You deleted, then went into Insert mode. To replace text, c{motion} deletes the range and puts you in Insert mode in one go.
Both routes leave the same text. The longer one goes back to the start of the word, deletes it and types the new name. ciw takes the whole word from where the cursor already is. On a lesson page, if you typed more keys than par, the result card shows the par route as a tip. If the analyser has a note about a technique, it shows that instead.
The shorter-route check
An exercise knows its reference route. Your own text has none. There's only what the text was, what it became and where the cursor stood. So after you edit, the analyser asks the engine a narrower question. From that exact position, does an operator with a text object produce that exact text in fewer keys?
First it splits what you typed into edits. An edit runs from the last change up to and including the key that changed the text, so the moves you made to get somewhere belong to the edit they were for. Insert mode stays part of one edit until you press Esc.
Then it looks at each edit, and at up to three edits in a row taken together, because a delete and the typing after it are often one change in your head and one c in Vim. For each, it tries c and d with the text objects below, and replays every candidate in the editor from where the cursor was when the first edit began.
iwawi"a"i'a'i(a(i[a[i{a{itat
A c candidate retypes the text you typed. A candidate counts only if the replay gives the same text as your edit did and is at least three keys shorter. y is never tried, because copying does not change the text.
Example: a shorter route on your own text
Change not ready to ready now. The cursor starts at the beginning of the line.
«const state = "not ready";», cursor on «c», column 1
«const state = "ready now";»
| Edit | Keys | Count |
|---|---|---|
| Edit 1 | f"ldw | 5 |
| Edit 2 | dw | 2 |
| Edit 3 | itype ready nowEsc | 11 |
| Your 3 edits | f"ldwdwitype ready nowEsc | 18 |
| Same text, same cursor | ci"type ready nowEsc 5 keys fewer | 13 |
In this editor, ci" works from before the opening quote on the same line, so the check can start where the first edit did.
Example: a route the check does not find
Replace what is inside the brackets with final. The cursor starts at the end of the line.
«send(draft, true);», cursor on «;», column 18
«send(final);»
| Edit | Keys | Count |
|---|---|---|
| Edit 1 | F(ldt) | 6 |
| Edit 2 | itype finalEsc | 7 |
| Your 2 edits | F(ldt)itype finalEsc | 13 |
From inside the brackets, the 9-key route ci(type finalEsc would make the same change. Here's what the analyser's replay gives from each place.
«send(final);»
«send(draft, true);»
With the cursor after the brackets, ci( does nothing, in Vim as in this site's editor, so the replay from where the edit began gives other text. The check doesn't try moving first, so it never compares a route that needs the cursor inside the brackets.
What the analyser cannot tell you
- On your own text it only suggests c or d with one of the fourteen text objects above. Counts, ., searches, macros, Visual mode and Ex commands are never suggested there.
- It looks at no more than three edits in a row, and it says nothing about savings of one or two keys.
- It starts from where your cursor was when the edit began. A route that only works after moving the cursor is not found.
- A match means the same text from the same starting point. It does not mean the route is the shortest possible, and the cursor and registers can end up in a different state from yours.
- The search for a shorter route is limited. It doesn't try Visual mode, macros, gn or Ex commands, so par doesn't prove that nothing shorter exists.
- Everything is replayed in CodeMirror's Vim mode, not in Vim. It covers the commands the course teaches, not all of Vim. The guides' examples are also checked in Vim, but the analyser's routes aren't.
Try it
Edit any text of your own and press Analyse, or do today's practice and compare each edit with par.