From c68fe1f2a3a40c37969c1f5d18e3134320a0c773 Mon Sep 17 00:00:00 2001 From: Gokul Soumya Date: Sat, 3 Jul 2021 06:37:49 +0530 Subject: Add object selection (textobjects) (#385) * Add textobjects for word * Add textobjects for surround characters * Apply clippy lints * Remove ThisWordPrevBound in favor of PrevWordEnd It's the same as PrevWordEnd except for taking the current char into account, so use a "flag" to capture that usecase * Add tests for PrevWordEnd movement * Remove ThisWord* movements They did not preserve anchor positions and were only used for textobject boundary search anyway so replace them with simple position finding functions * Rewrite tests of word textobject * Add tests for surround textobject * Add textobject docs * Refactor textobject word position functions * Apply clippy lints on textobject * Fix overflow error with textobjects--- book/src/keymap.md | 5 ++++- book/src/usage.md | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'book/src') diff --git a/book/src/keymap.md b/book/src/keymap.md index 0265fe6d..6b7ccd11 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -150,7 +150,8 @@ Jumps to various locations. ## Match mode Enter this mode using `m` from normal mode. See the relavant section -in [Usage](./usage.md#surround) for an explanation about surround usage. +in [Usage](./usage.md) for an explanation about [surround](./usage.md#surround) +and [textobject](./usage.md#textobject) usage. | Key | Description | | ----- | ----------- | @@ -158,6 +159,8 @@ in [Usage](./usage.md#surround) for an explanation about surround usage. | `s` `` | Surround current selection with `` | | `r` `` | Replace surround character `` with `` | | `d` `` | Delete surround character `` | +| `a` `` | Select around textobject | +| `i` `` | Select inside textobject | ## Object mode diff --git a/book/src/usage.md b/book/src/usage.md index e6bd60e2..0458071a 100644 --- a/book/src/usage.md +++ b/book/src/usage.md @@ -24,3 +24,19 @@ It can also act on multiple seletions (yay!). For example, to change every occur - `mr([` to replace the parens with square brackets Multiple characters are currently not supported, but planned. + +## Textobjects + +Currently supported: `word`, `surround`. + +![textobject-demo](https://user-images.githubusercontent.com/23398472/124231131-81a4bb00-db2d-11eb-9d10-8e577ca7b177.gif) + +- `ma` - Select around the object (`va` in vim, `` in kakoune) +- `mi` - Select inside the object (`vi` in vim, `` in kakoune) + +| Key after `mi` or `ma` | Textobject selected | +| --- | --- | +| `w` | Word | +| `(`, `[`, `'`, etc | Specified surround pairs | + +Textobjects based on treesitter, like `function`, `class`, etc are planned. -- cgit v1.2.3-70-g09d2