Skip to main content

Move

Enum Move 

Source
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 leave curswant alone, so a run of j through short lines returns to the original column on the far side;
  • everything else that moves the cursor SETS curswant to the column it landed on, so the next j aims 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.

Fields

§row: usize
§

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.

Fields

§row: usize
§col: usize
§

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.

Fields

§col: usize
§

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.

Fields

§row: usize
§col: usize

Trait Implementations§

Source§

impl Clone for Move

Source§

fn clone(&self) -> Move

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Move

Source§

impl Debug for Move

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Move

Source§

impl PartialEq for Move

Source§

fn eq(&self, other: &Move) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Move

Auto Trait Implementations§

§

impl Freeze for Move

§

impl RefUnwindSafe for Move

§

impl Send for Move

§

impl Sync for Move

§

impl Unpin for Move

§

impl UnsafeUnpin for Move

§

impl UnwindSafe for Move

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more