# Fix indentation of region

**URL:** <https://discuss.kakoune.com/t/fix-indentation-of-region/387>\
**Category:** Help\
**Tags:** format\
**Created:** [March 21, 2019, 4:17am UTC](https://discuss.kakoune.com/t/fix-indentation-of-region/387 "2019-03-21T04:17:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericricky](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/ericricky/32/266_2.png) [@ericricky](https://discuss.kakoune.com/u/ericricky)\
**Post date:** [March 21, 2019, 4:17am UTC](https://discuss.kakoune.com/t/fix-indentation-of-region/387/1 "2019-03-21T04:17:58Z")

</div>

Is there a way to fix the indentation of multiline selections in Kakoune? In Emacs, hitting tab while a region is selected does this, and it looks like Vim has [=](https://vim.fandom.com/wiki/Fix_indentation). If this isn’t built into Kakoune, is there a command line utility or Kakoune plugin that does this?

---

<div class="post-metadata">

**Author:** ![Screwtapello](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/screwtapello/32/12_2.png) [@Screwtapello](https://discuss.kakoune.com/u/Screwtapello)\
**Post date:** [March 21, 2019, 4:42am UTC](https://discuss.kakoune.com/t/fix-indentation-of-region/387/2 "2019-03-21T04:42:50Z")

</div>

The definition of “fix” depends on what kind of file you’re editing. Plain text is pretty simple, so you can just set up [a mapping to pipe things through `fmt`](https://github.com/mawww/kakoune/wiki/Wrapping#semi-automatically-breaking-lines-at-a-fixed-width). For source code, you’ll probably need a specialised tool, but if the language you’re working with has a Language Server, and that language server supports the standard auto-format command, and you’re using [kak-lsp](https://github.com/ul/kak-lsp) to integrate the language server with Kakoune, there’s a `:lsp-formatting` command you can use—[the docs](https://github.com/ul/kak-lsp#usage) even have a snippet showing how to make it auto-format every time you save the buffer.

---

<div class="post-metadata">

**Author:** ![andreyorst](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/andreyorst/32/29_2.png) [@andreyorst](https://discuss.kakoune.com/u/andreyorst)\
**Post date:** [March 21, 2019, 3:16pm UTC](https://discuss.kakoune.com/t/fix-indentation-of-region/387/3 "2019-03-21T15:16:35Z")

</div>

In Vim, there’s cindent feature, that indents any block of text as it is C code, which is boun to ==. If some (not-full) region of text will be passed to something like `clang-format` with pipe it will be broken, because `clang-format` doesn’t accept incremental formatting and will fail if syntax tree is not full. Vim formatter was simple, but doesn’t had this kind of “problem”. Emacs has a nice feature, Tab keypress inserts correct indentation no matter what. I would appreciate this behavior.

---

<div class="post-metadata">

**Author:** ![ericricky](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/ericricky/32/266_2.png) [@ericricky](https://discuss.kakoune.com/u/ericricky)\
**Post date:** [March 22, 2019, 2:33pm UTC](https://discuss.kakoune.com/t/fix-indentation-of-region/387/4 "2019-03-22T14:33:22Z")

</div>

@Screwtapello @andreyorst Thanks for the suggestions. I’ll play around with it and see what I like
