Skip to content

feat: word text objects (iw/aw) - #68

Merged
oribarilan merged 1 commit into
mainfrom
feat/text-objects
Sep 2, 2026
Merged

feat: word text objects (iw/aw)#68
oribarilan merged 1 commit into
mainfrom
feat/text-objects

Conversation

@oribarilan

Copy link
Copy Markdown
Owner

Adds vim word text objects iw/aw for the d/c/y operators and visual mode: diw ciw yiw daw caw yaw viw vaw.

Design

All object chars route through one seam, resolveTextObject in src/vim/textobject.ts, so the follow-up (quote/bracket pairs, plus iq/ib) adds only case arms + a pairRange in text.ts — no handler changes. The pure range algorithm (wordRange) lives in text.ts; the handlers gained ~2 small blocks each.

Included

  • Fixes delete / change / visual in word #57: after an operator, i/a start a text object instead of falling through to insert.
  • wordRange treats CR as a line boundary (CRLF-safe).
  • Extracts applyOperatorRange to dedupe the operator+e / operator+G / text-object apply-to-range logic.

Testing

just check green: 260 tests, lint clean. New unit tests for wordRange, resolveTextObject, and the normal/visual handler branches (including the #57 regression).

Deferred (deliberate)

  • Count on objects (d2iw) acts as diw.
  • vi<Esc> cancels the pending object but stays in visual (avoids a pending-state leak into normal).

Closes #57.

diw/ciw/yiw/daw/caw/yaw and viw/vaw, routed through a new resolveTextObject seam (src/vim/textobject.ts) so quote/bracket objects can be added later without touching the handlers.

- fix #57: after an operator, i/a now start a text object instead of falling through to insert mode
- wordRange treats CR as a line boundary (CRLF-safe)
- extract applyOperatorRange to share the operator+e / operator+G / text-object apply-to-range logic
@oribarilan
oribarilan merged commit 6ab65d7 into main Sep 2, 2026
1 check passed
@oribarilan
oribarilan deleted the feat/text-objects branch September 2, 2026 08:44
oribarilan added a commit that referenced this pull request Sep 2, 2026
Adds quote and bracket text objects on top of the `resolveTextObject`
seam from #68.

## Objects
- Quotes: `i"` `i'` `` i` `` (with `a` variants)
- Brackets: `i(` `i{` `i[` `i<` (with `a` variants), from either
delimiter
- `iq` for the nearest quote of any type (`"` `'` `` ` ``)
- `ib` for the nearest bracket of any type (`()` `{}` `[]`)

Works with `d`/`c`/`y` and in visual mode: `di"`, `ci(`, `da{`, `dib`,
`ciq`, `vi[`, and so on.

## Design
Purely additive over the seam: only `text.ts` (new pure functions
`bracketRange`, `quoteRange`, `anyQuoteRange`, `anyBracketRange`) and
`textobject.ts` (new `case` arms) changed. `normal.ts` and `visual.ts`
are untouched.

## Notes
- `ib` means any bracket, not vim's parens-only `ib` (documented in the
README). Use `i(` for parentheses specifically.
- Empty pairs no-op: `di"` on `""` and `ci(` on `()` do nothing (the
action model has no zero-width insert yet).

## Testing
`just check` green: 309 tests, lint clean. Covers nesting, multiline
brackets, cursor-on-delimiter, empty pairs, line-scoped quotes,
tightest-enclosing `iq`/`ib`, and a `db`-stays-a-motion regression
guard.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

delete / change / visual in word

1 participant