# Format specific selected lines

**URL:** <https://discuss.kakoune.com/t/format-specific-selected-lines/284>\
**Category:** Recipes & Guides\
**Tags:** format\
**Created:** [January 22, 2019, 4:58pm UTC](https://discuss.kakoune.com/t/format-specific-selected-lines/284 "2019-01-22T16:58:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lauccode](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/lauccode/32/52_2.png) [@lauccode](https://discuss.kakoune.com/u/lauccode)\
**Post date:** [January 22, 2019, 4:58pm UTC](https://discuss.kakoune.com/t/format-specific-selected-lines/284/1 "2019-01-22T16:58:23Z")

</div>

**I added those lines in kakrc. And it is working, but it is formating all the file :**

> hook global WinSetOption filetype=c %{  
> set window formatcmd ‘clang-format’  
> }  
> map global normal = :format\<ret\> -docstring ‘format buffer’

Is there a way to format only selected line with ‘X’ ?

---

<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:** [January 22, 2019, 5:19pm UTC](https://discuss.kakoune.com/t/format-specific-selected-lines/284/2 "2019-01-22T17:19:24Z")

</div>

you can pipe selection with | to clang format, although it will make no sense to clang format without surrounding information, and it will probably screw your formatting

---

<div class="post-metadata">

**Author:** ![lauccode](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/lauccode/32/52_2.png) [@lauccode](https://discuss.kakoune.com/u/lauccode)\
**Post date:** [January 24, 2019, 6:55pm UTC](https://discuss.kakoune.com/t/format-specific-selected-lines/284/3 "2019-01-24T18:55:06Z")

</div>

Thanks it is working well.  
I added this map to format the selection with f3 (if it can help someone) :

> map global normal ‘|clang-format’
