# Improve behavior around word-based brackets in bash \(\#29700\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/fc920bf63d827a33691f6bd4e24bef271a743c0b)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: fc920bf63d827a33691f6bd4e24bef271a743c0b

Requested commit: fc920bf63d827a33691f6bd4e24bef271a743c0b

Commit: fc920bf63d827a33691f6bd4e24bef271a743c0b

Tree: c217d937daabc91b2f152e33917c6594bb60ef20

Author: Ben Kunkle

Committer: GitHub

## Message

````
Improve behavior around word-based brackets in bash (#29700)

Closes #28414

Makes it so that `do`, `then`, `done`, `else`, etc are treated as
brackets in bash. They are not auto-closed *yet* as that requires
additional work to function properly, however they can now be toggled
between using `%` in vim. Additionally, newlines are inserted like they
are with regular brackets (`{}()[]""''`) when hitting enter between
them.

While `if <-> fi` `while/for <-> done` and `case <-> esac` are the
*logical* matching pairs, I've opted to instead match between `then <->
else/elif/fi` `do <-> done` and `in <-> esac` as these are the pairs
that delimit the sub-scope, and are more similar to the `{}` style
bracket pairs than `if <-> }` in a c-like syntax. This does cause some
wierd behavior with `else` in `if` expressions as it matches both with
the previous `then` as well as the following `fi`, so in this case

```bash
if true; then
   foo
else
   bar
f|i
```

after hitting `%` twice times (where cursor is `|`), the cursor will end
up on the `then` instead of back on the `fi` as hitting `%` on the else
will *always* navigate up to the `then`

Release Notes:

- vim: Improved behavior around word-based delimiters in bash (`do <->
done`, `then <-> fi`, etc) so they can be toggled between using `%`
````

## Parents

- [04c68dc0cf0f933f6b441f33ffa739b33334c72f](https://git.cafe/gitcafe/zed/commit/04c68dc0cf0f933f6b441f33ffa739b33334c72f?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/fc920bf63d827a33691f6bd4e24bef271a743c0b?format=markdown)
