on master help sign in
Add documentation for surround
commit753ed4cbc518774bb0331ed032a833a01f952ad1 authorGokul Soumya <gokulps15@gmail.com> dateTue 22 Jun 2021, 10:36 (5 years ago) parent892c807
3 files changed+40−3
book/src/keymap.md+14−2 book/src/usage.md+25 helix-term/src/commands.rs+1−1
book/src/keymap.md+14−2
@@ -21,7 +21,6 @@
2121| `F` | Find previous char |
2222| `Home` | Move to the start of the line |
2323| `End` | Move to the end of the line |
24−| `m` | Jump to matching bracket |
2524| `PageUp` | Move page up |
2625| `PageDown` | Move page down |
2726| `Ctrl-u` | Move half page up |
@@ -30,6 +29,7 @@
3029| `Ctrl-o` | Jump backward on the jumplist |
3130| `v` | Enter [select (extend) mode](#select--extend-mode) |
3231| `g` | Enter [goto mode](#goto-mode) |
32+| `m` | Enter [match mode](#match-mode)
3333| `:` | Enter command mode |
3434| `z` | Enter [view mode](#view-mode) |
3535| `Ctrl-w` | Enter [window mode](#window-mode) (maybe will be remove for spc w w later) |
@@ -70,7 +70,7 @@
7070| `Alt-;` | Flip selection cursor and anchor |
7171| `%` | Select entire file |
7272| `x` | Select current line, if already selected, extend to next line |
73−| `` | Expand selection to parent syntax node TODO: pick a key |
73+| | Expand selection to parent syntax node TODO: pick a key |
7474| `J` | join lines inside selection |
7575| `K` | keep selections matching the regex TODO: overlapped by hover help |
7676| `Space` | keep only the primary selection TODO: overlapped by space mode |
@@ -144,6 +144,18 @@ Jumps to various locations.
144144| `i` | Go to implementation |
145145| `a` | Go to the last accessed/alternate file |
146146
147+## Match mode
148+
149+Enter this mode using `m` from normal mode. See the relavant section
150+in [Usage](./usage.md#surround) for an explanation about surround usage.
151+
152+| Key | Description |
153+| ----- | ----------- |
154+| `m` | Goto matching bracket |
155+| `s` `<char>` | Surround current selection with `<char>` |
156+| `r` `<from><to>` | Replace surround character `<from>` with `<to>` |
157+| `d` `<char>` | Delete surround character `<char>` |
158+
147159## Object mode
148160
149161TODO: Mappings for selecting syntax nodes (a superset of `[`).
book/src/usage.md+25
@@ -1 +1,26 @@
11# Usage
2+
3+(Currently not fully documented, see the [keymappings](./keymap.md) list for more.)
4+
5+## Surround
6+
7+Functionality similar to [vim-surround](https://github.com/tpope/vim-surround) is built into
8+helix. The keymappings have been inspired from [vim-sandwich](https://github.com/machakann/vim-sandwich):
9+
10+![surround demo](https://user-images.githubusercontent.com/23398472/122865801-97073180-d344-11eb-8142-8f43809982c6.gif)
11+
12+- `ms` - Add surround characters
13+- `mr` - Replace surround characters
14+- `md` - Delete surround characters
15+
16+`ms` acts on a selection, so select the text first and use `ms<char>`. `mr` and `md` work
17+on the closest pairs found and selections are not required; use counts to act in outer pairs.
18+
19+It can also act on multiple seletions (yay!). For example, to change every occurance of `(use)` to `[use]`:
20+
21+- `%` to select the whole file
22+- `s` to split the selections on a search term
23+- Input `use` and hit Enter
24+- `mr([` to replace the parens with square brackets
25+
26+Multiple characters are currently not supported, but planned.
helix-term/src/commands.rs+1−1
@@ -3324,7 +3324,7 @@ fn surround(cx: &mut Context) {
33243324 cx.count = count;
33253325 match ch {
33263326 'm' => match_brackets(cx),
3327− 'a' => surround_add(cx),
3327+ 's' => surround_add(cx),
33283328 'r' => surround_replace(cx),
33293329 'd' => {
33303330 surround_delete(cx);