pub enum Move {
Vertical {
row: usize,
},
Jump {
row: usize,
col: usize,
},
Horizontal {
col: usize,
},
Raw {
row: usize,
col: usize,
},
}Expand description
How a cursor move relates to sticky_col (vim’s curswant) — the column
j / k aim at.
Vim’s rule has exactly two halves, and every variant here encodes one of
them (or, for Move::Raw, deliberately opts out):
- vertical motions READ
curswant, clamp to the target row’s length, and leavecurswantalone, so a run ofjthrough short lines returns to the original column on the far side; - everything else that moves the cursor SETS
curswantto the column it landed on, so the nextjaims there.
Pick by asking what the move is, not by what is convenient: the whole point of the enum is that the answer gets recorded at the call site.
Variants§
Vertical
j / k and their screen-line equivalents (<C-e> / <C-y>).
READS sticky_col, clamps the landing column to row’s length, and
leaves sticky_col holding the un-clamped want — that is what lets
the column survive a short line and reappear on the next long one.
Bootstraps sticky_col from the current column when nothing has set
it yet.
Jump
An explicit jump to a position: a search hit, gg / G, a mark, a
mouse click, a picker <CR>, ]d, a jumplist entry.
SETS sticky_col to col. Vim resets curswant on every explicit
jump, so the next j aims at the landed column rather than at
wherever the cursor sat beforehand — the bug fixed in c022a3a4.
Horizontal
A move within the current row: h, l, w, b, e, f / t,
0, ^, $.
SETS sticky_col to col, same half of the rule as Move::Jump;
the separate variant exists so horizontal call sites cannot silently
pass the wrong row.
Raw
Place the cursor without touching sticky_col at all.
This is the conspicuous variant on purpose. It is not the default
landing zone for a site whose semantics are unclear — a mechanical
migration that picked Raw everywhere would compile, pass, and
preserve the entire bug class. It is legitimate only where some other
code owns curswant for the duration, i.e.:
- the clamped write inside a vertical motion itself
(
hjkl_vim::vim::motion::apply_sticky_col), which must preserve the un-clamped want it just stored; - restoring a position saved earlier in the same operation (operator bodies that park the cursor, run an edit, then put it back), where the cursor is semantically where it already was;
- host-side state restores — viewport sync, snapshot replay — where the host’s own sticky tracking is authoritative.
Any other use wants Move::Jump. Each Raw should carry a one-line
reason at its call site, and it stays greppable for review.