# VSCode formatting issue on .h.in file

**URL:** <https://discourse.cmake.org/t/vscode-formatting-issue-on-h-in-file/9838>\
**Category:** Code\
**Created:** [January 12, 2024, 6:58am UTC](https://discourse.cmake.org/t/vscode-formatting-issue-on-h-in-file/9838 "2024-01-12T06:58:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KRISCHOMAT](https://discourse.cmake.org/user_avatar/discourse.cmake.org/krischomat/32/4163_2.png) [@KRISCHOMAT](https://discourse.cmake.org/u/KRISCHOMAT)\
**Post date:** [January 12, 2024, 6:58am UTC](https://discourse.cmake.org/t/vscode-formatting-issue-on-h-in-file/9838/1 "2024-01-12T06:58:34Z")

</div>

I just started the cmake tutorial and ran into an issue. When I want to set the .h.in file to

#define Tutorial\_VERSION\_MAJOR @Tutorial\_VERSION\_MAJOR@  
#define Tutorial\_VERSION\_MINOR @Tutorial\_VERSION\_MINOR@

and then save the file, vscode create a space before the last @ character like:

#define Tutorial\_VERSION\_MAJOR @Tutorial\_VERSION\_MAJOR @  
#define Tutorial\_VERSION\_MINOR @Tutorial\_VERSION\_MINOR @

I dont know where I can change this behaviour. I disabled prettier but the issue stays the same.

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [January 12, 2024, 8:57am UTC](https://discourse.cmake.org/t/vscode-formatting-issue-on-h-in-file/9838/2 "2024-01-12T08:57:52Z")

</div>

Sounds like a problem of Visual Studio Code, not CMake.

EDITED BY MODERATOR: Let’s keep it nice folks, I removed one remark.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [January 12, 2024, 1:03pm UTC](https://discourse.cmake.org/t/vscode-formatting-issue-on-h-in-file/9838/3 "2024-01-12T13:03:50Z")

</div>

Potential solution? [In Files - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=fcjr.in-files)

Maybe a configuration change? [visual studio code - VSCODE inserting spaces via format on save - Stack Overflow](https://stackoverflow.com/questions/40817613/vscode-inserting-spaces-via-format-on-save)

But yes, not a CMake problem. I suggest asking a VSCode user forum.

---

<div class="post-metadata">

**Author:** ![Coder47](https://discourse.cmake.org/user_avatar/discourse.cmake.org/coder47/32/5843_2.png) [@Coder47](https://discourse.cmake.org/u/Coder47)\
**Post date:** [October 5, 2025, 10:00pm UTC](https://discourse.cmake.org/t/vscode-formatting-issue-on-h-in-file/9838/4 "2025-10-05T22:00:55Z")

</div>

Just hit this. I realize this is not a cmake issue but in case others like me land here, this is what worked for me. .h.in files get associated with cpp formatters. In this case you want to associate them with cmake and then use the cmake formatter. So add this to your vscode Workspace settings. (or User if you want it like this everywhere):

```auto
{
    "files.associations": {
        "*.h.in": "cmake"
    },
    "[cmake]": {
        "editor.defaultFormatter": "ms-vscode.cmake-tools"
    }
}

```
